Skip to content

Revert "readline: add stricter validation for functions called after close #58024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@ class Interface extends InterfaceConstructor {
* @returns {void | Interface}
*/
pause() {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (this.paused) return;
this.input.pause();
this.paused = true;
Expand All @@ -614,9 +611,6 @@ class Interface extends InterfaceConstructor {
* @returns {void | Interface}
*/
resume() {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (!this.paused) return;
this.input.resume();
this.paused = false;
Expand All @@ -637,9 +631,6 @@ class Interface extends InterfaceConstructor {
* @returns {void}
*/
write(d, key) {
if (this.closed) {
throw new ERR_USE_AFTER_CLOSE('readline');
}
if (this.paused) this.resume();
if (this.terminal) {
this[kTtyWrite](d, key);
Expand Down
41 changes: 0 additions & 41 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,47 +1202,6 @@ for (let i = 0; i < 12; i++) {
fi.emit('data', 'Node.js\n');
}

// Call write after close
{
const [rli, fi] = getInterface({ terminal });
rli.question('What\'s your name?', common.mustCall((name) => {
assert.strictEqual(name, 'Node.js');
rli.close();
assert.throws(() => {
rli.write('I said Node.js');
}, {
name: 'Error',
code: 'ERR_USE_AFTER_CLOSE'
});
}));
fi.emit('data', 'Node.js\n');
}

// Call pause/resume after close
{
const [rli, fi] = getInterface({ terminal });
rli.question('What\'s your name?', common.mustCall((name) => {
assert.strictEqual(name, 'Node.js');
rli.close();
// No 'resume' nor 'pause' event should be emitted after close
rli.on('resume', common.mustNotCall());
rli.on('pause', common.mustNotCall());
assert.throws(() => {
rli.pause();
}, {
name: 'Error',
code: 'ERR_USE_AFTER_CLOSE'
});
assert.throws(() => {
rli.resume();
}, {
name: 'Error',
code: 'ERR_USE_AFTER_CLOSE'
});
}));
fi.emit('data', 'Node.js\n');
}

// Can create a new readline Interface with a null output argument
{
const [rli, fi] = getInterface({ output: null, terminal });
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-readline-promises-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function assertCursorRowsAndCols(rli, rows, cols) {
fi.emit('data', character);
}
fi.emit('data', '\n');
fi.end();
rli.close();
}

// \t when there is no completer function should behave like an ordinary
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-readline-promises-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if (process.env.TERM === 'dumb') {
output = '';
});
}
fi.end();
rli.close();
});
});
});
Expand Down Expand Up @@ -114,5 +114,5 @@ if (process.env.TERM === 'dumb') {
assert.match(output, /^Tab completion error: Error: message/);
output = '';
});
fi.end();
rli.close();
}
16 changes: 6 additions & 10 deletions test/parallel/test-repl-import-referrer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ const args = ['--interactive'];
const opts = { cwd: fixtures.path('es-modules') };
const child = cp.spawn(process.execPath, args, opts);

const outputs = [];
let output = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
outputs.push(data);
if (outputs.length === 3) {
// All the expected outputs have been received
// so we can close the child process's stdin
child.stdin.end();
}
output += data;
});

child.on('exit', common.mustCall(() => {
const results = outputs[2].split('\n')[0];
assert.strictEqual(
const results = output.replace(/^> /mg, '').split('\n').slice(2);
assert.deepStrictEqual(
results,
'[Module: null prototype] { message: \'A message\' }'
['[Module: null prototype] { message: \'A message\' }', '']
);
}));

child.stdin.write('await import(\'./message.mjs\');\n');
child.stdin.write('.exit');
child.stdin.end();
13 changes: 4 additions & 9 deletions test/parallel/test-repl-no-terminal.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict';
const common = require('../common');
const ArrayStream = require('../common/arraystream');
const repl = require('repl');

const stream = new ArrayStream();

const replServer = repl.start({ terminal: false, input: stream, output: stream });

replServer.setupHistory('/nonexistent/file', common.mustSucceed(() => {
replServer.close();
}));
const repl = require('repl');
const r = repl.start({ terminal: false });
r.setupHistory('/nonexistent/file', common.mustSucceed());
process.stdin.unref?.();
2 changes: 1 addition & 1 deletion test/parallel/test-repl-uncaught-exception-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ r.write(
' throw new RangeError("abc");\n' +
'}, 1);console.log()\n'
);
r.close();

setTimeout(() => {
r.close();
const len = process.listenerCount('uncaughtException');
process.removeAllListeners('uncaughtException');
assert.strictEqual(len, 0);
Expand Down
Loading