diff --git a/src/base_object-inl.h b/src/base_object-inl.h index d067a807cb8e14..8c8fa1699c3069 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -95,13 +95,12 @@ void BaseObject::MakeWeak() { persistent_handle_.SetWeak( this, [](const v8::WeakCallbackInfo& data) { - BaseObject* obj = data.GetParameter(); + std::unique_ptr obj(data.GetParameter()); // Clear the persistent handle so that ~BaseObject() doesn't attempt // to mess with internal fields, since the JS object may have // transitioned into an invalid state. // Refs: https://github.com/nodejs/node/issues/18897 obj->persistent_handle_.Reset(); - delete obj; }, v8::WeakCallbackType::kParameter); }