diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index 4fd69d43c48561..46674883381392 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -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( diff --git a/test/parallel/test-repl-paste-big-data.js b/test/parallel/test-repl-paste-big-data.js new file mode 100644 index 00000000000000..fd247b4b063192 --- /dev/null +++ b/test/parallel/test-repl-paste-big-data.js @@ -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: '' + }); +}