diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-07-04 21:14:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 21:14:58 +0200 |
commit | f7af0b01a59aaac91473e2f920137004d39a310a (patch) | |
tree | f04bdb8c0acba2730cff47a91b249e15543435a8 /core/bindings.rs | |
parent | 691d67b3ed788e30b17600d1dc472ecfa83b6585 (diff) |
feat: add "unhandledrejection" event support (#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>
Diffstat (limited to 'core/bindings.rs')
-rw-r--r-- | core/bindings.rs | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index a88e54af7..47632d00d 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -282,14 +282,6 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { let state_rc = JsRuntime::state(scope); let mut state = state_rc.borrow_mut(); - // Node compat: perform synchronous process.emit("unhandledRejection"). - // - // Note the callback follows the (type, promise, reason) signature of Node's - // internal promiseRejectHandler from lib/internal/process/promises.js, not - // the (promise, reason) signature of the "unhandledRejection" event listener. - // - // Short-circuits Deno's regular unhandled rejection logic because that's - // a) asynchronous, and b) always terminates. if let Some(js_promise_reject_cb) = state.js_promise_reject_cb.clone() { let js_uncaught_exception_cb = state.js_uncaught_exception_cb.clone(); drop(state); // Drop borrow, callbacks can call back into runtime. @@ -323,6 +315,7 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { } if tc_scope.has_caught() { + // TODO(bartlomieju): ensure that TODO provided below is still valid. // If we get here, an exception was thrown by the unhandledRejection // handler and there is ether no uncaughtException handler or the // handler threw an exception of its own. @@ -340,7 +333,6 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) { } else { let promise = message.get_promise(); let promise_global = v8::Global::new(scope, promise); - match message.get_event() { PromiseRejectWithNoHandler => { let error = message.get_value().unwrap(); |