summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node_util.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/node_util.cc b/src/node_util.cc
index fa39583b04..9c24985a47 100644
--- a/src/node_util.cc
+++ b/src/node_util.cc
@@ -191,14 +191,16 @@ class WeakReference : public BaseObject {
static void IncRef(const FunctionCallbackInfo<Value>& args) {
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
- if (weak_ref->reference_count_ == 0) weak_ref->target_.ClearWeak();
weak_ref->reference_count_++;
+ if (weak_ref->target_.IsEmpty()) return;
+ if (weak_ref->reference_count_ == 1) weak_ref->target_.ClearWeak();
}
static void DecRef(const FunctionCallbackInfo<Value>& args) {
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
CHECK_GE(weak_ref->reference_count_, 1);
weak_ref->reference_count_--;
+ if (weak_ref->target_.IsEmpty()) return;
if (weak_ref->reference_count_ == 0) weak_ref->target_.SetWeak();
}