Skip to content

Commit 0caf806

Browse files
kripkenbelraquib
authored andcommitted
Throw a wasm RuntimeError in abort (emscripten-core#9730)
Other JS errors may be seen as foreign exceptions which means native wasm exception handling will run destructors, but we do not want anything to run, and to just abort. Fixes emscripten-core#9715
1 parent f5c05ec commit 0caf806

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/preamble.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,25 @@ function abort(what) {
719719
EXITSTATUS = 1;
720720

721721
#if ASSERTIONS == 0
722-
throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
722+
what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
723723
#else
724-
var extra = '';
725-
var output = 'abort(' + what + ') at ' + stackTrace() + extra;
724+
var output = 'abort(' + what + ') at ' + stackTrace();
726725
#if EMTERPRETIFY_ASYNC
727726
abortDecorators.forEach(function(decorator) {
728727
output = decorator(output, what);
729728
});
730729
#endif
731-
throw output;
730+
what = output;
732731
#endif // ASSERTIONS
732+
733+
// Throw a wasm runtime error, because a JS error might be seen as a foreign
734+
// exception, which means we'd run destructors on it. We need the error to
735+
// simply make the program stop.
736+
#if WASM
737+
throw new WebAssembly.RuntimeError(what);
738+
#else
739+
throw what;
740+
#endif
733741
}
734742

735743
#if RELOCATABLE

src/wasm2js.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ WebAssembly = {
6969
});
7070
}
7171
};
72-
}
72+
},
73+
74+
RuntimeError: Error
7375
};
7476

7577
// We don't need to actually download a wasm binary, mark it as present but empty.

0 commit comments

Comments
 (0)