Skip to content

Commit 01398b2

Browse files
killaguaddaleax
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: #18881 Fixes: #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 edba129 commit 01398b2

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
@@ -650,7 +650,7 @@ REPLServer.prototype.createContext = function() {
650650
} else {
651651
sendInspectorCommand((session) => {
652652
session.post('Runtime.enable');
653-
session.on('Runtime.executionContextCreated', ({ params }) => {
653+
session.once('Runtime.executionContextCreated', ({ params }) => {
654654
this[kContextId] = params.context.id;
655655
});
656656
context = vm.createContext();
@@ -834,7 +834,6 @@ function complete(line, callback) {
834834
var flat = new ArrayStream(); // make a new "input" stream
835835
var magic = new REPLServer('', flat); // make a nested REPL
836836
replMap.set(magic, replMap.get(this));
837-
magic.resetContext();
838837
flat.run(tmp); // eval the flattened code
839838
// all this is only profitable if the nested REPL
840839
// 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)