From d4c8fa263d44aaafe400a130a52b88f42f738e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 11 Nov 2020 23:11:40 +0100 Subject: refactor(core): don't depend on get_identity_hash for promises (#8352) This commit changes how pending promise exceptions are stored in JsRuntime by using global handle to promise instead of its identity hash. --- core/runtime.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'core/runtime.rs') diff --git a/core/runtime.rs b/core/runtime.rs index 9766f71fa..e6e69636f 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -103,7 +103,8 @@ pub(crate) struct JsRuntimeState { pub(crate) shared_ab: Option>, pub(crate) js_recv_cb: Option>, pub(crate) js_macrotask_cb: Option>, - pub(crate) pending_promise_exceptions: HashMap>, + pub(crate) pending_promise_exceptions: + HashMap, v8::Global>, pending_dyn_mod_evaluate: HashMap, pending_mod_evaluate: Option, pub(crate) js_error_create_fn: Box, @@ -803,9 +804,9 @@ impl JsRuntime { ); let promise = v8::Local::::try_from(value) .expect("Expected to get promise as module evaluation result"); - let promise_id = promise.get_identity_hash(); + let promise_global = v8::Global::new(scope, promise); let mut state = state_rc.borrow_mut(); - state.pending_promise_exceptions.remove(&promise_id); + state.pending_promise_exceptions.remove(&promise_global); let promise_global = v8::Global::new(scope, promise); let module_global = v8::Global::new(scope, module); @@ -885,9 +886,9 @@ impl JsRuntime { ); let promise = v8::Local::::try_from(value) .expect("Expected to get promise as module evaluation result"); - let promise_id = promise.get_identity_hash(); + let promise_global = v8::Global::new(scope, promise); let mut state = state_rc.borrow_mut(); - state.pending_promise_exceptions.remove(&promise_id); + state.pending_promise_exceptions.remove(&promise_global); let promise_global = v8::Global::new(scope, promise); assert!( state.pending_mod_evaluate.is_none(), @@ -1385,7 +1386,14 @@ impl JsRuntime { return Ok(()); } - let key = { *state.pending_promise_exceptions.keys().next().unwrap() }; + let key = { + state + .pending_promise_exceptions + .keys() + .next() + .unwrap() + .clone() + }; let handle = state.pending_promise_exceptions.remove(&key).unwrap(); drop(state); -- cgit v1.2.3