diff options
author | Hood Chatham <roberthoodchatham@gmail.com> | 2024-07-14 11:25:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-14 11:25:09 +0200 |
commit | cae15267166e217822e3c58ac22b7817162f323a (patch) | |
tree | 7a388fc58b997ce86c7bd6bd19cb6005e3dd2717 /Python/emscripten_trampoline.c | |
parent | 3086b86cfda829e23a71569908edbfbcdc16327f (diff) | |
download | cpython-cae15267166e217822e3c58ac22b7817162f323a.tar.gz cpython-cae15267166e217822e3c58ac22b7817162f323a.zip |
gh-121698 Emscripten: Use updated WebAssembly type reflection proposal (GH-121699)
Diffstat (limited to 'Python/emscripten_trampoline.c')
-rw-r--r-- | Python/emscripten_trampoline.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/emscripten_trampoline.c b/Python/emscripten_trampoline.c index 2a80ec4f18d..960c6b4a2ef 100644 --- a/Python/emscripten_trampoline.c +++ b/Python/emscripten_trampoline.c @@ -10,7 +10,17 @@ * https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/type-reflection/index.js */ EM_JS(int, _PyEM_detect_type_reflection, (), { - return "Function" in WebAssembly; + if (!("Function" in WebAssembly)) { + return false; + } + if (WebAssembly.Function.type) { + // Node v20 + Module.PyEM_CountArgs = (func) => WebAssembly.Function.type(wasmTable.get(func)).parameters.length; + } else { + // Node >= 22, v8-based browsers + Module.PyEM_CountArgs = (func) => wasmTable.get(func).type().parameters.length; + } + return true; }); void @@ -43,7 +53,7 @@ EM_JS(int, _PyEM_CountFuncParams, (PyCFunctionWithKeywords func), if (n !== undefined) { return n; } - n = WebAssembly.Function.type(wasmTable.get(func)).parameters.length; + n = Module.PyEM_CountArgs(func); _PyEM_CountFuncParams.cache.set(func, n); return n; } |