From fc6f61227d19643155b38ba97c14f76bd2a0dfd1 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 28 Oct 2019 15:20:58 -0700 Subject: [PATCH 1/2] Throw a WebAssembly.RuntimeError --- src/preamble.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/preamble.js b/src/preamble.js index ec61ee660921..1c3ff44e7f18 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -719,17 +719,21 @@ 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. + throw new WebAssembly.RuntimeError(what); } #if RELOCATABLE From 9e577c40b24048647cd98fe2ada17d8439920995 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 28 Oct 2019 15:22:40 -0700 Subject: [PATCH 2/2] fix --- src/preamble.js | 4 ++++ src/wasm2js.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/preamble.js b/src/preamble.js index 1c3ff44e7f18..aac253b84915 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -733,7 +733,11 @@ function abort(what) { // 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 diff --git a/src/wasm2js.js b/src/wasm2js.js index c91cb13212db..09666af3ab76 100644 --- a/src/wasm2js.js +++ b/src/wasm2js.js @@ -69,7 +69,9 @@ WebAssembly = { }); } }; - } + }, + + RuntimeError: Error }; // We don't need to actually download a wasm binary, mark it as present but empty.