Skip to content
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
6 changes: 6 additions & 0 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ class Interface extends InterfaceConstructor {

[kInsertString](c) {
this[kBeforeEdit](this.line, this.cursor);
if (!this.isCompletionEnabled) {
this.line += c;
this.cursor += c.length;
this[kWriteToOutput](c);
return;
}
if (this.cursor < this.line.length) {
const beg = StringPrototypeSlice(this.line, 0, this.cursor);
const end = StringPrototypeSlice(
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-repl-paste-big-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const common = require('../common');
const repl = require('repl');
const stream = require('stream');
const assert = require('assert');

// Pasting big input should not cause the process to have a huge CPU usage.

const cpuUsage = process.cpuUsage();

const r = initRepl();
r.input.emit('data', 'a'.repeat(2e4) + '\n');
r.input.emit('data', '.exit\n');

r.once('exit', common.mustCall(() => {
const diff = process.cpuUsage(cpuUsage);
assert.ok(diff.user < 1e6);
}));

function initRepl() {
const input = new stream();
input.write = input.pause = input.resume = () => {};
input.readable = true;

const output = new stream();
output.write = () => {};
output.writable = true;

return repl.start({
input,
output,
terminal: true,
prompt: ''
});
}
Loading