summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2021-01-23 09:53:03 +0100
committerDarshan Sen <raisinten@gmail.com>2021-01-27 14:23:41 +0530
commit2e1e02a77aa6e86473ac9900b52eab1fbf247044 (patch)
treeab8fba2b817eacd2de41219fa417f92f1da55dd5
parentda3a9486a868949604557ffd0d7adf2d654d5b3f (diff)
downloadnode-new-2e1e02a77aa6e86473ac9900b52eab1fbf247044.tar.gz
lib: refactor to avoid unsafe array iteration
PR-URL: https://github.com/nodejs/node/pull/37029 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
-rw-r--r--lib/internal/process/per_thread.js28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js
index 4fdf0ba876..c5ec2609bc 100644
--- a/lib/internal/process/per_thread.js
+++ b/lib/internal/process/per_thread.js
@@ -5,6 +5,7 @@
// thread and the worker threads.
const {
+ ArrayPrototypeEvery,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSplice,
@@ -258,27 +259,24 @@ function buildAllowedFlags() {
const { options, aliases } = require('internal/options');
const allowedNodeEnvironmentFlags = [];
- for (const [name, info] of options) {
+ for (const { 0: name, 1: info } of options) {
if (info.envVarSettings === kAllowedInEnvironment) {
ArrayPrototypePush(allowedNodeEnvironmentFlags, name);
}
}
- for (const [ from, expansion ] of aliases) {
- let isAccepted = true;
- for (const to of expansion) {
- if (!StringPrototypeStartsWith(to, '-') || to === '--') continue;
- const recursiveExpansion = aliases.get(to);
- if (recursiveExpansion) {
- if (recursiveExpansion[0] === to)
- ArrayPrototypeSplice(recursiveExpansion, 0, 1);
- ArrayPrototypePush(expansion, ...recursiveExpansion);
- continue;
- }
- isAccepted = options.get(to).envVarSettings === kAllowedInEnvironment;
- if (!isAccepted) break;
+ function isAccepted(to) {
+ if (!StringPrototypeStartsWith(to, '-') || to === '--') return true;
+ const recursiveExpansion = aliases.get(to);
+ if (recursiveExpansion) {
+ if (recursiveExpansion[0] === to)
+ ArrayPrototypeSplice(recursiveExpansion, 0, 1);
+ return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
}
- if (isAccepted) {
+ return options.get(to).envVarSettings === kAllowedInEnvironment;
+ }
+ for (const { 0: from, 1: expansion } of aliases) {
+ if (ArrayPrototypeEvery(expansion, isAccepted)) {
let canonical = from;
if (StringPrototypeEndsWith(canonical, '='))
canonical = StringPrototypeSlice(canonical, 0, canonical.length - 1);