Skip to content

Commit 736d855

Browse files
committed
readline: initialize input before history manager
1 parent d14b484 commit 736d855

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/internal/readline/interface.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ function InterfaceConstructor(input, output, completer, terminal) {
172172
let crlfDelay;
173173
let prompt = '> ';
174174
let signal;
175+
let historySize;
176+
let history;
177+
let removeHistoryDuplicates;
175178

176179
if (input?.input) {
177180
// An options object was given
@@ -181,9 +184,9 @@ function InterfaceConstructor(input, output, completer, terminal) {
181184
signal = input.signal;
182185

183186
// It is possible to configure the history through the input object
184-
const historySize = input.historySize;
185-
const history = input.history;
186-
const removeHistoryDuplicates = input.removeHistoryDuplicates;
187+
historySize = input.historySize;
188+
history = input.history;
189+
removeHistoryDuplicates = input.removeHistoryDuplicates;
187190

188191
if (input.tabSize !== undefined) {
189192
validateUint32(input.tabSize, 'tabSize', true);
@@ -215,8 +218,6 @@ function InterfaceConstructor(input, output, completer, terminal) {
215218
input.removeHistoryDuplicates = removeHistoryDuplicates;
216219
}
217220

218-
this.setupHistoryManager(input);
219-
220221
if (completer !== undefined && typeof completer !== 'function') {
221222
throw new ERR_INVALID_ARG_VALUE('completer', completer);
222223
}
@@ -234,6 +235,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
234235
this[kSubstringSearch] = null;
235236
this.output = output;
236237
this.input = input;
238+
this.setupHistoryManager(input);
237239
this[kUndoStack] = [];
238240
this[kRedoStack] = [];
239241
this[kPreviousCursorCols] = -1;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const readline = require('readline');
4+
const assert = require('assert');
5+
6+
assert.doesNotThrow(() => {
7+
const input = new Proxy({}, {
8+
get(_target, prop) {
9+
if (prop === 'pause') return () => {};
10+
if (prop === 'resume') return () => {};
11+
return () => {};
12+
},
13+
});
14+
15+
readline.createInterface(input);
16+
});

0 commit comments

Comments
 (0)