Skip to content

Commit 6d53e79

Browse files
aduh95danielleadams
authored andcommitted
repl: refactor to avoid unsafe array iteration
PR-URL: #37345 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 799b2d5 commit 6d53e79

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/internal/repl/await.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ArrayFrom,
5+
ArrayPrototypeForEach,
56
ArrayPrototypeJoin,
67
ArrayPrototypePop,
78
ArrayPrototypePush,
@@ -61,10 +62,10 @@ const visitorsWithoutAncestors = {
6162
state.replace(node.start, node.start + node.kind.length, 'void (');
6263
}
6364

64-
for (const decl of node.declarations) {
65+
ArrayPrototypeForEach(node.declarations, (decl) => {
6566
state.prepend(decl, '(');
6667
state.append(decl, decl.init ? ')' : '=undefined)');
67-
}
68+
});
6869

6970
if (node.declarations.length !== 1) {
7071
state.append(node.declarations[node.declarations.length - 1], ')');

lib/internal/repl/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ function isRecoverableError(e, code) {
103103
staticClassFeatures,
104104
(Parser) => {
105105
return class extends Parser {
106+
// eslint-disable-next-line no-useless-constructor
107+
constructor(options, input, startPos) {
108+
super(options, input, startPos);
109+
}
106110
nextToken() {
107111
super.nextToken();
108112
if (this.type === tt.eof)

lib/repl.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const {
6262
Boolean,
6363
Error,
6464
FunctionPrototypeBind,
65-
MathMax,
65+
MathMaxApply,
6666
NumberIsNaN,
6767
NumberParseFloat,
6868
ObjectAssign,
@@ -1647,8 +1647,8 @@ function defineDefaultCommands(repl) {
16471647
help: 'Print this help message',
16481648
action: function() {
16491649
const names = ArrayPrototypeSort(ObjectKeys(this.commands));
1650-
const longestNameLength = MathMax(
1651-
...ArrayPrototypeMap(names, (name) => name.length)
1650+
const longestNameLength = MathMaxApply(
1651+
ArrayPrototypeMap(names, (name) => name.length)
16521652
);
16531653
ArrayPrototypeForEach(names, (name) => {
16541654
const cmd = this.commands[name];

0 commit comments

Comments
 (0)