From f10ef73ef57e37e912098e0d6b9483764bea4f31 Mon Sep 17 00:00:00 2001 From: Nitzan Uziely Date: Fri, 26 Mar 2021 20:09:28 +0300 Subject: [PATCH] fixup! readline: fix pre-aborted signal question handling --- lib/readline.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index bea005c853c46f..5166dddfa1565d 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -59,6 +59,7 @@ const { StringPrototypeStartsWith, StringPrototypeTrim, Promise, + PromiseReject, Symbol, SymbolAsyncIterator, SafeStringIterator, @@ -400,11 +401,11 @@ Interface.prototype.question = function(query, options, cb) { Interface.prototype.question[promisify.custom] = function(query, options) { options = typeof options === 'object' && options !== null ? options : {}; - return new Promise((resolve, reject) => { - if (options.signal?.aborted) { - throw new AbortError(); - } + if (options.signal && options.signal.aborted) { + return PromiseReject(new AbortError()); + } + return new Promise((resolve, reject) => { this.question(query, options, resolve); if (options.signal) { options.signal.addEventListener('abort', () => {