Skip to content

Commit

Permalink
lib: add missing type of removeEventListener in question
Browse files Browse the repository at this point in the history
removeEventListener of signal is not working because
event type is missed.

PR-URL: #45676
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
deokjinkim authored and danielleadams committed Jan 3, 2023
1 parent d9593ce commit 1ff8f68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 1ff8f68

Please sign in to comment.