Skip to content

Commit

Permalink
repl: refactor to avoid unsafe array iteration
Browse files Browse the repository at this point in the history
PR-URL: #37345
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 committed Feb 15, 2021
1 parent f24e707 commit 708f049
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/internal/repl/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const {
ArrayFrom,
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypePop,
ArrayPrototypePush,
Expand Down Expand Up @@ -61,10 +62,10 @@ const visitorsWithoutAncestors = {
state.replace(node.start, node.start + node.kind.length, 'void (');
}

for (const decl of node.declarations) {
ArrayPrototypeForEach(node.declarations, (decl) => {
state.prepend(decl, '(');
state.append(decl, decl.init ? ')' : '=undefined)');
}
});

if (node.declarations.length !== 1) {
state.append(node.declarations[node.declarations.length - 1], ')');
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function isRecoverableError(e, code) {
staticClassFeatures,
(Parser) => {
return class extends Parser {
// eslint-disable-next-line no-useless-constructor
constructor(options, input, startPos) {
super(options, input, startPos);
}
nextToken() {
super.nextToken();
if (this.type === tt.eof)
Expand Down
6 changes: 3 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const {
Boolean,
Error,
FunctionPrototypeBind,
MathMax,
MathMaxApply,
NumberIsNaN,
NumberParseFloat,
ObjectAssign,
Expand Down Expand Up @@ -1647,8 +1647,8 @@ function defineDefaultCommands(repl) {
help: 'Print this help message',
action: function() {
const names = ArrayPrototypeSort(ObjectKeys(this.commands));
const longestNameLength = MathMax(
...ArrayPrototypeMap(names, (name) => name.length)
const longestNameLength = MathMaxApply(
ArrayPrototypeMap(names, (name) => name.length)
);
ArrayPrototypeForEach(names, (name) => {
const cmd = this.commands[name];
Expand Down

0 comments on commit 708f049

Please sign in to comment.