@@ -214,12 +214,13 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
214
214
215
215
p->env ->RemoveCleanupHook (DestroyParamCleanupHook, p.get ());
216
216
217
- if (!prop_bag->Get (p->env ->context (), p->env ->destroyed_string ())
217
+ if (!prop_bag.IsEmpty () &&
218
+ !prop_bag->Get (p->env ->context (), p->env ->destroyed_string ())
218
219
.ToLocal (&val)) {
219
220
return ;
220
221
}
221
222
222
- if (val->IsFalse ()) {
223
+ if (val. IsEmpty () || val ->IsFalse ()) {
223
224
AsyncWrap::EmitDestroy (p->env , p->asyncId );
224
225
}
225
226
// unique_ptr goes out of scope here and pointer is deleted.
@@ -229,14 +230,16 @@ void AsyncWrap::WeakCallback(const WeakCallbackInfo<DestroyParam>& info) {
229
230
static void RegisterDestroyHook (const FunctionCallbackInfo<Value>& args) {
230
231
CHECK (args[0 ]->IsObject ());
231
232
CHECK (args[1 ]->IsNumber ());
232
- CHECK (args[2 ]->IsObject ());
233
+ CHECK (args. Length () == 2 || args [2 ]->IsObject ());
233
234
234
235
Isolate* isolate = args.GetIsolate ();
235
236
DestroyParam* p = new DestroyParam ();
236
237
p->asyncId = args[1 ].As <Number>()->Value ();
237
238
p->env = Environment::GetCurrent (args);
238
239
p->target .Reset (isolate, args[0 ].As <Object>());
239
- p->propBag .Reset (isolate, args[2 ].As <Object>());
240
+ if (args.Length () > 2 ) {
241
+ p->propBag .Reset (isolate, args[2 ].As <Object>());
242
+ }
240
243
p->target .SetWeak (p, AsyncWrap::WeakCallback, WeakCallbackType::kParameter );
241
244
p->env ->AddCleanupHook (DestroyParamCleanupHook, p);
242
245
}
0 commit comments