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 <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
Deokjin Kim 2022-12-01 23:39:39 +09:00 committed by GitHub
parent f2c4fe922b
commit 59678813e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -145,7 +145,7 @@ Interface.prototype.question = function question(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) => {

View File

@ -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 });