diff --git a/lib/repl.js b/lib/repl.js index 72fd37e0a4a08f..c73a5069bbe181 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -47,7 +47,10 @@ const GLOBAL_OBJECT_PROPERTIES = [ 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', 'Math', 'JSON' ]; const GLOBAL_OBJECT_PROPERTY_MAP = {}; -GLOBAL_OBJECT_PROPERTIES.forEach((p) => GLOBAL_OBJECT_PROPERTY_MAP[p] = p); +for (var n = 0; n < GLOBAL_OBJECT_PROPERTIES.length; n++) { + GLOBAL_OBJECT_PROPERTY_MAP[GLOBAL_OBJECT_PROPERTIES[n]] = + GLOBAL_OBJECT_PROPERTIES[n]; +} try { // hack for require.resolve("./relative") to work properly. @@ -692,13 +695,17 @@ REPLServer.prototype.createContext = function() { enumerable: true, get: () => _console }); - Object.getOwnPropertyNames(global).filter((name) => { - if (name === 'console' || name === 'global') return false; - return GLOBAL_OBJECT_PROPERTY_MAP[name] === undefined; - }).forEach((name) => { - Object.defineProperty(context, name, - Object.getOwnPropertyDescriptor(global, name)); - }); + + var names = Object.getOwnPropertyNames(global); + for (var n = 0; n < names.length; n++) { + var name = names[n]; + if (name === 'console' || name === 'global') + continue; + if (GLOBAL_OBJECT_PROPERTY_MAP[name] === undefined) { + Object.defineProperty(context, name, + Object.getOwnPropertyDescriptor(global, name)); + } + } } const module = new Module(''); @@ -769,10 +776,8 @@ function ArrayStream() { Stream.call(this); this.run = function(data) { - var self = this; - data.forEach(function(line) { - self.emit('data', line + '\n'); - }); + for (var n = 0; n < data.length; n++) + this.emit('data', `${data[n]}\n`); }; } util.inherits(ArrayStream, Stream); @@ -816,11 +821,11 @@ function complete(line, callback) { var tmp = this.lines.slice(); // Kill off all function declarations to push all local variables into // global scope - this.lines.level.forEach(function(kill) { - if (kill.isFunction) { + for (var n = 0; n < this.lines.level.length; n++) { + var kill = this.lines.level[n]; + if (kill.isFunction) tmp[kill.line] = ''; - } - }); + } var flat = new ArrayStream(); // make a new "input" stream var magic = new REPLServer('', flat); // make a nested REPL replMap.set(magic, replMap.get(this)); @@ -954,9 +959,8 @@ function complete(line, callback) { addStandardGlobals(completionGroups, filter); } else if (Array.isArray(globals[0])) { // Add grouped globals - globals.forEach(function(group) { - completionGroups.push(group); - }); + for (var n = 0; n < globals.length; n++) + completionGroups.push(globals[n]); } else { completionGroups.push(globals); addStandardGlobals(completionGroups, filter); @@ -1264,12 +1268,13 @@ function defineDefaultCommands(repl) { (max, name) => Math.max(max, name.length), 0 ); - names.forEach((name) => { - const cmd = this.commands[name]; - const spaces = ' '.repeat(longestNameLength - name.length + 3); - const line = '.' + name + (cmd.help ? spaces + cmd.help : '') + '\n'; + for (var n = 0; n < names.length; n++) { + var name = names[n]; + var cmd = this.commands[name]; + var spaces = ' '.repeat(longestNameLength - name.length + 3); + var line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`; this.outputStream.write(line); - }); + } this.displayPrompt(); } }); @@ -1293,15 +1298,13 @@ function defineDefaultCommands(repl) { try { var stats = fs.statSync(file); if (stats && stats.isFile()) { - var self = this; var data = fs.readFileSync(file, 'utf8'); var lines = data.split('\n'); this.displayPrompt(); - lines.forEach(function(line) { - if (line) { - self.write(line + '\n'); - } - }); + for (var n = 0; n < lines.length; n++) { + if (lines[n]) + this.write(`${lines[n]}\n`); + } } else { this.outputStream.write('Failed to load:' + file + ' is not a valid file\n');