diff options
author | ud2 <sjx233@qq.com> | 2023-05-08 06:27:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 00:27:59 +0200 |
commit | 40987178c4f9baf54599b502f943be76f42d6f85 (patch) | |
tree | 30892bb0a95bf68f48b95ef1b90bc94afb169fc1 /core/ops_builtin_v8.rs | |
parent | 7e1ae655720de72fd555bb1746bb35f5d17f39f6 (diff) |
fix(core): always report the first error on unhandled rejection (#18992)
The root cause of denoland/deno_std#3320, I believe, is that
`pending_promise_rejections` is a `HashMap` whose entries are in
arbitrary order, and as a result either of the two errors (`AddrInUse`
and `TypeError`) may be selected when determining which one to report. I
changed the field to a `VecDeque` so that the first error (`AddrInUse`
in this case) is always selected.
Diffstat (limited to 'core/ops_builtin_v8.rs')
-rw-r--r-- | core/ops_builtin_v8.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs index a77e7a7e6..8da484225 100644 --- a/core/ops_builtin_v8.rs +++ b/core/ops_builtin_v8.rs @@ -894,7 +894,7 @@ fn op_store_pending_promise_rejection<'a>( let error_global = v8::Global::new(scope, reason.v8_value); context_state .pending_promise_rejections - .insert(promise_global, error_global); + .push_back((promise_global, error_global)); } #[op(v8)] @@ -909,7 +909,7 @@ fn op_remove_pending_promise_rejection<'a>( let promise_global = v8::Global::new(scope, promise_value); context_state .pending_promise_rejections - .remove(&promise_global); + .retain(|(key, _)| key != &promise_global); } #[op(v8)] @@ -924,7 +924,8 @@ fn op_has_pending_promise_rejection<'a>( let promise_global = v8::Global::new(scope, promise_value); context_state .pending_promise_rejections - .contains_key(&promise_global) + .iter() + .any(|(key, _)| key == &promise_global) } #[op(v8)] |