tty: fix TypeError when stream is closed

Fixes: https://github.com/nodejs/node/issues/41330
PR-URL: https://github.com/nodejs/node/pull/43803
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Antoine du Hamel authored and RafaelGSS committed 2022-09-05 11:32:54 -03:00
1 parent 1f23c17ae0
commit 8b0a4afcae
2 files changed
+10 -1

No files matched your search

+1 -1
View File
@@ -72,7 +72,7 @@ ObjectSetPrototypeOf(ReadStream, net.Socket);
ReadStream.prototype.setRawMode = function(flag) {
flag = !!flag;
const err = this._handle.setRawMode(flag);
const err = this._handle?.setRawMode(flag);
if (err) {
this.emit('error', errors.errnoException(err, 'setRawMode'));
return this;
@@ -0,0 +1,9 @@
'use strict';
const common = require('../common');
if (!process.stdin.isTTY) {
common.skip('does not apply on non-TTY stdin');
}
process.stdin.destroy();
process.stdin.setRawMode(true);