Skip to content

Commit 2623154

Browse files
killaguBridgeAR
authored andcommitted
repl: fix tab-complete warning
When create a nest repl, will register `Runtime.executionContextCreated` listener to the inspector session.This patch will fix listener repeatedly register. PR-URL: nodejs#18881 Fixes: nodejs#18284 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 51be03c commit 2623154

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/repl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ REPLServer.prototype.createContext = function() {
753753
} else {
754754
sendInspectorCommand((session) => {
755755
session.post('Runtime.enable');
756-
session.on('Runtime.executionContextCreated', ({ params }) => {
756+
session.once('Runtime.executionContextCreated', ({ params }) => {
757757
this[kContextId] = params.context.id;
758758
});
759759
context = vm.createContext();
@@ -937,7 +937,6 @@ function complete(line, callback) {
937937
var flat = new ArrayStream(); // make a new "input" stream
938938
var magic = new REPLServer('', flat); // make a nested REPL
939939
replMap.set(magic, replMap.get(this));
940-
magic.resetContext();
941940
flat.run(tmp); // eval the flattened code
942941
// all this is only profitable if the nested REPL
943942
// does not have a bufferedCommand
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const repl = require('repl');
5+
const DEFAULT_MAX_LISTENERS = require('events').defaultMaxListeners;
6+
7+
common.ArrayStream.prototype.write = () => {
8+
};
9+
10+
const putIn = new common.ArrayStream();
11+
const testMe = repl.start('', putIn);
12+
13+
// https://github.com/nodejs/node/issues/18284
14+
// Tab-completion should not repeatedly add the
15+
// `Runtime.executionContextCreated` listener
16+
process.on('warning', common.mustNotCall());
17+
18+
putIn.run(['.clear']);
19+
putIn.run(['async function test() {']);
20+
for (let i = 0; i < DEFAULT_MAX_LISTENERS; i++) {
21+
testMe.complete('await Promise.resolve()', () => {});
22+
}

0 commit comments

Comments
 (0)