Skip to content

Commit b673c69

Browse files
Revert "readline: add stricter validation for functions called after closed"
This reverts commit 8e7f32f. PR-URL: #58024 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 3b90f34 commit b673c69

7 files changed

+14
-73
lines changed

lib/internal/readline/interface.js

-9
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,6 @@ class Interface extends InterfaceConstructor {
599599
* @returns {void | Interface}
600600
*/
601601
pause() {
602-
if (this.closed) {
603-
throw new ERR_USE_AFTER_CLOSE('readline');
604-
}
605602
if (this.paused) return;
606603
this.input.pause();
607604
this.paused = true;
@@ -614,9 +611,6 @@ class Interface extends InterfaceConstructor {
614611
* @returns {void | Interface}
615612
*/
616613
resume() {
617-
if (this.closed) {
618-
throw new ERR_USE_AFTER_CLOSE('readline');
619-
}
620614
if (!this.paused) return;
621615
this.input.resume();
622616
this.paused = false;
@@ -637,9 +631,6 @@ class Interface extends InterfaceConstructor {
637631
* @returns {void}
638632
*/
639633
write(d, key) {
640-
if (this.closed) {
641-
throw new ERR_USE_AFTER_CLOSE('readline');
642-
}
643634
if (this.paused) this.resume();
644635
if (this.terminal) {
645636
this[kTtyWrite](d, key);

test/parallel/test-readline-interface.js

-41
Original file line numberDiff line numberDiff line change
@@ -1202,47 +1202,6 @@ for (let i = 0; i < 12; i++) {
12021202
fi.emit('data', 'Node.js\n');
12031203
}
12041204

1205-
// Call write after close
1206-
{
1207-
const [rli, fi] = getInterface({ terminal });
1208-
rli.question('What\'s your name?', common.mustCall((name) => {
1209-
assert.strictEqual(name, 'Node.js');
1210-
rli.close();
1211-
assert.throws(() => {
1212-
rli.write('I said Node.js');
1213-
}, {
1214-
name: 'Error',
1215-
code: 'ERR_USE_AFTER_CLOSE'
1216-
});
1217-
}));
1218-
fi.emit('data', 'Node.js\n');
1219-
}
1220-
1221-
// Call pause/resume after close
1222-
{
1223-
const [rli, fi] = getInterface({ terminal });
1224-
rli.question('What\'s your name?', common.mustCall((name) => {
1225-
assert.strictEqual(name, 'Node.js');
1226-
rli.close();
1227-
// No 'resume' nor 'pause' event should be emitted after close
1228-
rli.on('resume', common.mustNotCall());
1229-
rli.on('pause', common.mustNotCall());
1230-
assert.throws(() => {
1231-
rli.pause();
1232-
}, {
1233-
name: 'Error',
1234-
code: 'ERR_USE_AFTER_CLOSE'
1235-
});
1236-
assert.throws(() => {
1237-
rli.resume();
1238-
}, {
1239-
name: 'Error',
1240-
code: 'ERR_USE_AFTER_CLOSE'
1241-
});
1242-
}));
1243-
fi.emit('data', 'Node.js\n');
1244-
}
1245-
12461205
// Can create a new readline Interface with a null output argument
12471206
{
12481207
const [rli, fi] = getInterface({ output: null, terminal });

test/parallel/test-readline-promises-interface.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function assertCursorRowsAndCols(rli, rows, cols) {
204204
fi.emit('data', character);
205205
}
206206
fi.emit('data', '\n');
207-
fi.end();
207+
rli.close();
208208
}
209209

210210
// \t when there is no completer function should behave like an ordinary

test/parallel/test-readline-promises-tab-complete.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if (process.env.TERM === 'dumb') {
8080
output = '';
8181
});
8282
}
83-
fi.end();
83+
rli.close();
8484
});
8585
});
8686
});
@@ -114,5 +114,5 @@ if (process.env.TERM === 'dumb') {
114114
assert.match(output, /^Tab completion error: Error: message/);
115115
output = '';
116116
});
117-
fi.end();
117+
rli.close();
118118
}

test/parallel/test-repl-import-referrer.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,20 @@ const args = ['--interactive'];
88
const opts = { cwd: fixtures.path('es-modules') };
99
const child = cp.spawn(process.execPath, args, opts);
1010

11-
const outputs = [];
11+
let output = '';
1212
child.stdout.setEncoding('utf8');
1313
child.stdout.on('data', (data) => {
14-
outputs.push(data);
15-
if (outputs.length === 3) {
16-
// All the expected outputs have been received
17-
// so we can close the child process's stdin
18-
child.stdin.end();
19-
}
14+
output += data;
2015
});
2116

2217
child.on('exit', common.mustCall(() => {
23-
const results = outputs[2].split('\n')[0];
24-
assert.strictEqual(
18+
const results = output.replace(/^> /mg, '').split('\n').slice(2);
19+
assert.deepStrictEqual(
2520
results,
26-
'[Module: null prototype] { message: \'A message\' }'
21+
['[Module: null prototype] { message: \'A message\' }', '']
2722
);
2823
}));
2924

3025
child.stdin.write('await import(\'./message.mjs\');\n');
3126
child.stdin.write('.exit');
27+
child.stdin.end();
+4-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
'use strict';
22
const common = require('../common');
3-
const ArrayStream = require('../common/arraystream');
4-
const repl = require('repl');
5-
6-
const stream = new ArrayStream();
73

8-
const replServer = repl.start({ terminal: false, input: stream, output: stream });
9-
10-
replServer.setupHistory('/nonexistent/file', common.mustSucceed(() => {
11-
replServer.close();
12-
}));
4+
const repl = require('repl');
5+
const r = repl.start({ terminal: false });
6+
r.setupHistory('/nonexistent/file', common.mustSucceed());
7+
process.stdin.unref?.();

test/parallel/test-repl-uncaught-exception-async.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ r.write(
3434
' throw new RangeError("abc");\n' +
3535
'}, 1);console.log()\n'
3636
);
37+
r.close();
3738

3839
setTimeout(() => {
39-
r.close();
4040
const len = process.listenerCount('uncaughtException');
4141
process.removeAllListeners('uncaughtException');
4242
assert.strictEqual(len, 0);

0 commit comments

Comments
 (0)