diff --git a/cpython/patches/0008-Make-Emscripten-trampolines-work-with-JSPI.patch b/cpython/patches/0008-Make-Emscripten-trampolines-work-with-JSPI.patch index 6ed0d32977a..d2ed9627c70 100644 --- a/cpython/patches/0008-Make-Emscripten-trampolines-work-with-JSPI.patch +++ b/cpython/patches/0008-Make-Emscripten-trampolines-work-with-JSPI.patch @@ -270,7 +270,7 @@ index 0000000000..d2d24a6e0a + if (n !== undefined) { + return n; + } -+ n = WebAssembly.Function.type(wasmTable.get(func)).parameters.length; ++ n = wasmFunctionType(wasmTable.get(func)).parameters.length; + _PyEM_CountFuncParams.cache.set(func, n); + return n; +} diff --git a/src/core/pre.js b/src/core/pre.js index a77d78a3cb8..e57eabfa833 100644 --- a/src/core/pre.js +++ b/src/core/pre.js @@ -99,3 +99,13 @@ Module.iterObject = function* (object) { } } }; + +function wasmFunctionType(wasm_func) { + if (!WebAssembly.Function) { + throw new Error("No type reflection"); + } + if (WebAssembly.Function.type) { + return WebAssembly.Function.type(wasm_func); + } + return wasm_func.type(); +} diff --git a/src/core/stack_switching/suspenders.mjs b/src/core/stack_switching/suspenders.mjs index 758ce9c9778..cd66a4b10a7 100644 --- a/src/core/stack_switching/suspenders.mjs +++ b/src/core/stack_switching/suspenders.mjs @@ -154,7 +154,7 @@ export function createPromising(wasm_func) { if (promisingFunctionMap.has(wasm_func)) { return promisingFunctionMap.get(wasm_func); } - const type = WebAssembly.Function.type(wasm_func); + const type = wasmFunctionType(wasm_func); const module = getPromisingModule(type); const instance = new WebAssembly.Instance(module, { e: { i: wasm_func, s: suspenderGlobal },