From ff93f3e1a8fa2018f53e38e9afb668aed00d9659 Mon Sep 17 00:00:00 2001 From: atlowChemi Date: Thu, 14 Mar 2024 10:55:07 +0200 Subject: [PATCH] readline: use internal addAbortListener PR-URL: https://github.com/nodejs/node/pull/52081 Refs: https://github.com/nodejs/node/pull/48596 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca --- lib/internal/readline/interface.js | 3 ++- lib/readline.js | 4 ++-- lib/readline/promises.js | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index f7f06674ef7c41..f8120ca47b2829 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -53,6 +53,7 @@ const { stripVTControlCharacters, } = require('internal/util/inspect'); const EventEmitter = require('events'); +const { addAbortListener } = require('internal/events/abort_listener'); const { charLengthAt, charLengthLeft, @@ -326,7 +327,7 @@ function InterfaceConstructor(input, output, completer, terminal) { if (signal.aborted) { process.nextTick(onAborted); } else { - const disposable = EventEmitter.addAbortListener(signal, onAborted); + const disposable = addAbortListener(signal, onAborted); self.once('close', disposable[SymbolDispose]); } } diff --git a/lib/readline.js b/lib/readline.js index 5276d9401b4c12..509c7022ee95cc 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -145,7 +145,7 @@ Interface.prototype.question = function question(query, options, cb) { const onAbort = () => { this[kQuestionCancel](); }; - addAbortListener ??= require('events').addAbortListener; + addAbortListener ??= require('internal/events/abort_listener').addAbortListener; const disposable = addAbortListener(options.signal, onAbort); const originalCb = cb; cb = typeof cb === 'function' ? (answer) => { @@ -175,7 +175,7 @@ Interface.prototype.question[promisify.custom] = function question(query, option const onAbort = () => { reject(new AbortError(undefined, { cause: options.signal.reason })); }; - addAbortListener ??= require('events').addAbortListener; + addAbortListener ??= require('internal/events/abort_listener').addAbortListener; const disposable = addAbortListener(options.signal, onAbort); cb = (answer) => { disposable[SymbolDispose](); diff --git a/lib/readline/promises.js b/lib/readline/promises.js index 4c2ce90479ef8f..ccd0745a33f941 100644 --- a/lib/readline/promises.js +++ b/lib/readline/promises.js @@ -45,7 +45,7 @@ class Interface extends _Interface { this[kQuestionCancel](); reject(new AbortError(undefined, { cause: options.signal.reason })); }; - addAbortListener ??= require('events').addAbortListener; + addAbortListener ??= require('internal/events/abort_listener').addAbortListener; const disposable = addAbortListener(options.signal, onAbort); cb = (answer) => {