@@ -109,6 +109,19 @@ const kContextId = Symbol('contextId');
109
109
110
110
let addedNewListener = false ;
111
111
112
+ const GLOBAL_OBJECT_PROPERTIES = [
113
+ 'NaN' , 'Infinity' , 'undefined' , 'eval' , 'parseInt' , 'parseFloat' , 'isNaN' ,
114
+ 'isFinite' , 'decodeURI' , 'decodeURIComponent' , 'encodeURI' ,
115
+ 'encodeURIComponent' , 'Object' , 'Function' , 'Array' , 'String' , 'Boolean' ,
116
+ 'Number' , 'Date' , 'RegExp' , 'Error' , 'EvalError' , 'RangeError' ,
117
+ 'ReferenceError' , 'SyntaxError' , 'TypeError' , 'URIError' , 'Math' , 'JSON'
118
+ ] ;
119
+ const GLOBAL_OBJECT_PROPERTY_MAP = { } ;
120
+ for ( var n = 0 ; n < GLOBAL_OBJECT_PROPERTIES . length ; n ++ ) {
121
+ GLOBAL_OBJECT_PROPERTY_MAP [ GLOBAL_OBJECT_PROPERTIES [ n ] ] =
122
+ GLOBAL_OBJECT_PROPERTIES [ n ] ;
123
+ }
124
+
112
125
try {
113
126
// Hack for require.resolve("./relative") to work properly.
114
127
module . filename = path . resolve ( 'repl' ) ;
@@ -874,17 +887,22 @@ REPLServer.prototype.createContext = function() {
874
887
} , ( ) => {
875
888
context = vm . createContext ( ) ;
876
889
} ) ;
877
- for ( const name of Object . getOwnPropertyNames ( global ) ) {
878
- Object . defineProperty ( context , name ,
879
- Object . getOwnPropertyDescriptor ( global , name ) ) ;
880
- }
881
890
context . global = context ;
882
891
const _console = new Console ( this . outputStream ) ;
883
892
Object . defineProperty ( context , 'console' , {
884
893
configurable : true ,
885
894
writable : true ,
886
895
value : _console
887
896
} ) ;
897
+
898
+ for ( const name of Object . getOwnPropertyNames ( global ) ) {
899
+ if ( name === 'console' || name === 'global' )
900
+ continue ;
901
+ if ( GLOBAL_OBJECT_PROPERTY_MAP [ name ] === undefined ) {
902
+ Object . defineProperty ( context , name ,
903
+ Object . getOwnPropertyDescriptor ( global , name ) ) ;
904
+ }
905
+ }
888
906
}
889
907
890
908
const module = new CJSModule ( '<repl>' ) ;
@@ -1455,6 +1473,10 @@ function _memory(cmd) {
1455
1473
}
1456
1474
1457
1475
function addCommonWords ( completionGroups ) {
1476
+ // Global object properties
1477
+ // (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
1478
+ completionGroups . push ( GLOBAL_OBJECT_PROPERTIES ) ;
1479
+
1458
1480
// Only words which do not yet exist as global property should be added to
1459
1481
// this list.
1460
1482
completionGroups . push ( [
0 commit comments