Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: fix tab-complete warning #18881

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,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 @@ -937,7 +937,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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resetContext have called in constructor,so it should be deleted.

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()', () => {});
}