diff options
author | Andreu Botella <andreu@andreubotella.com> | 2023-01-14 19:39:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-15 09:09:00 +0530 |
commit | 05ef925eb095ae603f694fe8172ddcbd5b19b9b2 (patch) | |
tree | f4cd7fe88a62f5f427c2dba77f9902b13abaf501 /core/error.rs | |
parent | df8bfa26be69af46b8f166e255330b5ba8d48893 (diff) |
refactor(core): Move optional callbacks from `JsRuntimeState` to `ContextState` (#17422)
The `JsRuntimeState` struct stores a number of JS callbacks that are
used either in the event loop or when interacting with V8. Some of these
callback fields are vectors of callbacks, and therefore could plausibly
store at least one callback per realm. However, some of those fields are
`Option<v8::Global<v8::Function>>`, which would make the callbacks set
by a realm override the one that might have been set by a different
realm.
As it turns out, all of the current such optional callbacks
(`js_promise_reject_cb`, `js_format_exception_cb` and
`js_wasm_streaming_cb`) are only used from inside a realm, and therefore
this change makes it so such callbacks can only be set from inside a
realm, and will only affect that realm.
This is a reland of #15599.
Towards #13239.
Diffstat (limited to 'core/error.rs')
-rw-r--r-- | core/error.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/core/error.rs b/core/error.rs index 02ed95ef7..a682c69aa 100644 --- a/core/error.rs +++ b/core/error.rs @@ -312,10 +312,10 @@ impl JsError { let msg = v8::Exception::create_message(scope, exception); let mut exception_message = None; - let state_rc = JsRuntime::state(scope); + let context_state_rc = JsRealm::state_from_scope(scope); let js_format_exception_cb = - state_rc.borrow().js_format_exception_cb.clone(); + context_state_rc.borrow().js_format_exception_cb.clone(); if let Some(format_exception_cb) = js_format_exception_cb { let format_exception_cb = format_exception_cb.open(scope); let this = v8::undefined(scope).into(); @@ -381,6 +381,7 @@ impl JsError { let mut source_line = None; let mut source_line_frame_index = None; { + let state_rc = JsRuntime::state(scope); let state = &mut *state_rc.borrow_mut(); // When the stack frame array is empty, but the source location given by |