Skip to content

Commit f692b0d

Browse files
deokjinkimdanielleadams
authored andcommitted
lib: add missing type of removeEventListener in question
removeEventListener of signal is not working because event type is missed. PR-URL: #45676 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent cfc1bf0 commit f692b0d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/readline.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Interface.prototype.question = function(query, options, cb) {
146146
};
147147
options.signal.addEventListener('abort', onAbort, { once: true });
148148
const cleanup = () => {
149-
options.signal.removeEventListener(onAbort);
149+
options.signal.removeEventListener('abort', onAbort);
150150
};
151151
const originalCb = cb;
152152
cb = typeof cb === 'function' ? (answer) => {

test/parallel/test-readline-interface.js

+18
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,24 @@ for (let i = 0; i < 12; i++) {
921921
fi.emit('data', 'asdf\n');
922922
}
923923

924+
// Ensure that options.signal.removeEventListener was called
925+
{
926+
const ac = new AbortController();
927+
const signal = ac.signal;
928+
const [rli] = getInterface({ terminal });
929+
signal.removeEventListener = common.mustCall(
930+
(event, onAbortFn) => {
931+
assert.strictEqual(event, 'abort');
932+
assert.strictEqual(onAbortFn.name, 'onAbort');
933+
});
934+
935+
rli.question('hello?', { signal }, common.mustCall());
936+
937+
rli.write('bar\n');
938+
ac.abort();
939+
rli.close();
940+
}
941+
924942
// Sending a blank line
925943
{
926944
const [rli, fi] = getInterface({ terminal });

0 commit comments

Comments
 (0)