From f692b0dfdf57244886d494818df5b80fbb07c284 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 1 Dec 2022 23:39:39 +0900 Subject: [PATCH] lib: add missing type of removeEventListener in question removeEventListener of signal is not working because event type is missed. PR-URL: https://github.com/nodejs/node/pull/45676 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca --- lib/readline.js | 2 +- test/parallel/test-readline-interface.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/readline.js b/lib/readline.js index 51ba11577bf813..ea644e1991ea11 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -146,7 +146,7 @@ Interface.prototype.question = function(query, options, cb) { }; options.signal.addEventListener('abort', onAbort, { once: true }); const cleanup = () => { - options.signal.removeEventListener(onAbort); + options.signal.removeEventListener('abort', onAbort); }; const originalCb = cb; cb = typeof cb === 'function' ? (answer) => { diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 7bffa0b66e5cf8..b5a3b0499fcdbd 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -921,6 +921,24 @@ for (let i = 0; i < 12; i++) { fi.emit('data', 'asdf\n'); } + // Ensure that options.signal.removeEventListener was called + { + const ac = new AbortController(); + const signal = ac.signal; + const [rli] = getInterface({ terminal }); + signal.removeEventListener = common.mustCall( + (event, onAbortFn) => { + assert.strictEqual(event, 'abort'); + assert.strictEqual(onAbortFn.name, 'onAbort'); + }); + + rli.question('hello?', { signal }, common.mustCall()); + + rli.write('bar\n'); + ac.abort(); + rli.close(); + } + // Sending a blank line { const [rli, fi] = getInterface({ terminal });