readline: fix question still called after closed

resolve: https://github.com/nodejs/node/issues/42450

PR-URL: https://github.com/nodejs/node/pull/42464
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Xuguang Mei 2022-04-08 18:17:03 +08:00 committed by GitHub
parent 0bac5478eb
commit d36b60e69a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 1 deletions

View file

@ -38,7 +38,10 @@ const {
const { codes } = require('internal/errors');
const { ERR_INVALID_ARG_VALUE } = codes;
const {
ERR_INVALID_ARG_VALUE,
ERR_USE_AFTER_CLOSE,
} = codes;
const {
validateAbortSignal,
validateArray,
@ -398,6 +401,9 @@ class Interface extends InterfaceConstructor {
}
question(query, cb) {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (this[kQuestionCallback]) {
this.prompt();
} else {