summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-11-11 23:11:40 +0100
committerGitHub <noreply@github.com>2020-11-11 23:11:40 +0100
commitd4c8fa263d44aaafe400a130a52b88f42f738e8d (patch)
treefe40668fda84fd3c3d22d7b6323fc03bd267dff8 /core/runtime.rs
parentc744ee2756d9cd812d47650fae52ef855cea9e53 (diff)
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.
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs20
1 files changed, 14 insertions, 6 deletions
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<v8::Global<v8::SharedArrayBuffer>>,
pub(crate) js_recv_cb: Option<v8::Global<v8::Function>>,
pub(crate) js_macrotask_cb: Option<v8::Global<v8::Function>>,
- pub(crate) pending_promise_exceptions: HashMap<i32, v8::Global<v8::Value>>,
+ pub(crate) pending_promise_exceptions:
+ HashMap<v8::Global<v8::Promise>, v8::Global<v8::Value>>,
pending_dyn_mod_evaluate: HashMap<ModuleLoadId, DynImportModEvaluate>,
pending_mod_evaluate: Option<ModEvaluate>,
pub(crate) js_error_create_fn: Box<JsErrorCreateFn>,
@@ -803,9 +804,9 @@ impl JsRuntime {
);
let promise = v8::Local::<v8::Promise>::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::<v8::Promise>::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);