@@ -90,18 +90,6 @@ let processTopLevelAwait;
9090const parentModule = module ;
9191const replMap = new WeakMap ( ) ;
9292
93- const GLOBAL_OBJECT_PROPERTIES = [
94- 'NaN' , 'Infinity' , 'undefined' , 'eval' , 'parseInt' , 'parseFloat' , 'isNaN' ,
95- 'isFinite' , 'decodeURI' , 'decodeURIComponent' , 'encodeURI' ,
96- 'encodeURIComponent' , 'Object' , 'Function' , 'Array' , 'String' , 'Boolean' ,
97- 'Number' , 'Date' , 'RegExp' , 'Error' , 'EvalError' , 'RangeError' ,
98- 'ReferenceError' , 'SyntaxError' , 'TypeError' , 'URIError' , 'Math' , 'JSON'
99- ] ;
100- const GLOBAL_OBJECT_PROPERTY_MAP = { } ;
101- for ( var n = 0 ; n < GLOBAL_OBJECT_PROPERTIES . length ; n ++ ) {
102- GLOBAL_OBJECT_PROPERTY_MAP [ GLOBAL_OBJECT_PROPERTIES [ n ] ] =
103- GLOBAL_OBJECT_PROPERTIES [ n ] ;
104- }
10593const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
10694const kContextId = Symbol ( 'contextId' ) ;
10795
@@ -806,24 +794,17 @@ REPLServer.prototype.createContext = function() {
806794 } , ( ) => {
807795 context = vm . createContext ( ) ;
808796 } ) ;
797+ for ( const name of Object . getOwnPropertyNames ( global ) ) {
798+ Object . defineProperty ( context , name ,
799+ Object . getOwnPropertyDescriptor ( global , name ) ) ;
800+ }
809801 context . global = context ;
810802 const _console = new Console ( this . outputStream ) ;
811803 Object . defineProperty ( context , 'console' , {
812804 configurable : true ,
813805 writable : true ,
814806 value : _console
815807 } ) ;
816-
817- var names = Object . getOwnPropertyNames ( global ) ;
818- for ( var n = 0 ; n < names . length ; n ++ ) {
819- var name = names [ n ] ;
820- if ( name === 'console' || name === 'global' )
821- continue ;
822- if ( GLOBAL_OBJECT_PROPERTY_MAP [ name ] === undefined ) {
823- Object . defineProperty ( context , name ,
824- Object . getOwnPropertyDescriptor ( global , name ) ) ;
825- }
826- }
827808 }
828809
829810 var module = new CJSModule ( '<repl>' ) ;
@@ -1135,19 +1116,19 @@ function complete(line, callback) {
11351116 }
11361117 completionGroups . push (
11371118 filteredOwnPropertyNames . call ( this , this . context ) ) ;
1138- addStandardGlobals ( completionGroups , filter ) ;
1119+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
11391120 completionGroupsLoaded ( ) ;
11401121 } else {
11411122 this . eval ( '.scope' , this . context , 'repl' , function ev ( err , globals ) {
11421123 if ( err || ! Array . isArray ( globals ) ) {
1143- addStandardGlobals ( completionGroups , filter ) ;
1124+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
11441125 } else if ( Array . isArray ( globals [ 0 ] ) ) {
11451126 // Add grouped globals
11461127 for ( var n = 0 ; n < globals . length ; n ++ )
11471128 completionGroups . push ( globals [ n ] ) ;
11481129 } else {
11491130 completionGroups . push ( globals ) ;
1150- addStandardGlobals ( completionGroups , filter ) ;
1131+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
11511132 }
11521133 completionGroupsLoaded ( ) ;
11531134 } ) ;
@@ -1371,21 +1352,16 @@ function _memory(cmd) {
13711352 }
13721353}
13731354
1374- function addStandardGlobals ( completionGroups , filter ) {
1375- // Global object properties
1376- // (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
1377- completionGroups . push ( GLOBAL_OBJECT_PROPERTIES ) ;
1378- // Common keywords. Exclude for completion on the empty string, b/c
1379- // they just get in the way.
1380- if ( filter ) {
1381- completionGroups . push ( [
1382- 'async' , 'await' , 'break' , 'case' , 'catch' , 'const' , 'continue' ,
1383- 'debugger' , 'default' , 'delete' , 'do' , 'else' , 'export' , 'false' ,
1384- 'finally' , 'for' , 'function' , 'if' , 'import' , 'in' , 'instanceof' , 'let' ,
1385- 'new' , 'null' , 'return' , 'switch' , 'this' , 'throw' , 'true' , 'try' ,
1386- 'typeof' , 'undefined' , 'var' , 'void' , 'while' , 'with' , 'yield'
1387- ] ) ;
1388- }
1355+ function addCommonWords ( completionGroups ) {
1356+ // Only words which do not yet exist as global property should be added to
1357+ // this list.
1358+ completionGroups . push ( [
1359+ 'async' , 'await' , 'break' , 'case' , 'catch' , 'const' , 'continue' ,
1360+ 'debugger' , 'default' , 'delete' , 'do' , 'else' , 'export' , 'false' ,
1361+ 'finally' , 'for' , 'function' , 'if' , 'import' , 'in' , 'instanceof' , 'let' ,
1362+ 'new' , 'null' , 'return' , 'switch' , 'this' , 'throw' , 'true' , 'try' ,
1363+ 'typeof' , 'var' , 'void' , 'while' , 'with' , 'yield'
1364+ ] ) ;
13891365}
13901366
13911367function _turnOnEditorMode ( repl ) {
0 commit comments