mirror of
https://github.com/denoland/deno.git
synced 2025-01-26 00:47:50 -05:00
1a7259b04b
Relanding #12994 This commit adds support for "unhandledrejection" event. This event will trigger event listeners registered using: "globalThis.addEventListener("unhandledrejection") "globalThis.onunhandledrejection" This is done by registering a default handler using "Deno.core.setPromiseRejectCallback" that allows to handle rejected promises in JavaScript instead of Rust. This commit will make it possible to polyfill "process.on("unhandledRejection")" in the Node compat layer. Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
11 lines
270 B
JavaScript
11 lines
270 B
JavaScript
globalThis.addEventListener("unhandledrejection", (e) => {
|
|
console.log("unhandled rejection at:", e.promise, "reason:", e.reason);
|
|
e.preventDefault();
|
|
});
|
|
|
|
function Foo() {
|
|
this.bar = Promise.reject(new Error("bar not available"));
|
|
}
|
|
|
|
new Foo();
|
|
Promise.reject();
|