Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
tty: add ref() so process.stdin.ref() etc. work
  • Loading branch information
insightfuls authored and Ben Schmidt committed Feb 21, 2017
commit 0a0024e804375eca5ac7fc968df74818c284f277
1 change: 1 addition & 0 deletions src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void TTYWrap::Initialize(Local<Object> target,

env->SetProtoMethod(t, "close", HandleWrap::Close);
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef);

StreamWrap::AddMethods(env, t, StreamBase::kFlagNoShutdown);
Expand Down
5 changes: 5 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ On how to run tests in this direcotry, see
<td>Yes</td>
<td>Various tests that are able to be run in parallel.</td>
</tr>
<tr>
<td>pseudo-tty</td>
<td>Yes</td>
<td>Tests that require stdin/stdout/stderr to be a TTY.</td>
</tr>
<tr>
<td>pummel</td>
<td>No</td>
Expand Down
27 changes: 27 additions & 0 deletions test/pseudo-tty/ref_keeps_node_running.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
require('../common');

const { TTY, isTTY } = process.binding('tty_wrap');
const strictEqual = require('assert').strictEqual;

strictEqual(isTTY(0), true, 'fd 0 is not a TTY');

const handle = new TTY(0);
handle.readStart();
handle.onread = () => {};

function isHandleActive(handle) {
return process._getActiveHandles().some((active) => active === handle);
}

strictEqual(isHandleActive(handle), true, 'TTY handle not initially active');

handle.unref();

strictEqual(isHandleActive(handle), false, 'TTY handle active after unref()');

handle.ref();

strictEqual(isHandleActive(handle), true, 'TTY handle inactive after ref()');

handle.unref();
Empty file.