diff --git a/lib/repl.js b/lib/repl.js index 605ea437870b38..75a96897d58f3c 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -43,7 +43,6 @@ 'use strict'; const { - ArrayIsArray, Error, MathMax, NumberIsNaN, @@ -1291,40 +1290,23 @@ function complete(line, callback) { // Resolve expr and get its completions. const memberGroups = []; if (!expr) { - // If context is instance of vm.ScriptContext // Get global vars synchronously - if (this.useGlobal || vm.isContext(this.context)) { - completionGroups.push(getGlobalLexicalScopeNames(this[kContextId])); - let contextProto = this.context; - while (contextProto = ObjectGetPrototypeOf(contextProto)) { - completionGroups.push( - filteredOwnPropertyNames.call(this, contextProto)); - } - const contextOwnNames = - filteredOwnPropertyNames.call(this, this.context); - if (!this.useGlobal) { - // When the context is not `global`, builtins are not own - // properties of it. - contextOwnNames.push(...globalBuiltins); - } - completionGroups.push(contextOwnNames); - if (filter !== '') addCommonWords(completionGroups); - completionGroupsLoaded(); - } else { - this.eval('.scope', this.context, 'repl', function ev(err, globals) { - if (err || !ArrayIsArray(globals)) { - if (filter !== '') addCommonWords(completionGroups); - } else if (ArrayIsArray(globals[0])) { - // Add grouped globals - for (let n = 0; n < globals.length; n++) - completionGroups.push(globals[n]); - } else { - completionGroups.push(globals); - if (filter !== '') addCommonWords(completionGroups); - } - completionGroupsLoaded(); - }); + completionGroups.push(getGlobalLexicalScopeNames(this[kContextId])); + let contextProto = this.context; + while (contextProto = ObjectGetPrototypeOf(contextProto)) { + completionGroups.push( + filteredOwnPropertyNames.call(this, contextProto)); + } + const contextOwnNames = + filteredOwnPropertyNames.call(this, this.context); + if (!this.useGlobal) { + // When the context is not `global`, builtins are not own + // properties of it. + contextOwnNames.push(...globalBuiltins); } + completionGroups.push(contextOwnNames); + if (filter !== '') addCommonWords(completionGroups); + completionGroupsLoaded(); } else { const evalExpr = `try { ${expr} } catch {}`; this.eval(evalExpr, this.context, 'repl', (e, obj) => { diff --git a/test/parallel/test-repl-eval-scope.js b/test/parallel/test-repl-eval-scope.js deleted file mode 100644 index 702b6056f101a5..00000000000000 --- a/test/parallel/test-repl-eval-scope.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; -const common = require('../common'); -const ArrayStream = require('../common/arraystream'); -const assert = require('assert'); -const repl = require('repl'); - -{ - const stream = new ArrayStream(); - const options = { - eval: common.mustCall((cmd, context) => { - assert.strictEqual(cmd, '.scope\n'); - assert.deepStrictEqual(context, { animal: 'Sterrance' }); - }), - input: stream, - output: stream, - terminal: true - }; - - const r = repl.start(options); - r.context = { animal: 'Sterrance' }; - - stream.emit('data', '\t'); - stream.emit('.exit\n'); -}