Skip to content

Commit 9bb5a5e

Browse files
committed
handle_wrap: IsRefed -> Unrefed, no isAlive check
This fixes my perceived usability issues with 7d8882b. Which, at the time of writing, has not landed in any release except v6 RCs. This should not be considered a breaking change due to that. It is useful if you have a handle, even if it has been closed, to be able to inspect whether that handle was unrefed or not. As such, this renames the method accordingly. If people need to check a handle's aliveness, that is a separate API we should consider exposing. Refs: nodejs#5834 PR-URL: nodejs#6204 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent eb4201f commit 9bb5a5e

11 files changed

+57
-49
lines changed

src/handle_wrap.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
3737
}
3838

3939

40-
void HandleWrap::IsRefed(const FunctionCallbackInfo<Value>& args) {
40+
void HandleWrap::Unrefed(const FunctionCallbackInfo<Value>& args) {
4141
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
4242

43-
bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0;
44-
args.GetReturnValue().Set(refed);
43+
bool unrefed = wrap->flags_ & kUnref == 1;
44+
args.GetReturnValue().Set(unrefed);
4545
}
4646

4747

src/handle_wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +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);
38+
static void Unrefed(const v8::FunctionCallbackInfo<v8::Value>& args);
3939

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

src/pipe_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +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);
83+
env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed);
8484

8585
StreamWrap::AddMethods(env, t);
8686

src/process_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +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);
43+
env->SetProtoMethod(constructor, "unrefed", HandleWrap::Unrefed);
4444

4545
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"),
4646
constructor->GetFunction());

src/signal_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +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);
35+
env->SetProtoMethod(constructor, "unrefed", HandleWrap::Unrefed);
3636
env->SetProtoMethod(constructor, "start", Start);
3737
env->SetProtoMethod(constructor, "stop", Stop);
3838

src/tcp_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +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);
90+
env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed);
9191

9292
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
9393

src/timer_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +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);
42+
env->SetProtoMethod(constructor, "unrefed", HandleWrap::Unrefed);
4343

4444
env->SetProtoMethod(constructor, "start", Start);
4545
env->SetProtoMethod(constructor, "stop", Stop);

src/tty_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +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);
39+
env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed);
4040

4141
StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown);
4242

src/udp_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +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);
111+
env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed);
112112

113113
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction());
114114
env->set_udp_constructor_function(t->GetFunction());

test/parallel/test-handle-wrap-isrefed-tty.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ function makeAssert(message) {
99
strictEqual(actual, expected, message);
1010
};
1111
}
12-
const assert = makeAssert('isRefed() not working on tty_wrap');
12+
const assert = makeAssert('unrefed() not working on tty_wrap');
1313

1414
if (process.argv[2] === 'child') {
1515
// Test tty_wrap in piped child to guarentee stdin being a TTY.
1616
const ReadStream = require('tty').ReadStream;
1717
const tty = new ReadStream(0);
18-
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true);
19-
assert(tty._handle.isRefed(), true);
18+
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('unrefed'), true);
19+
assert(tty._handle.unrefed(), false);
2020
tty.unref();
21-
assert(tty._handle.isRefed(), false);
21+
assert(tty._handle.unrefed(), true);
22+
tty._handle.close();
23+
assert(tty._handle.unrefed(), true);
2224
return;
2325
}
2426

0 commit comments

Comments
 (0)