summaryrefslogtreecommitdiff
path: root/core/ops_builtin_v8.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2022-09-02 11:43:39 +0100
committerGitHub <noreply@github.com>2022-09-02 12:43:39 +0200
commita74b2ecf379ddb1ff03c61d4e876153d7b4c45d2 (patch)
tree47b3fbe18ba35d59b4fb1062a53544f98656138a /core/ops_builtin_v8.rs
parent658d2cdff22646010915dc1f4a128de6c42a9f79 (diff)
fix(repl): don't terminate on unhandled error events (#15548)
Diffstat (limited to 'core/ops_builtin_v8.rs')
-rw-r--r--core/ops_builtin_v8.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs
index f8b59a760..abdbdedc8 100644
--- a/core/ops_builtin_v8.rs
+++ b/core/ops_builtin_v8.rs
@@ -43,7 +43,7 @@ pub(crate) fn init_builtins_v8() -> Vec<OpDecl> {
op_set_wasm_streaming_callback::decl(),
op_abort_wasm_streaming::decl(),
op_destructure_error::decl(),
- op_terminate::decl(),
+ op_dispatch_exception::decl(),
op_op_names::decl(),
op_apply_source_map::decl(),
op_set_format_exception_callback::decl(),
@@ -718,13 +718,27 @@ fn op_destructure_error(
JsError::from_v8_exception(scope, error.v8_value)
}
+/// Effectively throw an uncatchable error. This will terminate runtime
+/// execution before any more JS code can run, except in the REPL where it
+/// should just output the error to the console.
#[op(v8)]
-fn op_terminate(scope: &mut v8::HandleScope, exception: serde_v8::Value) {
+fn op_dispatch_exception(
+ scope: &mut v8::HandleScope,
+ exception: serde_v8::Value,
+) {
let state_rc = JsRuntime::state(scope);
let mut state = state_rc.borrow_mut();
- state.explicit_terminate_exception =
- Some(v8::Global::new(scope, exception.v8_value));
- scope.terminate_execution();
+ state
+ .dispatched_exceptions
+ .push_front(v8::Global::new(scope, exception.v8_value));
+ // Only terminate execution if there are no inspector sessions.
+ match state.inspector().try_borrow() {
+ Ok(inspector) if !inspector.has_active_sessions() => {
+ scope.terminate_execution();
+ }
+ // If the inspector is borrowed at this time, assume an inspector is active.
+ _ => {}
+ }
}
#[op(v8)]