mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00
Revert "readline: add stricter validation for functions called after closed"
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
This reverts commit 8e7f32f968
.
PR-URL: https://github.com/nodejs/node/pull/58024
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
parent
3b90f3454d
commit
b673c697a7
@ -599,9 +599,6 @@ class Interface extends InterfaceConstructor {
|
|||||||
* @returns {void | Interface}
|
* @returns {void | Interface}
|
||||||
*/
|
*/
|
||||||
pause() {
|
pause() {
|
||||||
if (this.closed) {
|
|
||||||
throw new ERR_USE_AFTER_CLOSE('readline');
|
|
||||||
}
|
|
||||||
if (this.paused) return;
|
if (this.paused) return;
|
||||||
this.input.pause();
|
this.input.pause();
|
||||||
this.paused = true;
|
this.paused = true;
|
||||||
@ -614,9 +611,6 @@ class Interface extends InterfaceConstructor {
|
|||||||
* @returns {void | Interface}
|
* @returns {void | Interface}
|
||||||
*/
|
*/
|
||||||
resume() {
|
resume() {
|
||||||
if (this.closed) {
|
|
||||||
throw new ERR_USE_AFTER_CLOSE('readline');
|
|
||||||
}
|
|
||||||
if (!this.paused) return;
|
if (!this.paused) return;
|
||||||
this.input.resume();
|
this.input.resume();
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
@ -637,9 +631,6 @@ class Interface extends InterfaceConstructor {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
write(d, key) {
|
write(d, key) {
|
||||||
if (this.closed) {
|
|
||||||
throw new ERR_USE_AFTER_CLOSE('readline');
|
|
||||||
}
|
|
||||||
if (this.paused) this.resume();
|
if (this.paused) this.resume();
|
||||||
if (this.terminal) {
|
if (this.terminal) {
|
||||||
this[kTtyWrite](d, key);
|
this[kTtyWrite](d, key);
|
||||||
|
@ -1202,47 +1202,6 @@ for (let i = 0; i < 12; i++) {
|
|||||||
fi.emit('data', 'Node.js\n');
|
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
|
// Can create a new readline Interface with a null output argument
|
||||||
{
|
{
|
||||||
const [rli, fi] = getInterface({ output: null, terminal });
|
const [rli, fi] = getInterface({ output: null, terminal });
|
||||||
|
@ -204,7 +204,7 @@ function assertCursorRowsAndCols(rli, rows, cols) {
|
|||||||
fi.emit('data', character);
|
fi.emit('data', character);
|
||||||
}
|
}
|
||||||
fi.emit('data', '\n');
|
fi.emit('data', '\n');
|
||||||
fi.end();
|
rli.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// \t when there is no completer function should behave like an ordinary
|
// \t when there is no completer function should behave like an ordinary
|
||||||
|
@ -80,7 +80,7 @@ if (process.env.TERM === 'dumb') {
|
|||||||
output = '';
|
output = '';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
fi.end();
|
rli.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -114,5 +114,5 @@ if (process.env.TERM === 'dumb') {
|
|||||||
assert.match(output, /^Tab completion error: Error: message/);
|
assert.match(output, /^Tab completion error: Error: message/);
|
||||||
output = '';
|
output = '';
|
||||||
});
|
});
|
||||||
fi.end();
|
rli.close();
|
||||||
}
|
}
|
||||||
|
@ -8,24 +8,20 @@ const args = ['--interactive'];
|
|||||||
const opts = { cwd: fixtures.path('es-modules') };
|
const opts = { cwd: fixtures.path('es-modules') };
|
||||||
const child = cp.spawn(process.execPath, args, opts);
|
const child = cp.spawn(process.execPath, args, opts);
|
||||||
|
|
||||||
const outputs = [];
|
let output = '';
|
||||||
child.stdout.setEncoding('utf8');
|
child.stdout.setEncoding('utf8');
|
||||||
child.stdout.on('data', (data) => {
|
child.stdout.on('data', (data) => {
|
||||||
outputs.push(data);
|
output += data;
|
||||||
if (outputs.length === 3) {
|
|
||||||
// All the expected outputs have been received
|
|
||||||
// so we can close the child process's stdin
|
|
||||||
child.stdin.end();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
child.on('exit', common.mustCall(() => {
|
child.on('exit', common.mustCall(() => {
|
||||||
const results = outputs[2].split('\n')[0];
|
const results = output.replace(/^> /mg, '').split('\n').slice(2);
|
||||||
assert.strictEqual(
|
assert.deepStrictEqual(
|
||||||
results,
|
results,
|
||||||
'[Module: null prototype] { message: \'A message\' }'
|
['[Module: null prototype] { message: \'A message\' }', '']
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
child.stdin.write('await import(\'./message.mjs\');\n');
|
child.stdin.write('await import(\'./message.mjs\');\n');
|
||||||
child.stdin.write('.exit');
|
child.stdin.write('.exit');
|
||||||
|
child.stdin.end();
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const ArrayStream = require('../common/arraystream');
|
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
const r = repl.start({ terminal: false });
|
||||||
const stream = new ArrayStream();
|
r.setupHistory('/nonexistent/file', common.mustSucceed());
|
||||||
|
process.stdin.unref?.();
|
||||||
const replServer = repl.start({ terminal: false, input: stream, output: stream });
|
|
||||||
|
|
||||||
replServer.setupHistory('/nonexistent/file', common.mustSucceed(() => {
|
|
||||||
replServer.close();
|
|
||||||
}));
|
|
||||||
|
@ -34,9 +34,9 @@ r.write(
|
|||||||
' throw new RangeError("abc");\n' +
|
' throw new RangeError("abc");\n' +
|
||||||
'}, 1);console.log()\n'
|
'}, 1);console.log()\n'
|
||||||
);
|
);
|
||||||
|
r.close();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
r.close();
|
|
||||||
const len = process.listenerCount('uncaughtException');
|
const len = process.listenerCount('uncaughtException');
|
||||||
process.removeAllListeners('uncaughtException');
|
process.removeAllListeners('uncaughtException');
|
||||||
assert.strictEqual(len, 0);
|
assert.strictEqual(len, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user