@@ -255,6 +255,13 @@ void WeakReference::Get(const FunctionCallbackInfo<Value>& args) {
255255 args.GetReturnValue ().Set (weak_ref->target_ .Get (isolate));
256256}
257257
258+ void WeakReference::GetRef (const FunctionCallbackInfo<Value>& args) {
259+ WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder ());
260+ Isolate* isolate = args.GetIsolate ();
261+ args.GetReturnValue ().Set (
262+ v8::Number::New (isolate, weak_ref->reference_count_ ));
263+ }
264+
258265void WeakReference::IncRef (const FunctionCallbackInfo<Value>& args) {
259266 WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder ());
260267 weak_ref->reference_count_ ++;
@@ -350,6 +357,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
350357 registry->Register (ArrayBufferViewHasBuffer);
351358 registry->Register (WeakReference::New);
352359 registry->Register (WeakReference::Get);
360+ registry->Register (WeakReference::GetRef);
353361 registry->Register (WeakReference::IncRef);
354362 registry->Register (WeakReference::DecRef);
355363 registry->Register (GuessHandleType);
@@ -438,6 +446,7 @@ void Initialize(Local<Object> target,
438446 WeakReference::kInternalFieldCount );
439447 weak_ref->Inherit (BaseObject::GetConstructorTemplate (env));
440448 SetProtoMethod (isolate, weak_ref, " get" , WeakReference::Get);
449+ SetProtoMethod (isolate, weak_ref, " getRef" , WeakReference::GetRef);
441450 SetProtoMethod (isolate, weak_ref, " incRef" , WeakReference::IncRef);
442451 SetProtoMethod (isolate, weak_ref, " decRef" , WeakReference::DecRef);
443452 SetConstructorFunction (context, target, " WeakReference" , weak_ref);
0 commit comments