diff --git a/core/runtime/jsrealm.rs b/core/runtime/jsrealm.rs index b99737923..c997a32f2 100644 --- a/core/runtime/jsrealm.rs +++ b/core/runtime/jsrealm.rs @@ -76,6 +76,7 @@ pub struct ContextState { pub(crate) get_error_class_fn: GetErrorClassFn, pub(crate) external_ops_tracker: ExternalOpsTracker, pub(crate) promises: Promises, + pub(crate) internal_promise_sym: RefCell>>>, } type PromiseId = i32; @@ -130,6 +131,7 @@ impl ContextState { unrefed_ops: Default::default(), external_ops_tracker, promises: Default::default(), + internal_promise_sym: Default::default(), } } } @@ -219,6 +221,7 @@ impl JsRealmInner { state.exception_state.prepare_to_destroy(); std::mem::take(&mut *state.js_event_loop_tick_cb.borrow_mut()); std::mem::take(&mut *state.js_wasm_streaming_cb.borrow_mut()); + std::mem::take(&mut *state.internal_promise_sym.borrow_mut()); { let ctx = self.context().open(isolate); diff --git a/core/runtime/jsruntime.rs b/core/runtime/jsruntime.rs index 092e116ab..993dfa17d 100644 --- a/core/runtime/jsruntime.rs +++ b/core/runtime/jsruntime.rs @@ -1420,7 +1420,12 @@ impl JsRuntime { /// Grab and store JavaScript bindings to callbacks necessary for the /// JsRuntime to operate properly. fn store_js_callbacks(&mut self, realm: &JsRealm, will_snapshot: bool) { - let (event_loop_tick_cb, build_custom_error_cb, wasm_instance_fn) = { + let ( + event_loop_tick_cb, + build_custom_error_cb, + wasm_instance_fn, + internal_promise_sym, + ) = { let scope = &mut realm.handle_scope(self.v8_isolate()); let context = realm.context(); let context_local = v8::Local::new(scope, context); @@ -1464,15 +1469,23 @@ impl JsRuntime { } } + let s = + FastString::from_static("Deno.core.internalPromiseId").v8_string(scope); + let sym = v8::Symbol::for_key(scope, s); ( v8::Global::new(scope, event_loop_tick_cb), v8::Global::new(scope, build_custom_error_cb), wasm_instance_fn.map(|f| v8::Global::new(scope, f)), + v8::Global::new(scope, sym), ) }; // Put global handles in the realm's ContextState let state_rc = realm.0.state(); + state_rc + .internal_promise_sym + .borrow_mut() + .replace(Rc::new(internal_promise_sym)); state_rc .js_event_loop_tick_cb .borrow_mut() diff --git a/core/runtime/ops.rs b/core/runtime/ops.rs index aa8bec4a5..2c0c11238 100644 --- a/core/runtime/ops.rs +++ b/core/runtime/ops.rs @@ -112,9 +112,10 @@ pub fn make_promise( let context = JsRealm::state_from_scope(scope); let prom = v8::PromiseResolver::new(scope).unwrap(); let p = prom.get_promise(scope); - let s = - FastString::from_static("Deno.core.internalPromiseId").v8_string(scope); - let sym = v8::Symbol::for_key(scope, s); + let sym = v8::Local::new( + scope, + &*context.internal_promise_sym.borrow().clone().unwrap(), + ); let prom = v8::Global::new(scope, prom); let id = context.promises.register_new(prom.clone()); let id_v = v8::Integer::new(scope, id);