Skip to content

Commit

Permalink
Throw a wasm RuntimeError in abort (#9730)
Browse files Browse the repository at this point in the history
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 #9715
  • Loading branch information
kripken committed Oct 29, 2019
1 parent 7e57c5a commit 8d265e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,17 +719,25 @@ function abort(what) {
EXITSTATUS = 1;

#if ASSERTIONS == 0
throw 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
what = 'abort(' + what + '). Build with -s ASSERTIONS=1 for more info.';
#else
var extra = '';
var output = 'abort(' + what + ') at ' + stackTrace() + extra;
var output = 'abort(' + what + ') at ' + stackTrace();
#if EMTERPRETIFY_ASYNC
abortDecorators.forEach(function(decorator) {
output = decorator(output, what);
});
#endif
throw output;
what = output;
#endif // ASSERTIONS

// Throw a wasm runtime error, because a JS error might be seen as a foreign
// exception, which means we'd run destructors on it. We need the error to
// simply make the program stop.
#if WASM
throw new WebAssembly.RuntimeError(what);
#else
throw what;
#endif
}

#if RELOCATABLE
Expand Down
4 changes: 3 additions & 1 deletion src/wasm2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ WebAssembly = {
});
}
};
}
},

RuntimeError: Error
};

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

0 comments on commit 8d265e6

Please sign in to comment.