@@ -58,6 +58,7 @@ const Module = require('module');
58
58
const domain = require ( 'domain' ) ;
59
59
const debug = util . debuglog ( 'repl' ) ;
60
60
const errors = require ( 'internal/errors' ) ;
61
+ const { sendInspectorCommand } = require ( 'internal/util/inspector' ) ;
61
62
62
63
const parentModule = module ;
63
64
const replMap = new WeakMap ( ) ;
@@ -75,6 +76,7 @@ for (var n = 0; n < GLOBAL_OBJECT_PROPERTIES.length; n++) {
75
76
GLOBAL_OBJECT_PROPERTIES [ n ] ;
76
77
}
77
78
const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
79
+ const kContextId = Symbol ( 'contextId' ) ;
78
80
79
81
try {
80
82
// hack for require.resolve("./relative") to work properly.
@@ -155,6 +157,8 @@ function REPLServer(prompt,
155
157
self . last = undefined ;
156
158
self . breakEvalOnSigint = ! ! breakEvalOnSigint ;
157
159
self . editorMode = false ;
160
+ // Context id for use with the inspector protocol.
161
+ self [ kContextId ] = undefined ;
158
162
159
163
// just for backwards compat, see github.com/joyent/node/pull/7127
160
164
self . rli = this ;
@@ -644,7 +648,16 @@ REPLServer.prototype.createContext = function() {
644
648
if ( this . useGlobal ) {
645
649
context = global ;
646
650
} else {
647
- context = vm . createContext ( ) ;
651
+ sendInspectorCommand ( ( session ) => {
652
+ session . post ( 'Runtime.enable' ) ;
653
+ session . on ( 'Runtime.executionContextCreated' , ( { params } ) => {
654
+ this [ kContextId ] = params . context . id ;
655
+ } ) ;
656
+ context = vm . createContext ( ) ;
657
+ session . post ( 'Runtime.disable' ) ;
658
+ } , ( ) => {
659
+ context = vm . createContext ( ) ;
660
+ } ) ;
648
661
context . global = context ;
649
662
const _console = new Console ( this . outputStream ) ;
650
663
Object . defineProperty ( context , 'console' , {
@@ -779,6 +792,18 @@ function filteredOwnPropertyNames(obj) {
779
792
return Object . getOwnPropertyNames ( obj ) . filter ( intFilter ) ;
780
793
}
781
794
795
+ function getGlobalLexicalScopeNames ( contextId ) {
796
+ return sendInspectorCommand ( ( session ) => {
797
+ let names = [ ] ;
798
+ session . post ( 'Runtime.globalLexicalScopeNames' , {
799
+ executionContextId : contextId
800
+ } , ( error , result ) => {
801
+ if ( ! error ) names = result . names ;
802
+ } ) ;
803
+ return names ;
804
+ } , ( ) => [ ] ) ;
805
+ }
806
+
782
807
REPLServer . prototype . complete = function ( ) {
783
808
this . completer . apply ( this , arguments ) ;
784
809
} ;
@@ -942,6 +967,7 @@ function complete(line, callback) {
942
967
// If context is instance of vm.ScriptContext
943
968
// Get global vars synchronously
944
969
if ( this . useGlobal || vm . isContext ( this . context ) ) {
970
+ completionGroups . push ( getGlobalLexicalScopeNames ( this [ kContextId ] ) ) ;
945
971
var contextProto = this . context ;
946
972
while ( contextProto = Object . getPrototypeOf ( contextProto ) ) {
947
973
completionGroups . push (
0 commit comments