From 635fb963a2ce86fe18deecbecd8d901f03381a18 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 26 Apr 2016 12:08:21 -0400 Subject: [PATCH 1/3] Revert "handle_wrap: IsRefed -> Unrefed, no isAlive check" This reverts commit 9bb5a5e2a127010807f5b8a8bf4cf34109271c55. Refs: https://github.com/nodejs/node/pull/6382 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/5834 --- src/handle_wrap.cc | 6 +- src/handle_wrap.h | 2 +- src/pipe_wrap.cc | 2 +- src/process_wrap.cc | 2 +- src/signal_wrap.cc | 2 +- src/tcp_wrap.cc | 2 +- src/timer_wrap.cc | 2 +- src/tty_wrap.cc | 2 +- src/udp_wrap.cc | 2 +- test/parallel/test-handle-wrap-isrefed-tty.js | 10 +-- test/parallel/test-handle-wrap-isrefed.js | 74 +++++++++---------- 11 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 8421d694a991bb..7a7ce8ae262e34 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -37,11 +37,11 @@ void HandleWrap::Unref(const FunctionCallbackInfo& args) { } -void HandleWrap::Unrefed(const FunctionCallbackInfo& args) { +void HandleWrap::IsRefed(const FunctionCallbackInfo& args) { HandleWrap* wrap = Unwrap(args.Holder()); - bool unrefed = wrap->flags_ & kUnref == 1; - args.GetReturnValue().Set(unrefed); + bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0; + args.GetReturnValue().Set(refed); } diff --git a/src/handle_wrap.h b/src/handle_wrap.h index d945143d31a952..cb3ba3f5d52e15 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -35,7 +35,7 @@ class HandleWrap : public AsyncWrap { static void Close(const v8::FunctionCallbackInfo& args); static void Ref(const v8::FunctionCallbackInfo& args); static void Unref(const v8::FunctionCallbackInfo& args); - static void Unrefed(const v8::FunctionCallbackInfo& args); + static void IsRefed(const v8::FunctionCallbackInfo& 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 43df5cb7158b41..25080041c276d8 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -80,7 +80,7 @@ void PipeWrap::Initialize(Local target, env->SetProtoMethod(t, "close", HandleWrap::Close); env->SetProtoMethod(t, "unref", HandleWrap::Unref); env->SetProtoMethod(t, "ref", HandleWrap::Ref); - env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); StreamWrap::AddMethods(env, t); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index b804d9f35e47f1..0b7ad41b61a5ae 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -40,7 +40,7 @@ class ProcessWrap : public HandleWrap { env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); - env->SetProtoMethod(constructor, "unrefed", HandleWrap::Unrefed); + 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 a008b083f0ab53..ca5201d81a4b14 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -32,7 +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, "unrefed", HandleWrap::Unrefed); + 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 d1cc99e756e124..4e8617af2d0c18 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -87,7 +87,7 @@ void TCPWrap::Initialize(Local target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed); + 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 b2c41ebf73a51e..4a1cd3716a9030 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -39,7 +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, "unrefed", HandleWrap::Unrefed); + 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 e7acedd27a1745..5a1d333c3d2bf1 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -36,7 +36,7 @@ void TTYWrap::Initialize(Local target, env->SetProtoMethod(t, "close", HandleWrap::Close); env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed); + 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 b5f3a3cf540f05..ac087f395aced7 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -108,7 +108,7 @@ void UDPWrap::Initialize(Local target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "unref", HandleWrap::Unref); - env->SetProtoMethod(t, "unrefed", HandleWrap::Unrefed); + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction()); env->set_udp_constructor_function(t->GetFunction()); diff --git a/test/parallel/test-handle-wrap-isrefed-tty.js b/test/parallel/test-handle-wrap-isrefed-tty.js index 4c31d63b52c568..9656fe06eee72c 100644 --- a/test/parallel/test-handle-wrap-isrefed-tty.js +++ b/test/parallel/test-handle-wrap-isrefed-tty.js @@ -9,18 +9,16 @@ function makeAssert(message) { strictEqual(actual, expected, message); }; } -const assert = makeAssert('unrefed() not working on tty_wrap'); +const assert = makeAssert('isRefed() not working on tty_wrap'); if (process.argv[2] === 'child') { // Test tty_wrap in piped child to guarentee stdin being a TTY. const ReadStream = require('tty').ReadStream; const tty = new ReadStream(0); - assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('unrefed'), true); - assert(tty._handle.unrefed(), false); + assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true); + assert(tty._handle.isRefed(), true); tty.unref(); - assert(tty._handle.unrefed(), true); - tty._handle.close(); - assert(tty._handle.unrefed(), true); + assert(tty._handle.isRefed(), false); return; } diff --git a/test/parallel/test-handle-wrap-isrefed.js b/test/parallel/test-handle-wrap-isrefed.js index c88534117c3c9b..cd828aa1c4f7d5 100644 --- a/test/parallel/test-handle-wrap-isrefed.js +++ b/test/parallel/test-handle-wrap-isrefed.js @@ -12,92 +12,86 @@ function makeAssert(message) { // child_process { - const assert = makeAssert('unrefed() not working on process_wrap'); + const assert = makeAssert('isRefed() not working on process_wrap'); const spawn = require('child_process').spawn; const cmd = common.isWindows ? 'rundll32' : 'ls'; const cp = spawn(cmd); - assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('unrefed'), true); - assert(cp._handle.unrefed(), false); + assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('isRefed'), true); + assert(cp._handle.isRefed(), true); cp.unref(); - assert(cp._handle.unrefed(), true); + assert(cp._handle.isRefed(), false); cp.ref(); - assert(cp._handle.unrefed(), false); - cp._handle.close(); - assert(cp._handle.unrefed(), false); + assert(cp._handle.isRefed(), true); + cp.unref(); } // dgram { - const assert = makeAssert('unrefed() not working on udp_wrap'); + const assert = makeAssert('isRefed() not working on udp_wrap'); const dgram = require('dgram'); const sock4 = dgram.createSocket('udp4'); - assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('unrefed'), true); - assert(sock4._handle.unrefed(), false); + assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('isRefed'), true); + assert(sock4._handle.isRefed(), true); sock4.unref(); - assert(sock4._handle.unrefed(), true); + assert(sock4._handle.isRefed(), false); sock4.ref(); - assert(sock4._handle.unrefed(), false); - sock4._handle.close(); - assert(sock4._handle.unrefed(), false); + assert(sock4._handle.isRefed(), true); + sock4.unref(); const sock6 = dgram.createSocket('udp6'); - assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('unrefed'), true); - assert(sock6._handle.unrefed(), false); + assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('isRefed'), true); + assert(sock6._handle.isRefed(), true); sock6.unref(); - assert(sock6._handle.unrefed(), true); + assert(sock6._handle.isRefed(), false); sock6.ref(); - assert(sock6._handle.unrefed(), false); - sock6._handle.close(); - assert(sock6._handle.unrefed(), false); + assert(sock6._handle.isRefed(), true); + sock6.unref(); } // pipe { - const assert = makeAssert('unrefed() not working on pipe_wrap'); + const assert = makeAssert('isRefed() not working on pipe_wrap'); const Pipe = process.binding('pipe_wrap').Pipe; const handle = new Pipe(); - assert(Object.getPrototypeOf(handle).hasOwnProperty('unrefed'), true); - assert(handle.unrefed(), false); + assert(Object.getPrototypeOf(handle).hasOwnProperty('isRefed'), true); + assert(handle.isRefed(), true); handle.unref(); - assert(handle.unrefed(), true); + assert(handle.isRefed(), false); handle.ref(); - assert(handle.unrefed(), false); - handle.close(); - assert(handle.unrefed(), false); + assert(handle.isRefed(), true); + handle.unref(); } // tcp { - const assert = makeAssert('unrefed() not working on tcp_wrap'); + const assert = makeAssert('isRefed() not working on tcp_wrap'); const net = require('net'); const server = net.createServer(() => {}).listen(common.PORT); - assert(Object.getPrototypeOf(server._handle).hasOwnProperty('unrefed'), true); - assert(server._handle.unrefed(), false); + assert(Object.getPrototypeOf(server._handle).hasOwnProperty('isRefed'), true); + assert(server._handle.isRefed(), true); assert(server._unref, false); server.unref(); - assert(server._handle.unrefed(), true); + assert(server._handle.isRefed(), false); assert(server._unref, true); server.ref(); - assert(server._handle.unrefed(), false); + assert(server._handle.isRefed(), true); assert(server._unref, false); - server._handle.close(); - assert(server._handle.unrefed(), false); + server.unref(); } // timers { - const assert = makeAssert('unrefed() not working on timer_wrap'); + const assert = makeAssert('isRefed() not working on timer_wrap'); const timer = setTimeout(() => {}, 500); timer.unref(); - assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('unrefed'), true); - assert(timer._handle.unrefed(), true); + assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('isRefed'), true); + assert(timer._handle.isRefed(), false); timer.ref(); - assert(timer._handle.unrefed(), false); - timer.close(); - assert(timer._handle.unrefed(), false); + assert(timer._handle.isRefed(), true); + timer.unref(); } From 6b025df39b3b2d35130b9005bcc5f35de69527e9 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 26 Apr 2016 12:40:15 -0400 Subject: [PATCH 2/3] Revert "src: fix -Wunused-variable compiler warning" This reverts commit f938ef7492f40a81ca2bcae68fd42b8e15235fab. Refs: https://github.com/nodejs/node/pull/6382 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/5834 --- src/handle_wrap.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 7a7ce8ae262e34..60a58d9529bca9 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -38,6 +38,7 @@ void HandleWrap::Unref(const FunctionCallbackInfo& args) { void HandleWrap::IsRefed(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); HandleWrap* wrap = Unwrap(args.Holder()); bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0; From 80a22296af01632ba5f007272c10e413a8fe6b27 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 26 Apr 2016 12:40:35 -0400 Subject: [PATCH 3/3] Revert "handle_wrap: expose an `isRefed()` check to JS" This reverts commit 7d8882ba9a8cfc8f0e2126deb3f3df7456de0ffa. Refs: https://github.com/nodejs/node/pull/6382 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/5834 --- src/handle_wrap.cc | 9 -- src/handle_wrap.h | 1 - src/pipe_wrap.cc | 1 - src/process_wrap.cc | 1 - src/signal_wrap.cc | 1 - src/tcp_wrap.cc | 1 - src/timer_wrap.cc | 1 - src/tty_wrap.cc | 1 - src/udp_wrap.cc | 1 - test/parallel/test-handle-wrap-isrefed-tty.js | 31 ------ test/parallel/test-handle-wrap-isrefed.js | 97 ------------------- 11 files changed, 145 deletions(-) delete mode 100644 test/parallel/test-handle-wrap-isrefed-tty.js delete mode 100644 test/parallel/test-handle-wrap-isrefed.js diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 60a58d9529bca9..43c5490eefa888 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -37,15 +37,6 @@ void HandleWrap::Unref(const FunctionCallbackInfo& args) { } -void HandleWrap::IsRefed(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - HandleWrap* wrap = Unwrap(args.Holder()); - - bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0; - args.GetReturnValue().Set(refed); -} - - void HandleWrap::Close(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); diff --git a/src/handle_wrap.h b/src/handle_wrap.h index cb3ba3f5d52e15..da712b33befbcc 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -35,7 +35,6 @@ class HandleWrap : public AsyncWrap { static void Close(const v8::FunctionCallbackInfo& args); static void Ref(const v8::FunctionCallbackInfo& args); static void Unref(const v8::FunctionCallbackInfo& args); - static void IsRefed(const v8::FunctionCallbackInfo& 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 25080041c276d8..1c60944fe64079 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -80,7 +80,6 @@ void PipeWrap::Initialize(Local 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 0b7ad41b61a5ae..420c71d7ea4052 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -40,7 +40,6 @@ 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 ca5201d81a4b14..5f6a6a52bcd786 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -32,7 +32,6 @@ 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 4e8617af2d0c18..c36e814ec6e37f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -87,7 +87,6 @@ void TCPWrap::Initialize(Local 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 4a1cd3716a9030..79fa86953d47e2 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -39,7 +39,6 @@ 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 5a1d333c3d2bf1..63e8454bacdec3 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -36,7 +36,6 @@ void TTYWrap::Initialize(Local 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 ac087f395aced7..dc2804812fdf19 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -108,7 +108,6 @@ void UDPWrap::Initialize(Local 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()); diff --git a/test/parallel/test-handle-wrap-isrefed-tty.js b/test/parallel/test-handle-wrap-isrefed-tty.js deleted file mode 100644 index 9656fe06eee72c..00000000000000 --- a/test/parallel/test-handle-wrap-isrefed-tty.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -const common = require('../common'); -const strictEqual = require('assert').strictEqual; -const spawn = require('child_process').spawn; - -function makeAssert(message) { - return function(actual, expected) { - strictEqual(actual, expected, message); - }; -} -const assert = makeAssert('isRefed() not working on tty_wrap'); - -if (process.argv[2] === 'child') { - // Test tty_wrap in piped child to guarentee stdin being a TTY. - const ReadStream = require('tty').ReadStream; - const tty = new ReadStream(0); - assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true); - assert(tty._handle.isRefed(), true); - tty.unref(); - assert(tty._handle.isRefed(), false); - return; -} - -// Use spawn so that we can be sure that stdin has a _handle property. -// Refs: https://github.com/nodejs/node/pull/5916 -const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); -proc.stderr.pipe(process.stderr); -proc.on('exit', common.mustCall(function(exitCode) { - process.exitCode = exitCode; -})); diff --git a/test/parallel/test-handle-wrap-isrefed.js b/test/parallel/test-handle-wrap-isrefed.js deleted file mode 100644 index cd828aa1c4f7d5..00000000000000 --- a/test/parallel/test-handle-wrap-isrefed.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -const common = require('../common'); -const strictEqual = require('assert').strictEqual; - -function makeAssert(message) { - return function(actual, expected) { - strictEqual(actual, expected, message); - }; -} - - -// child_process -{ - const assert = makeAssert('isRefed() not working on process_wrap'); - const spawn = require('child_process').spawn; - const cmd = common.isWindows ? 'rundll32' : 'ls'; - const cp = spawn(cmd); - assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('isRefed'), true); - assert(cp._handle.isRefed(), true); - cp.unref(); - assert(cp._handle.isRefed(), false); - cp.ref(); - assert(cp._handle.isRefed(), true); - cp.unref(); -} - - -// dgram -{ - const assert = makeAssert('isRefed() not working on udp_wrap'); - const dgram = require('dgram'); - - const sock4 = dgram.createSocket('udp4'); - assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('isRefed'), true); - assert(sock4._handle.isRefed(), true); - sock4.unref(); - assert(sock4._handle.isRefed(), false); - sock4.ref(); - assert(sock4._handle.isRefed(), true); - sock4.unref(); - - const sock6 = dgram.createSocket('udp6'); - assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('isRefed'), true); - assert(sock6._handle.isRefed(), true); - sock6.unref(); - assert(sock6._handle.isRefed(), false); - sock6.ref(); - assert(sock6._handle.isRefed(), true); - sock6.unref(); -} - - -// pipe -{ - const assert = makeAssert('isRefed() not working on pipe_wrap'); - const Pipe = process.binding('pipe_wrap').Pipe; - const handle = new Pipe(); - assert(Object.getPrototypeOf(handle).hasOwnProperty('isRefed'), true); - assert(handle.isRefed(), true); - handle.unref(); - assert(handle.isRefed(), false); - handle.ref(); - assert(handle.isRefed(), true); - handle.unref(); -} - - -// tcp -{ - const assert = makeAssert('isRefed() not working on tcp_wrap'); - const net = require('net'); - const server = net.createServer(() => {}).listen(common.PORT); - assert(Object.getPrototypeOf(server._handle).hasOwnProperty('isRefed'), true); - assert(server._handle.isRefed(), true); - assert(server._unref, false); - server.unref(); - assert(server._handle.isRefed(), false); - assert(server._unref, true); - server.ref(); - assert(server._handle.isRefed(), true); - assert(server._unref, false); - server.unref(); -} - - -// timers -{ - const assert = makeAssert('isRefed() not working on timer_wrap'); - const timer = setTimeout(() => {}, 500); - timer.unref(); - assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('isRefed'), true); - assert(timer._handle.isRefed(), false); - timer.ref(); - assert(timer._handle.isRefed(), true); - timer.unref(); -}