1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
denoland-deno/cli/tests/testdata/node/rejection_handled_web_process.ts
Bartek Iwańczuk 7471587d29
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>
2024-01-12 22:10:42 +00:00

26 lines
628 B
TypeScript

import chalk from "npm:chalk";
import process from "node:process";
console.log(chalk.red("Hello world!"));
globalThis.addEventListener("unhandledrejection", (e) => {
console.log('globalThis.addEventListener("unhandledrejection");');
e.preventDefault();
});
globalThis.addEventListener("rejectionhandled", (_) => {
console.log("Web rejectionhandled");
});
process.on("rejectionHandled", (_) => {
console.log("Node rejectionHandled");
});
const a = Promise.reject(1);
setTimeout(() => {
a.catch(() => console.log("Added catch handler to the promise"));
}, 10);
setTimeout(() => {
console.log("Success");
}, 50);