Skip to content

Commit

Permalink
repl: fix tab-complete warning
Browse files Browse the repository at this point in the history
When create a nest repl, will register `Runtime.executionContextCreated`
listener to the inspector session.This patch will fix listener
repeatedly register.

PR-URL: #18881
Fixes: #18284
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
killagu authored and addaleax committed Feb 26, 2018
1 parent edba129 commit 01398b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ REPLServer.prototype.createContext = function() {
} else {
sendInspectorCommand((session) => {
session.post('Runtime.enable');
session.on('Runtime.executionContextCreated', ({ params }) => {
session.once('Runtime.executionContextCreated', ({ params }) => {
this[kContextId] = params.context.id;
});
context = vm.createContext();
Expand Down Expand Up @@ -834,7 +834,6 @@ function complete(line, callback) {
var flat = new ArrayStream(); // make a new "input" stream
var magic = new REPLServer('', flat); // make a nested REPL
replMap.set(magic, replMap.get(this));
magic.resetContext();
flat.run(tmp); // eval the flattened code
// all this is only profitable if the nested REPL
// does not have a bufferedCommand
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-repl-tab-complete-no-warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const common = require('../common');
const repl = require('repl');
const DEFAULT_MAX_LISTENERS = require('events').defaultMaxListeners;

common.ArrayStream.prototype.write = () => {
};

const putIn = new common.ArrayStream();
const testMe = repl.start('', putIn);

// https://github.com/nodejs/node/issues/18284
// Tab-completion should not repeatedly add the
// `Runtime.executionContextCreated` listener
process.on('warning', common.mustNotCall());

putIn.run(['.clear']);
putIn.run(['async function test() {']);
for (let i = 0; i < DEFAULT_MAX_LISTENERS; i++) {
testMe.complete('await Promise.resolve()', () => {});
}

0 comments on commit 01398b2

Please sign in to comment.