[3.13] gh-121698 Emscripten: Use updated WebAssembly type reflection proposal (GH-121699) (GH-121745)

(cherry picked from commit cae1526716)

Co-authored-by: Hood Chatham <roberthoodchatham@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-07-14 12:01:03 +02:00 committed by GitHub
parent 35d425e300
commit f17057dab1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 2 deletions

View File

@ -10,7 +10,17 @@
* https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/type-reflection/index.js * https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/type-reflection/index.js
*/ */
EM_JS(int, _PyEM_detect_type_reflection, (), { 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 void
@ -43,7 +53,7 @@ EM_JS(int, _PyEM_CountFuncParams, (PyCFunctionWithKeywords func),
if (n !== undefined) { if (n !== undefined) {
return n; return n;
} }
n = WebAssembly.Function.type(wasmTable.get(func)).parameters.length; n = Module.PyEM_CountArgs(func);
_PyEM_CountFuncParams.cache.set(func, n); _PyEM_CountFuncParams.cache.set(func, n);
return n; return n;
} }