From fcca54d3ba2b5c1f9f45b70fde46ba07bde4d07b Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 20 Dec 2022 11:09:16 -0800 Subject: 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. --- core/error.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'core/error.rs') 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() -- cgit v1.2.3