diff options
author | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2016-03-21 22:59:31 +0300 |
---|---|---|
committer | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2016-04-07 19:44:19 +0300 |
commit | 7d8882ba9a8cfc8f0e2126deb3f3df7456de0ffa (patch) | |
tree | 44388842ee46106b5887707c6ae75db7155649a6 /src | |
parent | 1879e1ef178197fd3593fdbbe65c23224c0d256d (diff) |
handle_wrap: expose an `isRefed()` check to JS
This allows third-party tools to check whether or not a handle that
can be unreferenced is unreferenced at a particular time.
Notably, this should be helpful for inspection via AsyncWrap.
Also, this is useful even to node's internals, particularly timers.
Refs: https://github.com/nodejs/node/pull/5828
Refs: https://github.com/nodejs/node/pull/5827
PR-URL: https://github.com/nodejs/node/pull/5834
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/handle_wrap.cc | 10 | ||||
-rw-r--r-- | src/handle_wrap.h | 1 | ||||
-rw-r--r-- | src/pipe_wrap.cc | 1 | ||||
-rw-r--r-- | src/process_wrap.cc | 1 | ||||
-rw-r--r-- | src/signal_wrap.cc | 1 | ||||
-rw-r--r-- | src/tcp_wrap.cc | 1 | ||||
-rw-r--r-- | src/timer_wrap.cc | 1 | ||||
-rw-r--r-- | src/tty_wrap.cc | 1 | ||||
-rw-r--r-- | src/udp_wrap.cc | 1 |
9 files changed, 18 insertions, 0 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 43c5490eefa..9af60d50258 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -9,6 +9,7 @@ namespace node { +using v8::Boolean; using v8::Context; using v8::FunctionCallbackInfo; using v8::HandleScope; @@ -37,6 +38,15 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { } +void HandleWrap::IsRefed(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); + + bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0; + args.GetReturnValue().Set(refed); +} + + void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); diff --git a/src/handle_wrap.h b/src/handle_wrap.h index da712b33bef..cb3ba3f5d52 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -35,6 +35,7 @@ class HandleWrap : public AsyncWrap { static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args); static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args); + static void IsRefed(const v8::FunctionCallbackInfo<v8::Value>& args); static inline bool IsAlive(const HandleWrap* wrap) { return wrap != nullptr && wrap->GetHandle() != nullptr; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index db2fd16715c..ec6ef32b08a 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -81,6 +81,7 @@ void PipeWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "close", HandleWrap::Close); env->SetProtoMethod(t, "unref", HandleWrap::Unref); env->SetProtoMethod(t, "ref", HandleWrap::Ref); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); StreamWrap::AddMethods(env, t); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 7e9d2070bb9..dec93ddd0cd 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -40,6 +40,7 @@ class ProcessWrap : public HandleWrap { env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"), constructor->GetFunction()); diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index 5f6a6a52bcd..ca5201d81a4 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -32,6 +32,7 @@ class SignalWrap : public HandleWrap { env->SetProtoMethod(constructor, "close", HandleWrap::Close); env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 50fcb506aea..4bfe9dd0d83 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -88,6 +88,7 @@ void TCPWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "unref", HandleWrap::Unref); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 79fa86953d4..4a1cd3716a9 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -39,6 +39,7 @@ class TimerWrap : public HandleWrap { env->SetProtoMethod(constructor, "close", HandleWrap::Close); env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); env->SetProtoMethod(constructor, "start", Start); env->SetProtoMethod(constructor, "stop", Stop); diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index a78d2311456..567a504276a 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -37,6 +37,7 @@ void TTYWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "close", HandleWrap::Close); env->SetProtoMethod(t, "unref", HandleWrap::Unref); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index dc2804812fd..ac087f395ac 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -108,6 +108,7 @@ void UDPWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "unref", HandleWrap::Unref); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction()); env->set_udp_constructor_function(t->GetFunction()); |