]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-121698 Emscripten: Use updated WebAssembly type reflection proposal (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 14 Jul 2024 10:01:03 +0000 (12:01 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Jul 2024 10:01:03 +0000 (12:01 +0200)
(cherry picked from commit cae15267166e217822e3c58ac22b7817162f323a)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
Python/emscripten_trampoline.c

index 2a80ec4f18d7578be6019d6b0ed21c6e768a1eb4..960c6b4a2ef995dfa839601778eb89ee1f0ab69e 100644 (file)
  * 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;
 }