From ab89024ddc777ff888df0e239355f563e4cfa2a8 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 24 Aug 2022 19:12:30 +0200 Subject: [PATCH] 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 --- lib/tty.js | 2 +- test/parallel/test-repl-stdin-push-null.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-repl-stdin-push-null.js diff --git a/lib/tty.js b/lib/tty.js index 33e7c26f0291ed..3796c99cba62a4 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -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; diff --git a/test/parallel/test-repl-stdin-push-null.js b/test/parallel/test-repl-stdin-push-null.js new file mode 100644 index 00000000000000..53ba9ff7c33166 --- /dev/null +++ b/test/parallel/test-repl-stdin-push-null.js @@ -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);