diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index 08f7aaa9e3e7e8..1faff6a727fc07 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -172,6 +172,9 @@ function InterfaceConstructor(input, output, completer, terminal) { let crlfDelay; let prompt = '> '; let signal; + let historySize; + let history; + let removeHistoryDuplicates; if (input?.input) { // An options object was given @@ -181,9 +184,9 @@ function InterfaceConstructor(input, output, completer, terminal) { signal = input.signal; // It is possible to configure the history through the input object - const historySize = input.historySize; - const history = input.history; - const removeHistoryDuplicates = input.removeHistoryDuplicates; + historySize = input.historySize; + history = input.history; + removeHistoryDuplicates = input.removeHistoryDuplicates; if (input.tabSize !== undefined) { validateUint32(input.tabSize, 'tabSize', true); @@ -215,8 +218,6 @@ function InterfaceConstructor(input, output, completer, terminal) { input.removeHistoryDuplicates = removeHistoryDuplicates; } - this.setupHistoryManager(input); - if (completer !== undefined && typeof completer !== 'function') { throw new ERR_INVALID_ARG_VALUE('completer', completer); } @@ -234,6 +235,7 @@ function InterfaceConstructor(input, output, completer, terminal) { this[kSubstringSearch] = null; this.output = output; this.input = input; + this.setupHistoryManager(input); this[kUndoStack] = []; this[kRedoStack] = []; this[kPreviousCursorCols] = -1; diff --git a/test/parallel/test-readline-history-init-order.js b/test/parallel/test-readline-history-init-order.js new file mode 100644 index 00000000000000..19923decb4bc46 --- /dev/null +++ b/test/parallel/test-readline-history-init-order.js @@ -0,0 +1,16 @@ +'use strict'; + +const readline = require('readline'); +const assert = require('assert'); + +assert.doesNotThrow(() => { + const input = new Proxy({}, { + get(_target, prop) { + if (prop === 'pause') return () => {}; + if (prop === 'resume') return () => {}; + return () => {}; + }, + }); + + readline.createInterface(input); +});