From 61ba04ca096add7e450ddb690fa5895706fdd79b Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 22 Jun 2023 18:53:22 -0700 Subject: [PATCH] Changes for JSPI --- src/library.js | 2 +- src/library_dylink.js | 3 ++- src/parseTools.js | 2 +- src/preamble.js | 7 +++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/library.js b/src/library.js index b33d2ea65..e17fe94f0 100644 --- a/src/library.js +++ b/src/library.js @@ -1206,7 +1206,7 @@ addToLibrary({ #if EXCEPTION_STACK_TRACES throw new EmscriptenSjLj; #else - throw Infinity; + throw Module.wrapException(Infinity); #endif }, #elif !SUPPORT_LONGJMP diff --git a/src/library_dylink.js b/src/library_dylink.js index 736f73c66..fd769f7cc 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js @@ -73,6 +73,7 @@ var LibraryDylink = { #if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten' $createInvokeFunction__internal: true, $createInvokeFunction__deps: ['$dynCall', 'setThrew'], + $createInvokeFunction__postset: "if(!Module.createInvoke) { Module.createInvoke = Module.createInvokeFunction; }", $createInvokeFunction: (sig) => { return function() { var sp = stackSave(); @@ -125,7 +126,7 @@ var LibraryDylink = { // Asm.js-style exception handling: invoke wrapper generation else if (symName.startsWith('invoke_')) { // Create (and cache) new invoke_ functions on demand. - sym = wasmImports[symName] = createInvokeFunction(symName.split('_')[1]); + sym = wasmImports[symName] = Module.createInvoke(symName.split('_')[1]); } #endif #if !DISABLE_EXCEPTION_CATCHING diff --git a/src/parseTools.js b/src/parseTools.js index a069d0e21..0f99ab28a 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -538,7 +538,7 @@ function makeThrow(excPtr) { } return `assert(false, '${assertInfo}');`; } - return `throw ${excPtr};`; + return `throw Module.wrapException(${excPtr});`; } function storeException(varName, excPtr) { diff --git a/src/preamble.js b/src/preamble.js index d4041cd26..6f44924cf 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -14,6 +14,10 @@ // An online HTML version (which may be of a different version of Emscripten) // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html +if(!Module.wrapException) { + Module.wrapException = (e) => e; +} + #if BENCHMARK Module.realPrint = out; out = err = () => {}; @@ -928,6 +932,9 @@ function instantiateAsync(binary, binaryFile, imports, callback) { // Create the wasm instance. // Receives the wasm imports, returns the exports. function createWasm() { + if (Module.adjustWasmImports) { + Module.adjustWasmImports(wasmImports); + } // prepare imports var info = { #if MINIFY_WASM_IMPORTED_MODULES -- 2.25.1