mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
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.
This commit is contained in:
parent
c744ee2756
commit
d4c8fa263d
2 changed files with 17 additions and 9 deletions
|
@ -285,7 +285,7 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
|
|||
let mut state = state_rc.borrow_mut();
|
||||
|
||||
let promise = message.get_promise();
|
||||
let promise_id = promise.get_identity_hash();
|
||||
let promise_global = v8::Global::new(scope, promise);
|
||||
|
||||
match message.get_event() {
|
||||
v8::PromiseRejectEvent::PromiseRejectWithNoHandler => {
|
||||
|
@ -293,10 +293,10 @@ pub extern "C" fn promise_reject_callback(message: v8::PromiseRejectMessage) {
|
|||
let error_global = v8::Global::new(scope, error);
|
||||
state
|
||||
.pending_promise_exceptions
|
||||
.insert(promise_id, error_global);
|
||||
.insert(promise_global, error_global);
|
||||
}
|
||||
v8::PromiseRejectEvent::PromiseHandlerAddedAfterReject => {
|
||||
state.pending_promise_exceptions.remove(&promise_id);
|
||||
state.pending_promise_exceptions.remove(&promise_global);
|
||||
}
|
||||
v8::PromiseRejectEvent::PromiseRejectAfterResolved => {}
|
||||
v8::PromiseRejectEvent::PromiseResolveAfterResolved => {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue