Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: refactor to avoid unsafe array iteration #36444

Closed
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b81f448
lib: refactor to remove for-let-of loop in repl.js
RaisinTen Dec 8, 2020
f5d6c33
Apply suggestion from code review
RaisinTen Dec 10, 2020
b6b3c5b
lib: require ArrayPrototypeForEach in repl.js
RaisinTen Dec 10, 2020
0a167a1
lib: fix syntax error repl.js
RaisinTen Dec 10, 2020
3a9491e
lib: replace another loop repl.js
RaisinTen Dec 10, 2020
846ac65
lib: fix lint error repl.js
RaisinTen Dec 10, 2020
9367f9b
Apply suggestions from code review
RaisinTen Dec 11, 2020
61cb3b7
lib: replace all for loops with ArrayPrototypeForEach in repl.js
RaisinTen Dec 11, 2020
10c1759
lib: fix syntax error repl.js
RaisinTen Dec 11, 2020
669f93e
lib: fix lint error
RaisinTen Dec 11, 2020
dc678b0
lib: replace ArrayPrototypeSort with ArrayPrototypeForEach in repl.js
RaisinTen Dec 16, 2020
ddfbfc4
test: add unsafe array iteration test to repl
RaisinTen Dec 18, 2020
77a6be5
test: add notStrictEqual check instead for repl.js
RaisinTen Dec 18, 2020
6c19991
Update test/parallel/test-repl-unsafe-array-iteration.js
RaisinTen Dec 18, 2020
ccc860a
test: add test using child_process instead
RaisinTen Dec 19, 2020
81776d6
test: remove error code check
RaisinTen Dec 19, 2020
a45f1ed
Update test/parallel/test-repl-unsafe-array-iteration.js
RaisinTen Dec 19, 2020
c61b0b9
Update test/parallel/test-repl-unsafe-array-iteration.js
RaisinTen Dec 19, 2020
71350bd
Update test/parallel/test-repl-unsafe-array-iteration.js
RaisinTen Dec 20, 2020
1ec7036
Update test/parallel/test-repl-unsafe-array-iteration.js
RaisinTen Dec 21, 2020
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
9 changes: 5 additions & 4 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const {
ArrayPrototypeConcat,
ArrayPrototypeFilter,
ArrayPrototypeFindIndex,
ArrayPrototypeForEach,
ArrayPrototypeIncludes,
ArrayPrototypeJoin,
ArrayPrototypeMap,
Expand Down Expand Up @@ -662,7 +663,7 @@ function REPLServer(prompt,
let matched = false;

errStack = '';
for (const line of lines) {
ArrayPrototypePush(lines, (line) => {
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
if (!matched &&
RegExpPrototypeTest(/^\[?([A-Z][a-z0-9_]*)*Error/, line)) {
errStack += writer.options.breakLength >= line.length ?
Expand All @@ -672,7 +673,7 @@ function REPLServer(prompt,
} else {
errStack += line;
}
}
});
if (!matched) {
const ln = lines.length === 1 ? ' ' : ':\n';
errStack = `Uncaught${ln}${errStack}`;
Expand Down Expand Up @@ -1229,7 +1230,7 @@ function complete(line, callback) {
paths = ArrayPrototypeConcat(module.paths, CJSModule.globalPaths);
}

for (let dir of paths) {
ArrayPrototypeForEach(paths, (dir) => {
dir = path.resolve(dir, subdir);
const dirents = gracefulReaddir(dir, { withFileTypes: true }) || [];
for (const dirent of dirents) {
Expand Down Expand Up @@ -1257,7 +1258,7 @@ function complete(line, callback) {
}
}
}
}
});
if (group.length) {
ArrayPrototypePush(completionGroups, group);
}
Expand Down