-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tty_wrap: throw when uv_tty_init() returns error
Also add checks in lib/tty.js and tests. PR-URL: #12892 Ref: #11883 Ref: #8531 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
- Loading branch information
1 parent
dd6e3f6
commit 4b9d84d
Showing
4 changed files
with
56 additions
and
5 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 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,36 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const tty = require('tty'); | ||
|
||
|
||
assert.throws(() => { | ||
new tty.WriteStream(-1); | ||
}, /fd must be positive integer:/); | ||
|
||
const err_regex = common.isWindows ? | ||
/^Error: EBADF: bad file descriptor, uv_tty_init$/ : | ||
/^Error: EINVAL: invalid argument, uv_tty_init$/; | ||
assert.throws(() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.WriteStream(fd); | ||
}, err_regex); | ||
|
||
assert.throws(() => { | ||
new tty.ReadStream(-1); | ||
}, /fd must be positive integer:/); | ||
|
||
assert.throws(() => { | ||
let fd = 2; | ||
// Get first known bad file descriptor. | ||
try { | ||
while (fs.fstatSync(++fd)); | ||
} catch (e) { } | ||
new tty.ReadStream(fd); | ||
}, err_regex); |