Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
  • Loading branch information
aduh95 committed Feb 15, 2021
commit 708f04947100474790a3804ef703000f2b82ad9b
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