Skip to content

webassembly/objpyproxy: Avoid throwing on implicit symbols access. #17683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions ports/webassembly/objpyproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,35 @@ const py_proxy_handler = {
if (prop === "_ref") {
return target._ref;
}
if (prop === "then") {
return null;
}

if (prop === Symbol.iterator) {
// Get the Python object iterator, and return a JavaScript generator.
const iter_ref = Module.ccall(
"proxy_c_to_js_get_iter",
"number",
["number"],
[target._ref],
);
return function* () {
const value = Module._malloc(3 * 4);
while (true) {
const valid = Module.ccall(
"proxy_c_to_js_iternext",
"number",
["number", "pointer"],
[iter_ref, value],
);
if (!valid) {
break;
// 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(
"proxy_c_to_js_get_iter",
"number",
["number"],
[target._ref],
);
return function* () {
const value = Module._malloc(3 * 4);
while (true) {
const valid = Module.ccall(
"proxy_c_to_js_iternext",
"number",
["number", "pointer"],
[iter_ref, value],
);
if (!valid) {
break;
}
yield proxy_convert_mp_to_js_obj_jsside(value);
}
yield proxy_convert_mp_to_js_obj_jsside(value);
}
Module._free(value);
};
Module._free(value);
};
}
return undefined;
}

const value = Module._malloc(3 * 4);
Expand Down
14 changes: 14 additions & 0 deletions tests/ports/webassembly/py_proxy_get.mjs
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 5 additions & 0 deletions tests/ports/webassembly/py_proxy_get.mjs.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
true
true
true
true
true
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy