Skip to content
Closed
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
10 changes: 5 additions & 5 deletions lib/internal/options.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
37 changes: 19 additions & 18 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

const {
ArrayIsArray,
ArrayPrototypeEvery,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSplice,
BigUint64Array,
Float64Array,
MapPrototypeForEach,
MapPrototypeGet,
NumberMAX_SAFE_INTEGER,
ObjectDefineProperty,
ObjectFreeze,
Expand Down Expand Up @@ -257,35 +260,33 @@ 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) {
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 = MapPrototypeGet(aliases, to);
if (recursiveExpansion) {
if (recursiveExpansion[0] === to)
ArrayPrototypeSplice(recursiveExpansion, 0, 1);
return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
}
if (isAccepted) {
return MapPrototypeGet(options, to).envVarSettings ===
kAllowedInEnvironment;
}
MapPrototypeForEach(aliases, (expansion, from) => {
if (ArrayPrototypeEvery(expansion, isAccepted)) {
let canonical = from;
if (StringPrototypeEndsWith(canonical, '='))
canonical = StringPrototypeSlice(canonical, 0, canonical.length - 1);
if (StringPrototypeEndsWith(canonical, ' <arg>'))
canonical = StringPrototypeSlice(canonical, 0, canonical.length - 4);
ArrayPrototypePush(allowedNodeEnvironmentFlags, canonical);
}
}
});

const trimLeadingDashes =
(flag) => StringPrototypeReplace(flag, leadingDashesRegex, '');
Expand Down