@@ -47,7 +47,10 @@ const GLOBAL_OBJECT_PROPERTIES = [
47
47
'ReferenceError' , 'SyntaxError' , 'TypeError' , 'URIError' , 'Math' , 'JSON'
48
48
] ;
49
49
const GLOBAL_OBJECT_PROPERTY_MAP = { } ;
50
- GLOBAL_OBJECT_PROPERTIES . forEach ( ( p ) => GLOBAL_OBJECT_PROPERTY_MAP [ p ] = p ) ;
50
+ for ( var n = 0 ; n < GLOBAL_OBJECT_PROPERTIES . length ; n ++ ) {
51
+ GLOBAL_OBJECT_PROPERTY_MAP [ GLOBAL_OBJECT_PROPERTIES [ n ] ] =
52
+ GLOBAL_OBJECT_PROPERTIES [ n ] ;
53
+ }
51
54
52
55
try {
53
56
// hack for require.resolve("./relative") to work properly.
@@ -692,13 +695,17 @@ REPLServer.prototype.createContext = function() {
692
695
enumerable : true ,
693
696
get : ( ) => _console
694
697
} ) ;
695
- Object . getOwnPropertyNames ( global ) . filter ( ( name ) => {
696
- if ( name === 'console' || name === 'global' ) return false ;
697
- return GLOBAL_OBJECT_PROPERTY_MAP [ name ] === undefined ;
698
- } ) . forEach ( ( name ) => {
699
- Object . defineProperty ( context , name ,
700
- Object . getOwnPropertyDescriptor ( global , name ) ) ;
701
- } ) ;
698
+
699
+ var names = Object . getOwnPropertyNames ( global ) ;
700
+ for ( var n = 0 ; n < names . length ; n ++ ) {
701
+ var name = names [ n ] ;
702
+ if ( name === 'console' || name === 'global' )
703
+ continue ;
704
+ if ( GLOBAL_OBJECT_PROPERTY_MAP [ name ] === undefined ) {
705
+ Object . defineProperty ( context , name ,
706
+ Object . getOwnPropertyDescriptor ( global , name ) ) ;
707
+ }
708
+ }
702
709
}
703
710
704
711
const module = new Module ( '<repl>' ) ;
@@ -769,10 +776,8 @@ function ArrayStream() {
769
776
Stream . call ( this ) ;
770
777
771
778
this . run = function ( data ) {
772
- var self = this ;
773
- data . forEach ( function ( line ) {
774
- self . emit ( 'data' , line + '\n' ) ;
775
- } ) ;
779
+ for ( var n = 0 ; n < data . length ; n ++ )
780
+ this . emit ( 'data' , `${ data [ n ] } \n` ) ;
776
781
} ;
777
782
}
778
783
util . inherits ( ArrayStream , Stream ) ;
@@ -816,11 +821,11 @@ function complete(line, callback) {
816
821
var tmp = this . lines . slice ( ) ;
817
822
// Kill off all function declarations to push all local variables into
818
823
// global scope
819
- this . lines . level . forEach ( function ( kill ) {
820
- if ( kill . isFunction ) {
824
+ for ( var n = 0 ; n < this . lines . level . length ; n ++ ) {
825
+ var kill = this . lines . level [ n ] ;
826
+ if ( kill . isFunction )
821
827
tmp [ kill . line ] = '' ;
822
- }
823
- } ) ;
828
+ }
824
829
var flat = new ArrayStream ( ) ; // make a new "input" stream
825
830
var magic = new REPLServer ( '' , flat ) ; // make a nested REPL
826
831
replMap . set ( magic , replMap . get ( this ) ) ;
@@ -954,9 +959,8 @@ function complete(line, callback) {
954
959
addStandardGlobals ( completionGroups , filter ) ;
955
960
} else if ( Array . isArray ( globals [ 0 ] ) ) {
956
961
// Add grouped globals
957
- globals . forEach ( function ( group ) {
958
- completionGroups . push ( group ) ;
959
- } ) ;
962
+ for ( var n = 0 ; n < globals . length ; n ++ )
963
+ completionGroups . push ( globals [ n ] ) ;
960
964
} else {
961
965
completionGroups . push ( globals ) ;
962
966
addStandardGlobals ( completionGroups , filter ) ;
@@ -1264,12 +1268,13 @@ function defineDefaultCommands(repl) {
1264
1268
( max , name ) => Math . max ( max , name . length ) ,
1265
1269
0
1266
1270
) ;
1267
- names . forEach ( ( name ) => {
1268
- const cmd = this . commands [ name ] ;
1269
- const spaces = ' ' . repeat ( longestNameLength - name . length + 3 ) ;
1270
- const line = '.' + name + ( cmd . help ? spaces + cmd . help : '' ) + '\n' ;
1271
+ for ( var n = 0 ; n < names . length ; n ++ ) {
1272
+ var name = names [ n ] ;
1273
+ var cmd = this . commands [ name ] ;
1274
+ var spaces = ' ' . repeat ( longestNameLength - name . length + 3 ) ;
1275
+ var line = `.${ name } ${ cmd . help ? spaces + cmd . help : '' } \n` ;
1271
1276
this . outputStream . write ( line ) ;
1272
- } ) ;
1277
+ }
1273
1278
this . displayPrompt ( ) ;
1274
1279
}
1275
1280
} ) ;
@@ -1293,15 +1298,13 @@ function defineDefaultCommands(repl) {
1293
1298
try {
1294
1299
var stats = fs . statSync ( file ) ;
1295
1300
if ( stats && stats . isFile ( ) ) {
1296
- var self = this ;
1297
1301
var data = fs . readFileSync ( file , 'utf8' ) ;
1298
1302
var lines = data . split ( '\n' ) ;
1299
1303
this . displayPrompt ( ) ;
1300
- lines . forEach ( function ( line ) {
1301
- if ( line ) {
1302
- self . write ( line + '\n' ) ;
1303
- }
1304
- } ) ;
1304
+ for ( var n = 0 ; n < lines . length ; n ++ ) {
1305
+ if ( lines [ n ] )
1306
+ this . write ( `${ lines [ n ] } \n` ) ;
1307
+ }
1305
1308
} else {
1306
1309
this . outputStream . write ( 'Failed to load:' + file +
1307
1310
' is not a valid file\n' ) ;
0 commit comments