Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "unhandledrejection" event support (#12994) #15080

Merged
merged 4 commits into from
Jul 14, 2022

Conversation

bartlomieju
Copy link
Member

Re-landing #12994, which was reverted in #15075 due
to flaky tests.

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 <[email protected]>
runtime/js/99_main.js Outdated Show resolved Hide resolved
@bartlomieju bartlomieju added this to the 1.24 milestone Jul 5, 2022
@@ -268,6 +268,10 @@
terminate: opSync.bind(null, "op_terminate"),
opNames: opSync.bind(null, "op_op_names"),
eventLoopHasMoreWork: opSync.bind(null, "op_event_loop_has_more_work"),
setPromiseRejectCallback: opSync.bind(
null,
"op_set_promise_reject_callback",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note - we'll need to provide an op_set_promise_reject_callback handler that rethrows the exception if we want to leverage op_set_uncaught_exception_callback to implement uncaughtException compat.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll export default handler in an "internal" namespace so we can still call it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, we're gonna land it as is and circle back if this is not enough to polyfill std/node

@bartlomieju bartlomieju merged commit 1a7259b into denoland:main Jul 14, 2022
@bartlomieju bartlomieju deleted the unhandled_rejection branch July 14, 2022 20:39
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Jul 14, 2022
bartlomieju added a commit that referenced this pull request Jul 14, 2022
bartlomieju added a commit to bartlomieju/deno that referenced this pull request Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants