diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-09-01 23:01:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-01 23:01:05 +0200 |
commit | 307d84cfa5c1489ddfc8477f6561676356399e8c (patch) | |
tree | 5a65bdf5a3be832ee26852461b087552a552d22d /core/error.rs | |
parent | 58e76098e6325ad16d552924d58c33bad6573c07 (diff) |
refactor(core): Move optional callbacks from `JsRuntimeState` to `ContextState` (#15599)
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.
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 bc8a3195b..3a36a6ab9 100644 --- a/core/error.rs +++ b/core/error.rs @@ -218,10 +218,10 @@ impl JsError { let msg = v8::Exception::create_message(scope, exception); let mut exception_message = None; - let state_rc = JsRuntime::state(scope); + let realm_state_rc = JsRealm::state_from_scope(scope); let js_format_exception_cb = - state_rc.borrow().js_format_exception_cb.clone(); + realm_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(); @@ -286,6 +286,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 |