| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5c7da21 commit d313204
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | 10 | namespace node { | |
| 11 | 11 | ||
| 12 | + using v8::Boolean; | ||
| 12 | 13 | using v8::Context; | |
| 13 | 14 | using v8::FunctionCallbackInfo; | |
| 14 | 15 | using v8::HandleScope; | |
@@ -37,6 +38,15 @@ void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { | |||
| 37 | 38 | } | |
| 38 | 39 | ||
| 39 | 40 | ||
| 41 | + void HandleWrap::IsRefed(const FunctionCallbackInfo<Value>& args) { | ||
| 42 | + Environment* env = Environment::GetCurrent(args); | ||
| 43 | + HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); | ||
| 44 | + | ||
| 45 | + bool refed = IsAlive(wrap) && (wrap->flags_ & kUnref) == 0; | ||
| 46 | + args.GetReturnValue().Set(refed); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + | ||
| 40 | 50 | void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { | |
| 41 | 51 | Environment* env = Environment::GetCurrent(args); | |
| 42 | 52 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ class HandleWrap : public AsyncWrap { | |||
| 35 | 35 | static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 36 | 36 | static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 37 | 37 | static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 38 | + static void IsRefed(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 38 | 39 | ||
| 39 | 40 | static inline bool IsAlive(const HandleWrap* wrap) { | |
| 40 | 41 | return wrap != nullptr && wrap->GetHandle() != nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,7 @@ void PipeWrap::Initialize(Local<Object> target, | |||
| 80 | 80 | env->SetProtoMethod(t, "close", HandleWrap::Close); | |
| 81 | 81 | env->SetProtoMethod(t, "unref", HandleWrap::Unref); | |
| 82 | 82 | env->SetProtoMethod(t, "ref", HandleWrap::Ref); | |
| 83 | + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); | ||
| 83 | 84 | ||
| 84 | 85 | StreamWrap::AddMethods(env, t); | |
| 85 | 86 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,6 +40,7 @@ class ProcessWrap : public HandleWrap { | |||
| 40 | 40 | ||
| 41 | 41 | env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); | |
| 42 | 42 | env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); | |
| 43 | + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); | ||
| 43 | 44 | ||
| 44 | 45 | target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "Process"), | |
| 45 | 46 | constructor->GetFunction()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ class SignalWrap : public HandleWrap { | |||
| 32 | 32 | env->SetProtoMethod(constructor, "close", HandleWrap::Close); | |
| 33 | 33 | env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); | |
| 34 | 34 | env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); | |
| 35 | + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); | ||
| 35 | 36 | env->SetProtoMethod(constructor, "start", Start); | |
| 36 | 37 | env->SetProtoMethod(constructor, "stop", Stop); | |
| 37 | 38 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,7 @@ void TCPWrap::Initialize(Local<Object> target, | |||
| 87 | 87 | ||
| 88 | 88 | env->SetProtoMethod(t, "ref", HandleWrap::Ref); | |
| 89 | 89 | env->SetProtoMethod(t, "unref", HandleWrap::Unref); | |
| 90 | + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); | ||
| 90 | 91 | ||
| 91 | 92 | StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); | |
| 92 | 93 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,7 @@ class TimerWrap : public HandleWrap { | |||
| 39 | 39 | env->SetProtoMethod(constructor, "close", HandleWrap::Close); | |
| 40 | 40 | env->SetProtoMethod(constructor, "ref", HandleWrap::Ref); | |
| 41 | 41 | env->SetProtoMethod(constructor, "unref", HandleWrap::Unref); | |
| 42 | + env->SetProtoMethod(constructor, "isRefed", HandleWrap::IsRefed); | ||
| 42 | 43 | ||
| 43 | 44 | env->SetProtoMethod(constructor, "start", Start); | |
| 44 | 45 | env->SetProtoMethod(constructor, "stop", Stop); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,7 @@ void TTYWrap::Initialize(Local<Object> target, | |||
| 36 | 36 | ||
| 37 | 37 | env->SetProtoMethod(t, "close", HandleWrap::Close); | |
| 38 | 38 | env->SetProtoMethod(t, "unref", HandleWrap::Unref); | |
| 39 | + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); | ||
| 39 | 40 | ||
| 40 | 41 | StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown); | |
| 41 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -108,6 +108,7 @@ void UDPWrap::Initialize(Local<Object> target, | |||
| 108 | 108 | ||
| 109 | 109 | env->SetProtoMethod(t, "ref", HandleWrap::Ref); | |
| 110 | 110 | env->SetProtoMethod(t, "unref", HandleWrap::Unref); | |
| 111 | + env->SetProtoMethod(t, "isRefed", HandleWrap::IsRefed); | ||
| 111 | 112 | ||
| 112 | 113 | target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "UDP"), t->GetFunction()); | |
| 113 | 114 | env->set_udp_constructor_function(t->GetFunction()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const strictEqual = require('assert').strictEqual; | ||
| 5 | + const spawn = require('child_process').spawn; | ||
| 6 | + | ||
| 7 | + function makeAssert(message) { | ||
| 8 | + return function(actual, expected) { | ||
| 9 | + strictEqual(actual, expected, message); | ||
| 10 | + }; | ||
| 11 | + } | ||
| 12 | + const assert = makeAssert('isRefed() not working on tty_wrap'); | ||
| 13 | + | ||
| 14 | + if (process.argv[2] === 'child') { | ||
| 15 | + // Test tty_wrap in piped child to guarentee stdin being a TTY. | ||
| 16 | + const ReadStream = require('tty').ReadStream; | ||
| 17 | + const tty = new ReadStream(0); | ||
| 18 | + assert(Object.getPrototypeOf(tty._handle).hasOwnProperty('isRefed'), true); | ||
| 19 | + assert(tty._handle.isRefed(), true); | ||
| 20 | + tty.unref(); | ||
| 21 | + assert(tty._handle.isRefed(), false); | ||
| 22 | + return; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + // Use spawn so that we can be sure that stdin has a _handle property. | ||
| 26 | + // Refs: https://github.com/nodejs/node/pull/5916 | ||
| 27 | + const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' }); | ||
| 28 | + proc.stderr.pipe(process.stderr); | ||
| 29 | + proc.on('exit', common.mustCall(function(exitCode) { | ||
| 30 | + process.exitCode = exitCode; | ||
| 31 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments