Skip to content

Commit 635fb96

Browse files
committed
Revert "handle_wrap: IsRefed -> Unrefed, no isAlive check"
This reverts commit 9bb5a5e. Refs: nodejs#6382 Refs: nodejs#6204 Refs: nodejs#5834
1 parent 31de5cc commit 635fb96

11 files changed

+49
-57
lines changed

src/handle_wrap.cc

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

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

4747

src/handle_wrap.h

+1-1
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 Unrefed(const v8::FunctionCallbackInfo<v8::Value>& args);
38+
static void IsRefed(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

+1-1
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, "unrefed", HandleWrap::Unrefed);
83+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
8484

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

src/process_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
43+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
4444

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

src/signal_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
35+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
3636
env->SetProtoMethod(constructor, "start", Start);
3737
env->SetProtoMethod(constructor, "stop", Stop);
3838

src/tcp_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
90+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
9191

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

src/timer_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
42+
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
4343

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

src/tty_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
39+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
4040

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

src/udp_wrap.cc

+1-1
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, "unrefed", HandleWrap::Unrefed);
111+
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
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

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@ function makeAssert(message) {
99
strictEqual(actual, expected, message);
1010
};
1111
}
12-
const assert = makeAssert('unrefed() not working on tty_wrap');
12+
const assert = makeAssert('isRefed() 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('unrefed'), true);
19-
assert(tty._handle.unrefed(), false);
18+
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true);
19+
assert(tty._handle.isRefed(), true);
2020
tty.unref();
21-
assert(tty._handle.unrefed(), true);
22-
tty._handle.close();
23-
assert(tty._handle.unrefed(), true);
21+
assert(tty._handle.isRefed(), false);
2422
return;
2523
}
2624

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

+34-40
Original file line numberDiff line numberDiff line change
@@ -12,92 +12,86 @@ function makeAssert(message) {
1212

1313
// child_process
1414
{
15-
const assert = makeAssert('unrefed() not working on process_wrap');
15+
const assert = makeAssert('isRefed() not working on process_wrap');
1616
const spawn = require('child_process').spawn;
1717
const cmd = common.isWindows ? 'rundll32' : 'ls';
1818
const cp = spawn(cmd);
19-
assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('unrefed'), true);
20-
assert(cp._handle.unrefed(), false);
19+
assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('isRefed'), true);
20+
assert(cp._handle.isRefed(), true);
2121
cp.unref();
22-
assert(cp._handle.unrefed(), true);
22+
assert(cp._handle.isRefed(), false);
2323
cp.ref();
24-
assert(cp._handle.unrefed(), false);
25-
cp._handle.close();
26-
assert(cp._handle.unrefed(), false);
24+
assert(cp._handle.isRefed(), true);
25+
cp.unref();
2726
}
2827

2928

3029
// dgram
3130
{
32-
const assert = makeAssert('unrefed() not working on udp_wrap');
31+
const assert = makeAssert('isRefed() not working on udp_wrap');
3332
const dgram = require('dgram');
3433

3534
const sock4 = dgram.createSocket('udp4');
36-
assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('unrefed'), true);
37-
assert(sock4._handle.unrefed(), false);
35+
assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('isRefed'), true);
36+
assert(sock4._handle.isRefed(), true);
3837
sock4.unref();
39-
assert(sock4._handle.unrefed(), true);
38+
assert(sock4._handle.isRefed(), false);
4039
sock4.ref();
41-
assert(sock4._handle.unrefed(), false);
42-
sock4._handle.close();
43-
assert(sock4._handle.unrefed(), false);
40+
assert(sock4._handle.isRefed(), true);
41+
sock4.unref();
4442

4543
const sock6 = dgram.createSocket('udp6');
46-
assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('unrefed'), true);
47-
assert(sock6._handle.unrefed(), false);
44+
assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('isRefed'), true);
45+
assert(sock6._handle.isRefed(), true);
4846
sock6.unref();
49-
assert(sock6._handle.unrefed(), true);
47+
assert(sock6._handle.isRefed(), false);
5048
sock6.ref();
51-
assert(sock6._handle.unrefed(), false);
52-
sock6._handle.close();
53-
assert(sock6._handle.unrefed(), false);
49+
assert(sock6._handle.isRefed(), true);
50+
sock6.unref();
5451
}
5552

5653

5754
// pipe
5855
{
59-
const assert = makeAssert('unrefed() not working on pipe_wrap');
56+
const assert = makeAssert('isRefed() not working on pipe_wrap');
6057
const Pipe = process.binding('pipe_wrap').Pipe;
6158
const handle = new Pipe();
62-
assert(Object.getPrototypeOf(handle).hasOwnProperty('unrefed'), true);
63-
assert(handle.unrefed(), false);
59+
assert(Object.getPrototypeOf(handle).hasOwnProperty('isRefed'), true);
60+
assert(handle.isRefed(), true);
6461
handle.unref();
65-
assert(handle.unrefed(), true);
62+
assert(handle.isRefed(), false);
6663
handle.ref();
67-
assert(handle.unrefed(), false);
68-
handle.close();
69-
assert(handle.unrefed(), false);
64+
assert(handle.isRefed(), true);
65+
handle.unref();
7066
}
7167

7268

7369
// tcp
7470
{
75-
const assert = makeAssert('unrefed() not working on tcp_wrap');
71+
const assert = makeAssert('isRefed() not working on tcp_wrap');
7672
const net = require('net');
7773
const server = net.createServer(() => {}).listen(common.PORT);
78-
assert(Object.getPrototypeOf(server._handle).hasOwnProperty('unrefed'), true);
79-
assert(server._handle.unrefed(), false);
74+
assert(Object.getPrototypeOf(server._handle).hasOwnProperty('isRefed'), true);
75+
assert(server._handle.isRefed(), true);
8076
assert(server._unref, false);
8177
server.unref();
82-
assert(server._handle.unrefed(), true);
78+
assert(server._handle.isRefed(), false);
8379
assert(server._unref, true);
8480
server.ref();
85-
assert(server._handle.unrefed(), false);
81+
assert(server._handle.isRefed(), true);
8682
assert(server._unref, false);
87-
server._handle.close();
88-
assert(server._handle.unrefed(), false);
83+
server.unref();
8984
}
9085

9186

9287
// timers
9388
{
94-
const assert = makeAssert('unrefed() not working on timer_wrap');
89+
const assert = makeAssert('isRefed() not working on timer_wrap');
9590
const timer = setTimeout(() => {}, 500);
9691
timer.unref();
97-
assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('unrefed'), true);
98-
assert(timer._handle.unrefed(), true);
92+
assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('isRefed'), true);
93+
assert(timer._handle.isRefed(), false);
9994
timer.ref();
100-
assert(timer._handle.unrefed(), false);
101-
timer.close();
102-
assert(timer._handle.unrefed(), false);
95+
assert(timer._handle.isRefed(), true);
96+
timer.unref();
10397
}

0 commit comments

Comments
 (0)