webassembly/objpyproxy: Avoid throwing on implicit symbols access.

This commit improves get handling by guarding against implicit unknown
symbols accessed directly by specific JS native APIs.

Fixes issue #17657.

Signed-off-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
This commit is contained in:
webreflection 2025-07-15 10:40:15 +02:00 committed by Damien George
parent 554f114f18
commit c72a3e528d
3 changed files with 46 additions and 26 deletions

View file

@ -165,10 +165,9 @@ const py_proxy_handler = {
if (prop === "_ref") {
return target._ref;
}
if (prop === "then") {
return null;
}
// ignore both then and all symbols but Symbol.iterator
if (prop === "then" || typeof prop !== "string") {
if (prop === Symbol.iterator) {
// Get the Python object iterator, and return a JavaScript generator.
const iter_ref = Module.ccall(
@ -194,6 +193,8 @@ const py_proxy_handler = {
Module._free(value);
};
}
return undefined;
}
const value = Module._malloc(3 * 4);
Module.ccall(

View file

@ -0,0 +1,14 @@
// Test `<py-obj> get <attr>` on the JavaScript side, which tests PyProxy.get.
const mp = await (await import(process.argv[2])).loadMicroPython();
mp.runPython(`
x = {"a": 1}
`);
const x = mp.globals.get("x");
console.log(x.a === 1);
console.log(x.b === undefined);
console.log(typeof x[Symbol.iterator] === "function");
console.log(x[Symbol.toStringTag] === undefined);
console.log(x.then === undefined);

View file

@ -0,0 +1,5 @@
true
true
true
true
true