diff options
| author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-12 23:10:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-12 22:10:42 +0000 |
| commit | 7471587d29096a8de95a530f2132214ab9c08afa (patch) | |
| tree | d9de4d8e894f7c744c75029898bc1fdd850a758a /ext/node | |
| parent | 288774c5eda35c27db21526bbcc94488c534137c (diff) | |
feat: "rejectionhandled" Web event and "rejectionHandled" Node event (#21875)
This commit adds support for "rejectionhandled" Web Event and
"rejectionHandled" Node event.
```js
import process from "node:process";
process.on("rejectionHandled", (promise) => {
console.log("rejectionHandled", reason, promise);
});
window.addEventListener("rejectionhandled", (event) => {
console.log("rejectionhandled", event.reason, event.promise);
});
```
---------
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
Diffstat (limited to 'ext/node')
| -rw-r--r-- | ext/node/polyfills/process.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index 3d5009b90..1edcccc00 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -75,7 +75,6 @@ import { buildAllowedFlags } from "ext:deno_node/internal/process/per_thread.mjs const notImplementedEvents = [ "multipleResolves", - "rejectionHandled", "worker", ]; @@ -746,6 +745,7 @@ export const removeListener = process.removeListener; export const removeAllListeners = process.removeAllListeners; let unhandledRejectionListenerCount = 0; +let rejectionHandledListenerCount = 0; let uncaughtExceptionListenerCount = 0; let beforeExitListenerCount = 0; let exitListenerCount = 0; @@ -755,6 +755,9 @@ process.on("newListener", (event: string) => { case "unhandledRejection": unhandledRejectionListenerCount++; break; + case "rejectionHandled": + rejectionHandledListenerCount++; + break; case "uncaughtException": uncaughtExceptionListenerCount++; break; @@ -775,6 +778,9 @@ process.on("removeListener", (event: string) => { case "unhandledRejection": unhandledRejectionListenerCount--; break; + case "rejectionHandled": + rejectionHandledListenerCount--; + break; case "uncaughtException": uncaughtExceptionListenerCount--; break; @@ -837,6 +843,16 @@ function synchronizeListeners() { internals.nodeProcessUnhandledRejectionCallback = undefined; } + // Install special "handledrejection" handler, that will be called + // last. + if (rejectionHandledListenerCount > 0) { + internals.nodeProcessRejectionHandledCallback = (event) => { + process.emit("rejectionHandled", event.reason, event.promise); + }; + } else { + internals.nodeProcessRejectionHandledCallback = undefined; + } + if (uncaughtExceptionListenerCount > 0) { globalThis.addEventListener("error", processOnError); } else { |
