handle_wrap: expose an `isRefed()` check to JS · nodejs/node@d313204 · GitHub
Skip to content

Commit d313204

Browse files
Fishrock123evanlucas
authored andcommitted
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: #5828 Refs: #5827 PR-URL: #5834 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 5c7da21 commit d313204

11 files changed

Lines changed: 146 additions & 0 deletions

src/handle_wrap.cc

Lines changed: 10 additions & 0 deletions

src/handle_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class HandleWrap : public AsyncWrap {
3535
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
3636
static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
3737
static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
38+
static void IsRefed(const v8::FunctionCallbackInfo<v8::Value>& args);
3839

3940
static inline bool IsAlive(const HandleWrap* wrap) {
4041
return wrap != nullptr && wrap->GetHandle() != nullptr;

src/pipe_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void PipeWrap::Initialize(Local<Object> target,
8080
env->SetProtoMethod(t, "close", HandleWrap::Close);
8181
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
8282
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
83+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
8384

8485
StreamWrap::AddMethods(env, t);
8586

src/process_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ProcessWrap : public HandleWrap {
4040

4141
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
4242
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
43+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
4344

4445
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"),
4546
constructor->GetFunction());

src/signal_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SignalWrap : public HandleWrap {
3232
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
3333
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
3434
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
35+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
3536
env->SetProtoMethod(constructor, "start", Start);
3637
env->SetProtoMethod(constructor, "stop", Stop);
3738

src/tcp_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void TCPWrap::Initialize(Local<Object> target,
8787

8888
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
8989
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
90+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
9091

9192
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
9293

src/timer_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TimerWrap : public HandleWrap {
3939
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
4040
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
4141
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
42+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
4243

4344
env->SetProtoMethod(constructor, "start", Start);
4445
env->SetProtoMethod(constructor, "stop", Stop);

src/tty_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void TTYWrap::Initialize(Local<Object> target,
3636

3737
env->SetProtoMethod(t, "close", HandleWrap::Close);
3838
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
39+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
3940

4041
StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown);
4142

src/udp_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void UDPWrap::Initialize(Local<Object> target,
108108

109109
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
110110
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
111+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
111112

112113
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction());
113114
env->set_udp_constructor_function(t->GetFunction());
Lines changed: 31 additions & 0 deletions

0 commit comments

Comments
 (0)