Skip to content

Commit cae1526

Browse files
authored
gh-121698 Emscripten: Use updated WebAssembly type reflection proposal (GH-121699)
1 parent 3086b86 commit cae1526

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Python/emscripten_trampoline.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
* https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/type-reflection/index.js
1111
*/
1212
EM_JS(int, _PyEM_detect_type_reflection, (), {
13-
return "Function" in WebAssembly;
13+
if (!("Function" in WebAssembly)) {
14+
return false;
15+
}
16+
if (WebAssembly.Function.type) {
17+
// Node v20
18+
Module.PyEM_CountArgs = (func) => WebAssembly.Function.type(wasmTable.get(func)).parameters.length;
19+
} else {
20+
// Node >= 22, v8-based browsers
21+
Module.PyEM_CountArgs = (func) => wasmTable.get(func).type().parameters.length;
22+
}
23+
return true;
1424
});
1525

1626
void
@@ -43,7 +53,7 @@ EM_JS(int, _PyEM_CountFuncParams, (PyCFunctionWithKeywords func),
4353
if (n !== undefined) {
4454
return n;
4555
}
46-
n = WebAssembly.Function.type(wasmTable.get(func)).parameters.length;
56+
n = Module.PyEM_CountArgs(func);
4757
_PyEM_CountFuncParams.cache.set(func, n);
4858
return n;
4959
}

0 commit comments

Comments
 (0)