handle_wrap: IsRefed() -> HasRef()
Rename slightly to HasRef() at bnoordhuis’ request. Better reflects what we actually do for this check. Refs: https://github.com/nodejs/node/pull/6395 Refs: https://github.com/nodejs/node/pull/6204 Refs: https://github.com/nodejs/node/pull/6401 Refs: https://github.com/nodejs/node/pull/6382 Refs: https://github.com/nodejs/node/pull/6381 PR-URL: https://github.com/nodejs/node/pull/6546 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
parent
96a9439fd2
commit
fe4837afcc
@ -33,7 +33,7 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HandleWrap::IsRefed(const FunctionCallbackInfo<Value>& args) {
|
void HandleWrap::HasRef(const FunctionCallbackInfo<Value>& args) {
|
||||||
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
|
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
|
||||||
args.GetReturnValue().Set(HasRef(wrap));
|
args.GetReturnValue().Set(HasRef(wrap));
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class HandleWrap : public AsyncWrap {
|
|||||||
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
static void Ref(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 Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
static void IsRefed(const v8::FunctionCallbackInfo<v8::Value>& args);
|
static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||||
|
|
||||||
static inline bool IsAlive(const HandleWrap* wrap) {
|
static inline bool IsAlive(const HandleWrap* wrap) {
|
||||||
return wrap != nullptr && wrap->state_ != kClosed;
|
return wrap != nullptr && wrap->state_ != kClosed;
|
||||||
|
@ -80,7 +80,7 @@ void PipeWrap::Initialize(Local<Object> target,
|
|||||||
env->SetProtoMethod(t, "close", HandleWrap::Close);
|
env->SetProtoMethod(t, "close", HandleWrap::Close);
|
||||||
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
StreamWrap::AddMethods(env, t);
|
StreamWrap::AddMethods(env, t);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class ProcessWrap : public HandleWrap {
|
|||||||
|
|
||||||
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"),
|
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"),
|
||||||
constructor->GetFunction());
|
constructor->GetFunction());
|
||||||
|
@ -32,7 +32,7 @@ class SignalWrap : public HandleWrap {
|
|||||||
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
|
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
|
||||||
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef);
|
||||||
env->SetProtoMethod(constructor, "start", Start);
|
env->SetProtoMethod(constructor, "start", Start);
|
||||||
env->SetProtoMethod(constructor, "stop", Stop);
|
env->SetProtoMethod(constructor, "stop", Stop);
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ void TCPWrap::Initialize(Local<Object> target,
|
|||||||
|
|
||||||
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
|
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class TimerWrap : public HandleWrap {
|
|||||||
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
|
env->SetProtoMethod(constructor, "close", HandleWrap::Close);
|
||||||
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(constructor, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(constructor, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(constructor, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
env->SetProtoMethod(constructor, "start", Start);
|
env->SetProtoMethod(constructor, "start", Start);
|
||||||
env->SetProtoMethod(constructor, "stop", Stop);
|
env->SetProtoMethod(constructor, "stop", Stop);
|
||||||
|
@ -36,7 +36,7 @@ void TTYWrap::Initialize(Local<Object> target,
|
|||||||
|
|
||||||
env->SetProtoMethod(t, "close", HandleWrap::Close);
|
env->SetProtoMethod(t, "close", HandleWrap::Close);
|
||||||
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown);
|
StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown);
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ void UDPWrap::Initialize(Local<Object> target,
|
|||||||
|
|
||||||
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
|
||||||
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
|
||||||
env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed);
|
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);
|
||||||
|
|
||||||
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction());
|
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction());
|
||||||
env->set_udp_constructor_function(t->GetFunction());
|
env->set_udp_constructor_function(t->GetFunction());
|
||||||
|
@ -9,18 +9,18 @@ function makeAssert(message) {
|
|||||||
strictEqual(actual, expected, message);
|
strictEqual(actual, expected, message);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const assert = makeAssert('isRefed() not working on tty_wrap');
|
const assert = makeAssert('hasRef() not working on tty_wrap');
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
// Test tty_wrap in piped child to guarentee stdin being a TTY.
|
// Test tty_wrap in piped child to guarentee stdin being a TTY.
|
||||||
const ReadStream = require('tty').ReadStream;
|
const ReadStream = require('tty').ReadStream;
|
||||||
const tty = new ReadStream(0);
|
const tty = new ReadStream(0);
|
||||||
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(tty._handle.isRefed(), true);
|
assert(tty._handle.hasRef(), true);
|
||||||
tty.unref();
|
tty.unref();
|
||||||
assert(tty._handle.isRefed(), false);
|
assert(tty._handle.hasRef(), false);
|
||||||
tty._handle.close(
|
tty._handle.close(
|
||||||
common.mustCall(() => assert(tty._handle.isRefed(), false)));
|
common.mustCall(() => assert(tty._handle.hasRef(), false)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,90 +12,90 @@ function makeAssert(message) {
|
|||||||
|
|
||||||
// child_process
|
// child_process
|
||||||
{
|
{
|
||||||
const assert = makeAssert('isRefed() not working on process_wrap');
|
const assert = makeAssert('hasRef() not working on process_wrap');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const cmd = common.isWindows ? 'rundll32' : 'ls';
|
const cmd = common.isWindows ? 'rundll32' : 'ls';
|
||||||
const cp = spawn(cmd);
|
const cp = spawn(cmd);
|
||||||
assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(cp._handle.isRefed(), true);
|
assert(cp._handle.hasRef(), true);
|
||||||
cp.unref();
|
cp.unref();
|
||||||
assert(cp._handle.isRefed(), false);
|
assert(cp._handle.hasRef(), false);
|
||||||
cp.ref();
|
cp.ref();
|
||||||
assert(cp._handle.isRefed(), true);
|
assert(cp._handle.hasRef(), true);
|
||||||
cp._handle.close(common.mustCall(() => assert(cp._handle.isRefed(), false)));
|
cp._handle.close(common.mustCall(() => assert(cp._handle.hasRef(), false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// dgram
|
// dgram
|
||||||
{
|
{
|
||||||
const assert = makeAssert('isRefed() not working on udp_wrap');
|
const assert = makeAssert('hasRef() not working on udp_wrap');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
|
|
||||||
const sock4 = dgram.createSocket('udp4');
|
const sock4 = dgram.createSocket('udp4');
|
||||||
assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(sock4._handle.isRefed(), true);
|
assert(sock4._handle.hasRef(), true);
|
||||||
sock4.unref();
|
sock4.unref();
|
||||||
assert(sock4._handle.isRefed(), false);
|
assert(sock4._handle.hasRef(), false);
|
||||||
sock4.ref();
|
sock4.ref();
|
||||||
assert(sock4._handle.isRefed(), true);
|
assert(sock4._handle.hasRef(), true);
|
||||||
sock4._handle.close(
|
sock4._handle.close(
|
||||||
common.mustCall(() => assert(sock4._handle.isRefed(), false)));
|
common.mustCall(() => assert(sock4._handle.hasRef(), false)));
|
||||||
|
|
||||||
const sock6 = dgram.createSocket('udp6');
|
const sock6 = dgram.createSocket('udp6');
|
||||||
assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(sock6._handle.isRefed(), true);
|
assert(sock6._handle.hasRef(), true);
|
||||||
sock6.unref();
|
sock6.unref();
|
||||||
assert(sock6._handle.isRefed(), false);
|
assert(sock6._handle.hasRef(), false);
|
||||||
sock6.ref();
|
sock6.ref();
|
||||||
assert(sock6._handle.isRefed(), true);
|
assert(sock6._handle.hasRef(), true);
|
||||||
sock6._handle.close(
|
sock6._handle.close(
|
||||||
common.mustCall(() => assert(sock6._handle.isRefed(), false)));
|
common.mustCall(() => assert(sock6._handle.hasRef(), false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pipe
|
// pipe
|
||||||
{
|
{
|
||||||
const assert = makeAssert('isRefed() not working on pipe_wrap');
|
const assert = makeAssert('hasRef() not working on pipe_wrap');
|
||||||
const Pipe = process.binding('pipe_wrap').Pipe;
|
const Pipe = process.binding('pipe_wrap').Pipe;
|
||||||
const handle = new Pipe();
|
const handle = new Pipe();
|
||||||
assert(Object.getPrototypeOf(handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(handle.isRefed(), true);
|
assert(handle.hasRef(), true);
|
||||||
handle.unref();
|
handle.unref();
|
||||||
assert(handle.isRefed(), false);
|
assert(handle.hasRef(), false);
|
||||||
handle.ref();
|
handle.ref();
|
||||||
assert(handle.isRefed(), true);
|
assert(handle.hasRef(), true);
|
||||||
handle.close(common.mustCall(() => assert(handle.isRefed(), false)));
|
handle.close(common.mustCall(() => assert(handle.hasRef(), false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// tcp
|
// tcp
|
||||||
{
|
{
|
||||||
const assert = makeAssert('isRefed() not working on tcp_wrap');
|
const assert = makeAssert('hasRef() not working on tcp_wrap');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
const server = net.createServer(() => {}).listen(common.PORT);
|
const server = net.createServer(() => {}).listen(common.PORT);
|
||||||
assert(Object.getPrototypeOf(server._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(server._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(server._handle.isRefed(), true);
|
assert(server._handle.hasRef(), true);
|
||||||
assert(server._unref, false);
|
assert(server._unref, false);
|
||||||
server.unref();
|
server.unref();
|
||||||
assert(server._handle.isRefed(), false);
|
assert(server._handle.hasRef(), false);
|
||||||
assert(server._unref, true);
|
assert(server._unref, true);
|
||||||
server.ref();
|
server.ref();
|
||||||
assert(server._handle.isRefed(), true);
|
assert(server._handle.hasRef(), true);
|
||||||
assert(server._unref, false);
|
assert(server._unref, false);
|
||||||
server._handle.close(
|
server._handle.close(
|
||||||
common.mustCall(() => assert(server._handle.isRefed(), false)));
|
common.mustCall(() => assert(server._handle.hasRef(), false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
{
|
{
|
||||||
const assert = makeAssert('isRefed() not working on timer_wrap');
|
const assert = makeAssert('hasRef() not working on timer_wrap');
|
||||||
const timer = setTimeout(() => {}, 500);
|
const timer = setTimeout(() => {}, 500);
|
||||||
timer.unref();
|
timer.unref();
|
||||||
assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('isRefed'), true);
|
assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('hasRef'), true);
|
||||||
assert(timer._handle.isRefed(), false);
|
assert(timer._handle.hasRef(), false);
|
||||||
timer.ref();
|
timer.ref();
|
||||||
assert(timer._handle.isRefed(), true);
|
assert(timer._handle.hasRef(), true);
|
||||||
timer._handle.close(
|
timer._handle.close(
|
||||||
common.mustCall(() => assert(timer._handle.isRefed(), false)));
|
common.mustCall(() => assert(timer._handle.hasRef(), false)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user