Skip to content

Commit 0d5e324

Browse files
legendecasdanielleadams
authored andcommitted
src: clarify OptionEnvvarSettings member names
The term `Environment` in `kAllowedInEnvironment` and `kDisallowedInEnvironment` has nothing to do with the commonly used term `node::Environment`. Rename the member to `kAllowedInEnvvar` and `kDisallowedInEnvvar` respectively to reflect they are options of `OptionEnvvarSettings`. As `OptionEnvvarSettings` is part of the public embedder APIs, the legacy names are still preserved. PR-URL: #45057 Backport-PR-URL: #45994 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent e8b5a61 commit 0d5e324

File tree

7 files changed

+177
-162
lines changed

7 files changed

+177
-162
lines changed

lib/internal/process/per_thread.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@ const trailingValuesRegex = /=.*$/;
277277
// from data in the config binding.
278278
function buildAllowedFlags() {
279279
const {
280-
envSettings: { kAllowedInEnvironment },
280+
envSettings: { kAllowedInEnvvar },
281281
types: { kBoolean },
282282
} = internalBinding('options');
283283
const { options, aliases } = require('internal/options');
284284

285285
const allowedNodeEnvironmentFlags = [];
286286
for (const { 0: name, 1: info } of options) {
287-
if (info.envVarSettings === kAllowedInEnvironment) {
287+
if (info.envVarSettings === kAllowedInEnvvar) {
288288
ArrayPrototypePush(allowedNodeEnvironmentFlags, name);
289289
if (info.type === kBoolean) {
290290
const negatedName = `--no-${name.slice(2)}`;
@@ -301,7 +301,7 @@ function buildAllowedFlags() {
301301
ArrayPrototypeSplice(recursiveExpansion, 0, 1);
302302
return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
303303
}
304-
return options.get(to).envVarSettings === kAllowedInEnvironment;
304+
return options.get(to).envVarSettings === kAllowedInEnvvar;
305305
}
306306
for (const { 0: from, 1: expansion } of aliases) {
307307
if (ArrayPrototypeEvery(expansion, isAccepted)) {

src/node.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
817817
const int exit_code = ProcessGlobalArgs(&env_argv,
818818
nullptr,
819819
errors,
820-
kAllowedInEnvironment);
820+
kAllowedInEnvvar);
821821
if (exit_code != 0) return exit_code;
822822
}
823823
}
@@ -827,7 +827,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
827827
const int exit_code = ProcessGlobalArgs(argv,
828828
exec_argv,
829829
errors,
830-
kDisallowedInEnvironment);
830+
kDisallowedInEnvvar);
831831
if (exit_code != 0) return exit_code;
832832
}
833833

src/node.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,25 @@ inline std::unique_ptr<InitializationResult> InitializeOncePerProcess(
361361
}
362362

363363
enum OptionEnvvarSettings {
364-
kAllowedInEnvironment,
365-
kDisallowedInEnvironment
364+
// Allow the options to be set via the environment variable, like
365+
// `NODE_OPTIONS`.
366+
kAllowedInEnvvar = 0,
367+
// Disallow the options to be set via the environment variable, like
368+
// `NODE_OPTIONS`.
369+
kDisallowedInEnvvar = 1,
370+
// Deprecated, use kAllowedInEnvvar instead.
371+
kAllowedInEnvironment = kAllowedInEnvvar,
372+
// Deprecated, use kDisallowedInEnvvar instead.
373+
kDisallowedInEnvironment = kDisallowedInEnvvar,
366374
};
367375

376+
// Process the arguments and set up the per-process options.
377+
// If the `settings` is set as OptionEnvvarSettings::kAllowedInEnvvar, the
378+
// options that are allowed in the environment variable are processed. Options
379+
// that are disallowed to be set via environment variable are processed as
380+
// errors.
381+
// Otherwise all the options that are disallowed (and those are allowed) to be
382+
// set via environment variable are processed.
368383
NODE_EXTERN int ProcessGlobalArgs(std::vector<std::string>* args,
369384
std::vector<std::string>* exec_args,
370385
std::vector<std::string>* errors,

src/node_options-inl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void OptionsParser<Options>::Parse(
302302
const std::string arg = args.pop_first();
303303

304304
if (arg == "--") {
305-
if (required_env_settings == kAllowedInEnvironment)
305+
if (required_env_settings == kAllowedInEnvvar)
306306
errors->push_back(NotAllowedInEnvErr("--"));
307307
break;
308308
}
@@ -374,8 +374,8 @@ void OptionsParser<Options>::Parse(
374374
auto it = options_.find(name);
375375

376376
if ((it == options_.end() ||
377-
it->second.env_setting == kDisallowedInEnvironment) &&
378-
required_env_settings == kAllowedInEnvironment) {
377+
it->second.env_setting == kDisallowedInEnvvar) &&
378+
required_env_settings == kAllowedInEnvvar) {
379379
errors->push_back(NotAllowedInEnvErr(original_name));
380380
break;
381381
}

0 commit comments

Comments
 (0)