Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ pub(crate) fn exception_to_err_result<'s, 'i, T>(
Err(exception_to_err(scope, exception, in_promise, clear_error))
}

pub(crate) fn exception_to_err<'s, 'i>(
pub fn exception_to_err<'s, 'i>(
scope: &mut v8::PinScope<'s, 'i>,
exception: v8::Local<'s, v8::Value>,
mut in_promise: bool,
Expand Down
1 change: 1 addition & 0 deletions libs/core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub use crate::convert::FromV8;
pub use crate::convert::FromV8Scopeless;
pub use crate::convert::ToV8;
pub use crate::cppgc::GarbageCollected;
pub use crate::error::exception_to_err;
pub use crate::extensions::AccessorType;
pub use crate::extensions::Extension;
pub use crate::extensions::ExtensionArguments;
Expand Down
25 changes: 15 additions & 10 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,9 @@ impl MainWorker {
let undefined = v8::undefined(tc_scope);
dispatch_load_event_fn.call(tc_scope, undefined.into(), &[]);
if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(tc_scope, exception);
return Err(error);
return Err(deno_core::exception_to_err(
tc_scope, exception, false, true,
));
}
Ok(())
}
Expand All @@ -963,8 +964,9 @@ impl MainWorker {
let undefined = v8::undefined(tc_scope);
dispatch_unload_event_fn.call(tc_scope, undefined.into(), &[]);
if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(tc_scope, exception);
return Err(error);
return Err(deno_core::exception_to_err(
tc_scope, exception, false, true,
));
}
Ok(())
}
Expand All @@ -978,8 +980,9 @@ impl MainWorker {
let undefined = v8::undefined(tc_scope);
dispatch_process_exit_event_fn.call(tc_scope, undefined.into(), &[]);
if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(tc_scope, exception);
return Err(error);
return Err(deno_core::exception_to_err(
tc_scope, exception, false, true,
));
}
Ok(())
}
Expand All @@ -996,8 +999,9 @@ impl MainWorker {
let ret_val =
dispatch_beforeunload_event_fn.call(tc_scope, undefined.into(), &[]);
if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(tc_scope, exception);
return Err(error);
return Err(deno_core::exception_to_err(
tc_scope, exception, false, true,
));
}
let ret_val = ret_val.unwrap();
Ok(ret_val.is_false())
Expand All @@ -1020,8 +1024,9 @@ impl MainWorker {
&[],
);
if let Some(exception) = tc_scope.exception() {
let error = JsError::from_v8_exception(tc_scope, exception);
return Err(error);
return Err(deno_core::exception_to_err(
tc_scope, exception, false, true,
));
}
let ret_val = ret_val.unwrap();
Ok(ret_val.is_true())
Expand Down
19 changes: 19 additions & 0 deletions tests/specs/run/event_handler_throw_error/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"tests": {
"throw_in_unload": {
"args": "run throw_in_unload.ts",
"output": "error: Uncaught Error: unload error\n[WILDCARD]",
"exitCode": 1
},
"throw_in_beforeunload": {
"args": "run throw_in_beforeunload.ts",
"output": "error: Uncaught Error: beforeunload error\n[WILDCARD]",
"exitCode": 1
},
"throw_in_load": {
"args": "run throw_in_load.ts",
"output": "error: Uncaught Error: load error\n[WILDCARD]",
"exitCode": 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globalThis.addEventListener("beforeunload", () => {
throw new Error("beforeunload error");
});
3 changes: 3 additions & 0 deletions tests/specs/run/event_handler_throw_error/throw_in_load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globalThis.addEventListener("load", () => {
throw new Error("load error");
});
3 changes: 3 additions & 0 deletions tests/specs/run/event_handler_throw_error/throw_in_unload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
globalThis.addEventListener("unload", () => {
throw new Error("unload error");
});
Loading