@@ -90,18 +90,6 @@ let processTopLevelAwait;
90
90
const parentModule = module ;
91
91
const replMap = new WeakMap ( ) ;
92
92
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
- }
105
93
const kBufferedCommandSymbol = Symbol ( 'bufferedCommand' ) ;
106
94
const kContextId = Symbol ( 'contextId' ) ;
107
95
@@ -806,24 +794,17 @@ REPLServer.prototype.createContext = function() {
806
794
} , ( ) => {
807
795
context = vm . createContext ( ) ;
808
796
} ) ;
797
+ for ( const name of Object . getOwnPropertyNames ( global ) ) {
798
+ Object . defineProperty ( context , name ,
799
+ Object . getOwnPropertyDescriptor ( global , name ) ) ;
800
+ }
809
801
context . global = context ;
810
802
const _console = new Console ( this . outputStream ) ;
811
803
Object . defineProperty ( context , 'console' , {
812
804
configurable : true ,
813
805
writable : true ,
814
806
value : _console
815
807
} ) ;
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
- }
827
808
}
828
809
829
810
var module = new CJSModule ( '<repl>' ) ;
@@ -1135,19 +1116,19 @@ function complete(line, callback) {
1135
1116
}
1136
1117
completionGroups . push (
1137
1118
filteredOwnPropertyNames . call ( this , this . context ) ) ;
1138
- addStandardGlobals ( completionGroups , filter ) ;
1119
+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
1139
1120
completionGroupsLoaded ( ) ;
1140
1121
} else {
1141
1122
this . eval ( '.scope' , this . context , 'repl' , function ev ( err , globals ) {
1142
1123
if ( err || ! Array . isArray ( globals ) ) {
1143
- addStandardGlobals ( completionGroups , filter ) ;
1124
+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
1144
1125
} else if ( Array . isArray ( globals [ 0 ] ) ) {
1145
1126
// Add grouped globals
1146
1127
for ( var n = 0 ; n < globals . length ; n ++ )
1147
1128
completionGroups . push ( globals [ n ] ) ;
1148
1129
} else {
1149
1130
completionGroups . push ( globals ) ;
1150
- addStandardGlobals ( completionGroups , filter ) ;
1131
+ if ( filter !== '' ) addCommonWords ( completionGroups ) ;
1151
1132
}
1152
1133
completionGroupsLoaded ( ) ;
1153
1134
} ) ;
@@ -1371,21 +1352,16 @@ function _memory(cmd) {
1371
1352
}
1372
1353
}
1373
1354
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
+ ] ) ;
1389
1365
}
1390
1366
1391
1367
function _turnOnEditorMode ( repl ) {
0 commit comments