mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
Backport-PR-URL: https://github.com/nodejs/node/pull/19579 PR-URL: https://github.com/nodejs/node/pull/13686 Fixes: https://github.com/nodejs/node/issues/13682 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
45 lines
989 B
JavaScript
45 lines
989 B
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const tty = require('tty');
|
|
|
|
common.expectsError(() => {
|
|
new tty.WriteStream(-1);
|
|
}, {
|
|
code: 'ERR_INVALID_FD',
|
|
type: RangeError,
|
|
message: '"fd" must be a positive integer: -1'
|
|
});
|
|
|
|
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);
|
|
|
|
common.expectsError(() => {
|
|
new tty.ReadStream(-1);
|
|
}, {
|
|
code: 'ERR_INVALID_FD',
|
|
type: RangeError,
|
|
message: '"fd" must be a positive integer: -1'
|
|
});
|
|
|
|
assert.throws(() => {
|
|
let fd = 2;
|
|
// Get first known bad file descriptor.
|
|
try {
|
|
while (fs.fstatSync(++fd));
|
|
} catch (e) { }
|
|
new tty.ReadStream(fd);
|
|
}, err_regex);
|