Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGerhard Stöbich <deb2001-github@yahoo.de>2022-03-21 23:35:05 +0300
committerGitHub <noreply@github.com>2022-03-21 23:35:05 +0300
commitda399a6c8e6ed60313ba0d5dae24d55a1a7c2c37 (patch)
treee2dc164943b0fa76ad5d47ea92ba91c215e36240 /src
parent87089bf8c63db4696090b52bd8b2d9794ffe83c2 (diff)
async_hooks: remove destroyed symbol on Promises
Promises are never destroyed manually therefore it's not needed to attach an object to track if destroy hook was called already. PR-URL: https://github.com/nodejs/node/pull/42402 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/async_wrap.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc
index 77922bd04ad..38f2eb421f4 100644
--- a/src/async_wrap.cc
+++ b/src/async_wrap.cc
@@ -214,12 +214,13 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
p->env->RemoveCleanupHook(DestroyParamCleanupHook, p.get());
- if (!prop_bag->Get(p->env->context(), p->env->destroyed_string())
+ if (!prop_bag.IsEmpty() &&
+ !prop_bag->Get(p->env->context(), p->env->destroyed_string())
.ToLocal(&val)) {
return;
}
- if (val->IsFalse()) {
+ if (val.IsEmpty() || val->IsFalse()) {
AsyncWrap::EmitDestroy(p->env, p->asyncId);
}
// unique_ptr goes out of scope here and pointer is deleted.
@@ -229,14 +230,16 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsObject());
CHECK(args[1]->IsNumber());
- CHECK(args[2]->IsObject());
+ CHECK(args.Length() == 2 || args[2]->IsObject());
Isolate* isolate = args.GetIsolate();
DestroyParam* p = new DestroyParam();
p->asyncId = args[1].As<Number>()->Value();
p->env = Environment::GetCurrent(args);
p->target.Reset(isolate, args[0].As<Object>());
- p->propBag.Reset(isolate, args[2].As<Object>());
+ if (args.Length() > 2) {
+ p->propBag.Reset(isolate, args[2].As<Object>());
+ }
p->target.SetWeak(p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter);
p->env->AddCleanupHook(DestroyParamCleanupHook, p);
}