-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1 | ||
2 | ||
(<JsProxy 6>, 'Error', 'test') | ||
3 | ||
true Error test |