-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tty: add ref() so process.stdin.ref() etc. work
Also squashed from: * test: move tty-wrap isrefed test to pseudo-tty/ * test: test tty-wrap handle isrefed properly * test: improve failure messages in isrefed tests PR-URL: #7360 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: James M Snell <jasnell.gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
- Loading branch information
1 parent
b20bc13
commit 3c54f81
Showing
8 changed files
with
135 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
// see also test/parallel/test-handle-wrap-isrefed.js | ||
|
||
const common = require('../common'); | ||
const strictEqual = require('assert').strictEqual; | ||
const ReadStream = require('tty').ReadStream; | ||
const tty = new ReadStream(0); | ||
const isTTY = process.binding('tty_wrap').isTTY; | ||
strictEqual(isTTY(0), true, 'tty_wrap: stdin is not a TTY'); | ||
strictEqual(Object.getPrototypeOf(tty._handle).hasOwnProperty('hasRef'), | ||
true, 'tty_wrap: hasRef() missing'); | ||
strictEqual(tty._handle.hasRef(), | ||
true, 'tty_wrap: not initially refed'); | ||
tty.unref(); | ||
strictEqual(tty._handle.hasRef(), | ||
false, 'tty_wrap: unref() ineffective'); | ||
tty.ref(); | ||
strictEqual(tty._handle.hasRef(), | ||
true, 'tty_wrap: ref() ineffective'); | ||
tty._handle.close(common.mustCall(() => | ||
strictEqual(tty._handle.hasRef(), | ||
false, 'tty_wrap: not unrefed on close'))); |
Empty file.