From 75e28c5e735af71404578d189ec2533c4b356cc5 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Tue, 28 Feb 2017 18:20:39 -0800 Subject: [PATCH] napi: Fix weakref callback for wrap (#118) --- src/node_jsvmapi.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/node_jsvmapi.cc b/src/node_jsvmapi.cc index 2f9dba07e8..11e09b674c 100644 --- a/src/node_jsvmapi.cc +++ b/src/node_jsvmapi.cc @@ -147,7 +147,12 @@ namespace v8impl { _finalizeCallback(finalizeCallback), _finalizeData(finalizeData) { if (initialRefcount == 0) { - _persistent.SetWeak(this, FinalizeCallback, v8::WeakCallbackType::kParameter); + if (_finalizeCallback != nullptr || _deleteSelf) { + _persistent.SetWeak(this, FinalizeCallback, v8::WeakCallbackType::kParameter); + } + else { + _persistent.SetWeak(); + } _persistent.MarkIndependent(); } } @@ -172,7 +177,12 @@ namespace v8impl { int Release() { if (--_refcount == 0) { - _persistent.SetWeak(this, FinalizeCallback, v8::WeakCallbackType::kParameter); + if (_finalizeCallback != nullptr || _deleteSelf) { + _persistent.SetWeak(this, FinalizeCallback, v8::WeakCallbackType::kParameter); + } + else { + _persistent.SetWeak(); + } _persistent.MarkIndependent(); } @@ -721,7 +731,7 @@ napi_status napi_define_class( } napi_status status = napi_define_properties( - e, *result, staticDescriptors.size(), staticDescriptors.data()); + e, *result, static_cast(staticDescriptors.size()), staticDescriptors.data()); if (status != napi_ok) return status; }