diff options
| author | Damien George <damien@micropython.org> | 2024-05-09 15:11:21 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-05-13 11:52:17 +1000 |
| commit | a67e326cb9753f53e14a42b347133a571f972140 (patch) | |
| tree | eeea3e4a1a8e76b67914e16b1ef87bd62b4788eb /tests | |
| parent | 3f34be69c77dfbd1533af1f04ea460d7da2d118a (diff) | |
webassembly/proxy_c: Ensure objs thrown into generators are exceptions.
This commit defines a new `JsException` exception type which is used on the
Python side to wrap JavaScript errors. That's then used when a JavaScript
Promise is rejected, and the reason is then converted to a `JsException`
for the Python side to handle.
This new exception is exposed as `jsffi.JsException`.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ports/webassembly/await_error_handling.mjs | 22 | ||||
| -rw-r--r-- | tests/ports/webassembly/await_error_handling.mjs.exp | 5 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/ports/webassembly/await_error_handling.mjs b/tests/ports/webassembly/await_error_handling.mjs new file mode 100644 index 000000000..067bc2513 --- /dev/null +++ b/tests/ports/webassembly/await_error_handling.mjs @@ -0,0 +1,22 @@ +// Test await'ing on a JavaScript async function that throws a JavaScript Error. + +const mp = await (await import(process.argv[2])).loadMicroPython(); + +globalThis.foo = async () => { + console.log(2); + throw Error("test"); +}; + +await mp.runPythonAsync(` +import js, jsffi +print(1) +try: + await js.foo() +except jsffi.JsException as er: + error = er +print(error) +print(3) +`); + +const error = mp.globals.get("error"); +console.log(error instanceof Error, error.name, error.message); diff --git a/tests/ports/webassembly/await_error_handling.mjs.exp b/tests/ports/webassembly/await_error_handling.mjs.exp new file mode 100644 index 000000000..149f8914d --- /dev/null +++ b/tests/ports/webassembly/await_error_handling.mjs.exp @@ -0,0 +1,5 @@ +1 +2 +(<JsProxy 6>, 'Error', 'test') +3 +true Error test |
