mirror of
https://github.com/micropython/micropython.git
synced 2025-08-09 20:21:57 +02:00
webassembly/objpyproxy: Avoid throwing on symbol or iterator has-check.
JavaScript code uses "Symbol in object" to brand check its own proxies, and such checks should also work on the Python side. Signed-off-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
This commit is contained in:
committed by
Damien George
parent
16f9d7fdc3
commit
e33a0f4682
@@ -148,6 +148,12 @@ const py_proxy_handler = {
|
||||
};
|
||||
},
|
||||
has(target, prop) {
|
||||
// avoid throwing on `Symbol() in proxy` checks
|
||||
if (typeof prop !== "string") {
|
||||
// returns true only on iterator because other
|
||||
// symbols are not considered in the `get` trap
|
||||
return prop === Symbol.iterator;
|
||||
}
|
||||
return Module.ccall(
|
||||
"proxy_c_to_js_has_attr",
|
||||
"number",
|
||||
|
@@ -9,3 +9,5 @@ x = []
|
||||
const x = mp.globals.get("x");
|
||||
console.log("no_exist" in x);
|
||||
console.log("sort" in x);
|
||||
console.log(Symbol.toStringTag in x);
|
||||
console.log(Symbol.iterator in x);
|
||||
|
@@ -1,2 +1,4 @@
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
|
Reference in New Issue
Block a user