From 0bb5bbc7a0ff7565a4c7fa4ebc8c69e02f76e6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 May 2023 15:40:41 +0200 Subject: 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 --- ext/node/polyfills/process.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'ext/node') diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index d2f220734..2dc10d7b1 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -716,9 +716,9 @@ internals.__bootstrapNodeProcess = function ( core.setMacrotaskCallback(runNextTicks); enableNextTick(); - // TODO(bartlomieju): this is buggy, see https://github.com/denoland/deno/issues/16928 - // We should use a specialized API in 99_main.js instead - globalThis.addEventListener("unhandledrejection", (event) => { + // Install special "unhandledrejection" handler, that will be called + // last. + internals.nodeProcessUnhandledRejectionCallback = (event) => { if (process.listenerCount("unhandledRejection") === 0) { // The Node.js default behavior is to raise an uncaught exception if // an unhandled rejection occurs and there are no unhandledRejection @@ -734,7 +734,7 @@ internals.__bootstrapNodeProcess = function ( event.preventDefault(); process.emit("unhandledRejection", event.reason, event.promise); - }); + }; globalThis.addEventListener("error", (event) => { if (process.listenerCount("uncaughtException") > 0) { -- cgit v1.2.3