Skip to content

Commit 4c5a641

Browse files
saschanazkripken
authored andcommitted
Writable stack (#5999)
* fix writable stack in ErrnoError to work in strict mode * add testing for strict mode
1 parent fbebe2c commit 4c5a641

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ mergeInto(LibraryManager.library, {
13681368
this.setErrno(errno);
13691369
this.message = ERRNO_MESSAGES[errno];
13701370
// Node.js compatibility: assigning on this.stack fails on Node 4 (but fixed on Node 8)
1371-
if (this.stack) Object.defineProperty(this, "stack", { value: (new Error).stack });
1371+
if (this.stack) Object.defineProperty(this, "stack", { value: (new Error).stack, writable: true });
13721372
#if ASSERTIONS
13731373
if (this.stack) this.stack = demangleAll(this.stack);
13741374
#endif

tests/test_core.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4553,16 +4553,31 @@ def test_fs_mmap(self):
45534553
self.do_run_from_file(src, out)
45544554

45554555
def test_fs_errorstack(self):
4556+
# Enables strict mode, which may catch some strict-mode-only errors
4557+
# so that users can safely work with strict JavaScript if enabled.
4558+
post = '''
4559+
def process(filename):
4560+
src = open(filename, 'r').read()
4561+
open(filename, 'w').write('"use strict";\\n' + src)
4562+
'''
4563+
45564564
Settings.FORCE_FILESYSTEM = 1
45574565
self.do_run(r'''
45584566
#include <emscripten.h>
4567+
#include <iostream>
45594568
int main(void) {
4569+
std::cout << "hello world\n"; // should work with strict mode
45604570
EM_ASM(
4561-
FS.write('/dummy.txt', 'homu');
4571+
try {
4572+
FS.write('/dummy.txt', 'homu');
4573+
} catch (err) {
4574+
err.stack = err.stack; // should be writable
4575+
throw err;
4576+
}
45624577
);
45634578
return 0;
45644579
}
4565-
''', 'at new ErrnoError', js_engines=[NODE_JS]) # engines has different error stack format
4580+
''', 'at Object.write', js_engines=[NODE_JS], post_build=post) # engines has different error stack format
45664581

45674582
def test_unistd_access(self):
45684583
self.clear()

0 commit comments

Comments
 (0)