From 6a36c0b7002d9d575e7580a3c1834daf01e19b0c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 28 Dec 2020 00:39:03 +0100 Subject: [PATCH 1/3] lib: replace public Map methods with primordials --- lib/internal/options.js | 10 +++++----- lib/internal/process/per_thread.js | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/internal/options.js b/lib/internal/options.js index 10c6aa2d9a0978..6d4fb68e52854d 100644 --- a/lib/internal/options.js +++ b/lib/internal/options.js @@ -1,16 +1,16 @@ 'use strict'; +const { + MapPrototypeGet, +} = primordials; + const { getOptions, shouldNotRegisterESMLoader } = internalBinding('options'); const { options, aliases } = getOptions(); let warnOnAllowUnauthorized = true; function getOptionValue(option) { - const result = options.get(option); - if (!result) { - return undefined; - } - return result.value; + return MapPrototypeGet(options, option)?.value; } function getAllowUnauthorized() { diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index b16705f9fb95b0..0d77511a16016c 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -6,11 +6,14 @@ const { ArrayIsArray, + ArrayPrototypeForEach, ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeSplice, BigUint64Array, Float64Array, + MapPrototypeForEach, + MapPrototypeGet, NumberMAX_SAFE_INTEGER, ObjectDefineProperty, ObjectFreeze, @@ -257,26 +260,27 @@ function buildAllowedFlags() { const { options, aliases } = require('internal/options'); const allowedNodeEnvironmentFlags = []; - for (const [name, info] of options) { + MapPrototypeForEach(options, (info, name) => { if (info.envVarSettings === kAllowedInEnvironment) { ArrayPrototypePush(allowedNodeEnvironmentFlags, name); } - } + }); - for (const [ from, expansion ] of aliases) { + MapPrototypeForEach(aliases, (expansion, from) => { let isAccepted = true; - for (const to of expansion) { - if (!StringPrototypeStartsWith(to, '-') || to === '--') continue; - const recursiveExpansion = aliases.get(to); + ArrayPrototypeForEach(expansion, (to) => { + if (!isAccepted || !StringPrototypeStartsWith(to, '-') || to === '--') + return; + const recursiveExpansion = MapPrototypeGet(aliases, to); if (recursiveExpansion) { if (recursiveExpansion[0] === to) ArrayPrototypeSplice(recursiveExpansion, 0, 1); ArrayPrototypePush(expansion, ...recursiveExpansion); - continue; + return; } - isAccepted = options.get(to).envVarSettings === kAllowedInEnvironment; - if (!isAccepted) break; - } + isAccepted = + MapPrototypeGet(options, to).envVarSettings === kAllowedInEnvironment; + }); if (isAccepted) { let canonical = from; if (StringPrototypeEndsWith(canonical, '=')) @@ -285,7 +289,7 @@ function buildAllowedFlags() { canonical = StringPrototypeSlice(canonical, 0, canonical.length - 4); ArrayPrototypePush(allowedNodeEnvironmentFlags, canonical); } - } + }); const trimLeadingDashes = (flag) => StringPrototypeReplace(flag, leadingDashesRegex, ''); From 41ede60dd186cf5885191c8f36721c9137fe1940 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 28 Dec 2020 11:37:33 +0100 Subject: [PATCH 2/3] fixup! lib: replace public Map methods with primordials --- lib/internal/process/per_thread.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 0d77511a16016c..62d9fa54d261ce 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -6,7 +6,7 @@ const { ArrayIsArray, - ArrayPrototypeForEach, + ArrayPrototypeEvery, ArrayPrototypeMap, ArrayPrototypePush, ArrayPrototypeSplice, @@ -267,21 +267,18 @@ function buildAllowedFlags() { }); MapPrototypeForEach(aliases, (expansion, from) => { - let isAccepted = true; - ArrayPrototypeForEach(expansion, (to) => { - if (!isAccepted || !StringPrototypeStartsWith(to, '-') || to === '--') - return; + function isAccepted(to) { + if (!StringPrototypeStartsWith(to, '-') || to === '--') return true; const recursiveExpansion = MapPrototypeGet(aliases, to); if (recursiveExpansion) { if (recursiveExpansion[0] === to) ArrayPrototypeSplice(recursiveExpansion, 0, 1); - ArrayPrototypePush(expansion, ...recursiveExpansion); - return; + return ArrayPrototypeEvery(recursiveExpansion, isAccepted); } - isAccepted = - MapPrototypeGet(options, to).envVarSettings === kAllowedInEnvironment; - }); - if (isAccepted) { + return MapPrototypeGet(options, to).envVarSettings === + kAllowedInEnvironment; + } + if (ArrayPrototypeEvery(expansion, isAccepted)) { let canonical = from; if (StringPrototypeEndsWith(canonical, '=')) canonical = StringPrototypeSlice(canonical, 0, canonical.length - 1); From b8198cfccbe3cc762ce22a7d49b8964cef6df6fc Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 14 Jan 2021 11:13:03 +0100 Subject: [PATCH 3/3] fixup! lib: replace public Map methods with primordials --- lib/internal/process/per_thread.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 62d9fa54d261ce..c7449bead6de57 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -266,18 +266,18 @@ function buildAllowedFlags() { } }); - MapPrototypeForEach(aliases, (expansion, from) => { - function isAccepted(to) { - if (!StringPrototypeStartsWith(to, '-') || to === '--') return true; - const recursiveExpansion = MapPrototypeGet(aliases, to); - if (recursiveExpansion) { - if (recursiveExpansion[0] === to) - ArrayPrototypeSplice(recursiveExpansion, 0, 1); - return ArrayPrototypeEvery(recursiveExpansion, isAccepted); - } - return MapPrototypeGet(options, to).envVarSettings === - kAllowedInEnvironment; + function isAccepted(to) { + if (!StringPrototypeStartsWith(to, '-') || to === '--') return true; + const recursiveExpansion = MapPrototypeGet(aliases, to); + if (recursiveExpansion) { + if (recursiveExpansion[0] === to) + ArrayPrototypeSplice(recursiveExpansion, 0, 1); + return ArrayPrototypeEvery(recursiveExpansion, isAccepted); } + return MapPrototypeGet(options, to).envVarSettings === + kAllowedInEnvironment; + } + MapPrototypeForEach(aliases, (expansion, from) => { if (ArrayPrototypeEvery(expansion, isAccepted)) { let canonical = from; if (StringPrototypeEndsWith(canonical, '='))