Commit 7698bcc
fix(runtime): display proper error when throwing in event handlers (#32663)
## Summary
- Fixes `"Uncaught null"` being displayed instead of the actual error
when throwing in `unload`, `beforeunload`, `load`, or process
`exit`/`beforeExit` event handlers
- Root cause: `reportException` in JS calls `op_dispatch_exception`
which stores the real exception in `ExceptionState` and terminates
execution. The Rust-side dispatch functions then checked
`tc_scope.exception()` which returned `null` (the termination exception)
instead of the stored one
- Fix: use `exception_to_err` which properly checks `ExceptionState` for
a dispatched exception before falling back to `tc_scope.exception()`
Before:
```
error: Uncaught null
```
After:
```
error: Uncaught Error: foo
globalThis.addEventListener("unload", () => { throw new Error("foo"); });
^
at file:///...$deno$eval.mts:1:53
at innerInvokeEventListeners (ext:deno_web/02_event.js:781:9)
...
```
Closes #29087
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 9eed28a commit 7698bcc
File tree
7 files changed
+45
-11
lines changed- libs/core
- runtime
- tests/specs/run/event_handler_throw_error
7 files changed
+45
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1313 | 1313 | | |
1314 | 1314 | | |
1315 | 1315 | | |
1316 | | - | |
| 1316 | + | |
1317 | 1317 | | |
1318 | 1318 | | |
1319 | 1319 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
946 | 946 | | |
947 | 947 | | |
948 | 948 | | |
949 | | - | |
950 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
951 | 952 | | |
952 | 953 | | |
953 | 954 | | |
| |||
963 | 964 | | |
964 | 965 | | |
965 | 966 | | |
966 | | - | |
967 | | - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
968 | 970 | | |
969 | 971 | | |
970 | 972 | | |
| |||
978 | 980 | | |
979 | 981 | | |
980 | 982 | | |
981 | | - | |
982 | | - | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
983 | 986 | | |
984 | 987 | | |
985 | 988 | | |
| |||
1032 | 1035 | | |
1033 | 1036 | | |
1034 | 1037 | | |
1035 | | - | |
1036 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
1037 | 1041 | | |
1038 | 1042 | | |
1039 | 1043 | | |
| |||
1056 | 1060 | | |
1057 | 1061 | | |
1058 | 1062 | | |
1059 | | - | |
1060 | | - | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
1061 | 1066 | | |
1062 | 1067 | | |
1063 | 1068 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments