readline: add stricter validation for functions called after closed

PR-URL: https://github.com/nodejs/node/pull/57680
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Dario Piotrowicz 2025-03-29 22:20:33 +00:00 committed by James M Snell
parent 68cc1c9cd3
commit 8e7f32f968
7 changed files with 73 additions and 14 deletions

View file

@ -599,6 +599,9 @@ class Interface extends InterfaceConstructor {
* @returns {void | Interface}
*/
pause() {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (this.paused) return;
this.input.pause();
this.paused = true;
@ -611,6 +614,9 @@ class Interface extends InterfaceConstructor {
* @returns {void | Interface}
*/
resume() {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (!this.paused) return;
this.input.resume();
this.paused = false;
@ -631,6 +637,9 @@ class Interface extends InterfaceConstructor {
* @returns {void}
*/
write(d, key) {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (this.paused) this.resume();
if (this.terminal) {
this[kTtyWrite](d, key);