@@ -294,6 +294,13 @@ void WeakReference::Get(const FunctionCallbackInfo<Value>& args) {
294294 args.GetReturnValue ().Set (weak_ref->target_ .Get (isolate));
295295}
296296
297+ void WeakReference::GetRef (const FunctionCallbackInfo<Value>& args) {
298+ WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder ());
299+ Isolate* isolate = args.GetIsolate ();
300+ args.GetReturnValue ().Set (
301+ v8::Number::New (isolate, weak_ref->reference_count_ ));
302+ }
303+
297304void WeakReference::IncRef (const FunctionCallbackInfo<Value>& args) {
298305 WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder ());
299306 weak_ref->reference_count_ ++;
@@ -391,6 +398,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
391398 registry->Register (ArrayBufferViewHasBuffer);
392399 registry->Register (WeakReference::New);
393400 registry->Register (WeakReference::Get);
401+ registry->Register (WeakReference::GetRef);
394402 registry->Register (WeakReference::IncRef);
395403 registry->Register (WeakReference::DecRef);
396404 registry->Register (GuessHandleType);
@@ -464,6 +472,7 @@ void Initialize(Local<Object> target,
464472 WeakReference::kInternalFieldCount );
465473 weak_ref->Inherit (BaseObject::GetConstructorTemplate (env));
466474 SetProtoMethod (isolate, weak_ref, " get" , WeakReference::Get);
475+ SetProtoMethod (isolate, weak_ref, " getRef" , WeakReference::GetRef);
467476 SetProtoMethod (isolate, weak_ref, " incRef" , WeakReference::IncRef);
468477 SetProtoMethod (isolate, weak_ref, " decRef" , WeakReference::DecRef);
469478 SetConstructorFunction (context, target, " WeakReference" , weak_ref);
0 commit comments