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 /runtime/js | |
| 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 'runtime/js')
| -rw-r--r-- | runtime/js/99_main.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 4644d2d08..6c5ca3b59 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -344,6 +344,8 @@ function runtimeStart( } core.setUnhandledPromiseRejectionHandler(processUnhandledPromiseRejection); +core.setHandledPromiseRejectionHandler(processRejectionHandled); + // Notification that the core received an unhandled promise rejection that is about to // terminate the runtime. If we can handle it, attempt to do so. function processUnhandledPromiseRejection(promise, reason) { @@ -377,6 +379,20 @@ function processUnhandledPromiseRejection(promise, reason) { return false; } +function processRejectionHandled(promise, reason) { + const rejectionHandledEvent = new event.PromiseRejectionEvent( + "rejectionhandled", + { promise, reason }, + ); + + // Note that the handler may throw, causing a recursive "error" event + globalThis_.dispatchEvent(rejectionHandledEvent); + + if (typeof internals.nodeProcessRejectionHandledCallback !== "undefined") { + internals.nodeProcessRejectionHandledCallback(rejectionHandledEvent); + } +} + let hasBootstrapped = false; // Delete the `console` object that V8 automaticaly adds onto the global wrapper // object on context creation. We don't want this console object to shadow the |
