diff options
author | Andreu Botella <andreu@andreubotella.com> | 2022-12-20 11:09:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-20 20:09:16 +0100 |
commit | fcca54d3ba2b5c1f9f45b70fde46ba07bde4d07b (patch) | |
tree | be02aefc24c8ce469058bc7a62cd32307434fac1 /core/error.rs | |
parent | 748ce0a435fee2b4f10fe027fa7e5e7224ac23c9 (diff) |
fix(core): Have custom errors be created in the right realm (#17050)
Although PR #16366 did not fully revert `deno_core`'s support for
realms, since `JsRealm` still existed after that, it did remove the
`ContextState` struct, originally introduced in #14734. This change made
`js_build_custom_error_cb`, among other properties, a per-runtime
callback, rather than per-realm, which cause a bug where errors thrown
from an op would always be constructed in the main realm, rather than in
the current one.
This change adds back `ContextState` to fix this bug, adds back the
`known_realms` field of `JsRuntimeState` (needed to be able to drop the
callback when snapshotting), and also relands #14750, which adds the
`js_realm_sync_ops` test for this bug that was removed in #16366.
Diffstat (limited to 'core/error.rs')
-rw-r--r-- | core/error.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/error.rs b/core/error.rs index 2ee97c0ac..dc50b4d73 100644 --- a/core/error.rs +++ b/core/error.rs @@ -1,6 +1,7 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::runtime::GetErrorClassFn; +use crate::runtime::JsRealm; use crate::runtime::JsRuntime; use crate::source_map::apply_source_map; use crate::source_map::get_source_line; @@ -98,7 +99,7 @@ pub fn to_v8_error<'a>( error: &Error, ) -> v8::Local<'a, v8::Value> { let tc_scope = &mut v8::TryCatch::new(scope); - let cb = JsRuntime::state(tc_scope) + let cb = JsRealm::state_from_scope(tc_scope) .borrow() .js_build_custom_error_cb .clone() |