summaryrefslogtreecommitdiff
path: root/src/env-inl.h
diff options
context:
space:
mode:
authorBryan English <bryan@bryanenglish.com>2021-06-19 13:47:43 -0400
committerDanielle Adams <adamzdanielle@gmail.com>2021-06-21 21:48:22 -0400
commitd2b972ee5280a3b71912b1b5f8276be116f0bbf1 (patch)
tree0d9db34a887433cbd2c3bb71478a58e7a9b7b03d /src/env-inl.h
parent78d2e0ed8e763182e090be17d6fa280678411a54 (diff)
downloadnode-new-d2b972ee5280a3b71912b1b5f8276be116f0bbf1.tar.gz
async_hooks: check for empty contexts before removing
This way we don't end up attempting to SetPromiseHooks on contexts that have already been collected. Fixes: https://github.com/nodejs/node/issues/39019 PR-URL: https://github.com/nodejs/node/pull/39095 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Danielle Adams <adamzdanielle@gmail.com>
Diffstat (limited to 'src/env-inl.h')
-rw-r--r--src/env-inl.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index 6fb8f137c3..b3b1ea9082 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -104,6 +104,11 @@ inline void AsyncHooks::SetJSPromiseHooks(v8::Local<v8::Function> init,
js_promise_hooks_[2].Reset(env()->isolate(), after);
js_promise_hooks_[3].Reset(env()->isolate(), resolve);
for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
+ if (it->IsEmpty()) {
+ it = contexts_.erase(it);
+ it--;
+ continue;
+ }
PersistentToLocal::Weak(env()->isolate(), *it)
->SetPromiseHooks(init, before, after, resolve);
}
@@ -256,8 +261,13 @@ inline void AsyncHooks::RemoveContext(v8::Local<v8::Context> ctx) {
v8::Isolate* isolate = env()->isolate();
v8::HandleScope handle_scope(isolate);
for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
+ if (it->IsEmpty()) {
+ it = contexts_.erase(it);
+ it--;
+ continue;
+ }
v8::Local<v8::Context> saved_context =
- PersistentToLocal::Weak(env()->isolate(), *it);
+ PersistentToLocal::Weak(isolate, *it);
if (saved_context == ctx) {
it->Reset();
contexts_.erase(it);