Files
micropython/tests/ports/webassembly/py_proxy_identity.mjs
Damien George 24f395b5db tests/ports/webassembly: Move JsProxy identity test to separate file.
This test is not a PyProxy test, rather it's a JsProxy test.

Signed-off-by: Damien George <damien@micropython.org>
2025-09-26 14:02:11 +10:00

27 lines
614 B
JavaScript

// Test identity of PyProxy when they are the same Python object.
const mp = await (await import(process.argv[2])).loadMicroPython();
mp.runPython(`
l = []
`);
const l1 = mp.globals.get("l");
const l2 = mp.globals.get("l");
console.log(l1, l2);
console.log(l1 === l2);
globalThis.eventTarget = new EventTarget();
globalThis.event = new Event("event");
mp.runPython(`
import js
def callback(ev):
print("callback", ev)
js.eventTarget.addEventListener("event", callback)
js.eventTarget.dispatchEvent(js.event)
js.eventTarget.removeEventListener("event", callback)
js.eventTarget.dispatchEvent(js.event)
`);