mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
fix(node): fire 'unhandledrejection' event when using node: or npm: imports (#19235)
This commit fixes emitting "unhandledrejection" event when there are "node:" or "npm:" imports. Before this commit the Node "unhandledRejection" event was emitted using a regular listener for Web "unhandledrejection" event. This listener was installed before any user listener had a chance to be installed which effectively prevent emitting "unhandledrejection" events to user code. Closes https://github.com/denoland/deno/issues/16928
This commit is contained in:
parent
787e1f0f92
commit
0bb5bbc7a0
7 changed files with 80 additions and 5 deletions
|
@ -346,7 +346,8 @@ function promiseRejectCallback(type, promise, reason) {
|
|||
}
|
||||
|
||||
return !!globalThis_.onunhandledrejection ||
|
||||
event.listenerCount(globalThis_, "unhandledrejection") > 0;
|
||||
event.listenerCount(globalThis_, "unhandledrejection") > 0 ||
|
||||
typeof internals.nodeProcessUnhandledRejectionCallback !== "undefined";
|
||||
}
|
||||
|
||||
function promiseRejectMacrotaskCallback() {
|
||||
|
@ -383,6 +384,15 @@ function promiseRejectMacrotaskCallback() {
|
|||
globalThis_.dispatchEvent(rejectionEvent);
|
||||
globalThis_.removeEventListener("error", errorEventCb);
|
||||
|
||||
// If event was not yet prevented, try handing it off to Node compat layer
|
||||
// (if it was initialized)
|
||||
if (
|
||||
!rejectionEvent.defaultPrevented &&
|
||||
typeof internals.nodeProcessUnhandledRejectionCallback !== "undefined"
|
||||
) {
|
||||
internals.nodeProcessUnhandledRejectionCallback(rejectionEvent);
|
||||
}
|
||||
|
||||
// If event was not prevented (or "unhandledrejection" listeners didn't
|
||||
// throw) we will let Rust side handle it.
|
||||
if (rejectionEvent.defaultPrevented) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue