Skip to content

Commit cb039c2

Browse files
committed
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.
1 parent 6bdc101 commit cb039c2

File tree

7 files changed

+175
-165
lines changed

7 files changed

+175
-165
lines changed

lib/internal/process/per_thread.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ const trailingValuesRegex = /=.*$/;
267267
// from data in the config binding.
268268
function buildAllowedFlags() {
269269
const {
270-
envSettings: { kAllowedInEnvironment },
270+
envSettings: { kAllowedInEnvvar },
271271
types: { kBoolean },
272272
} = internalBinding('options');
273273
const { options, aliases } = require('internal/options');
274274

275275
const allowedNodeEnvironmentFlags = [];
276276
for (const { 0: name, 1: info } of options) {
277-
if (info.envVarSettings === kAllowedInEnvironment) {
277+
if (info.envVarSettings === kAllowedInEnvvar) {
278278
ArrayPrototypePush(allowedNodeEnvironmentFlags, name);
279279
if (info.type === kBoolean) {
280280
const negatedName = `--no-${name.slice(2)}`;
@@ -291,7 +291,7 @@ function buildAllowedFlags() {
291291
ArrayPrototypeSplice(recursiveExpansion, 0, 1);
292292
return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
293293
}
294-
return options.get(to).envVarSettings === kAllowedInEnvironment;
294+
return options.get(to).envVarSettings === kAllowedInEnvvar;
295295
}
296296
for (const { 0: from, 1: expansion } of aliases) {
297297
if (ArrayPrototypeEvery(expansion, isAccepted)) {

src/node.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ static ExitCode InitializeNodeWithArgsInternal(
769769
env_argv.insert(env_argv.begin(), argv->at(0));
770770

771771
const ExitCode exit_code = ProcessGlobalArgsInternal(
772-
&env_argv, nullptr, errors, kAllowedInEnvironment);
772+
&env_argv, nullptr, errors, kAllowedInEnvvar);
773773
if (exit_code != ExitCode::kNoFailure) return exit_code;
774774
}
775775
}
776776
#endif
777777

778778
if (!(flags & ProcessInitializationFlags::kDisableCLIOptions)) {
779-
const ExitCode exit_code = ProcessGlobalArgsInternal(
780-
argv, exec_argv, errors, kDisallowedInEnvironment);
779+
const ExitCode exit_code =
780+
ProcessGlobalArgsInternal(argv, exec_argv, errors, kDisallowedInEnvvar);
781781
if (exit_code != ExitCode::kNoFailure) return exit_code;
782782
}
783783

src/node.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,25 @@ inline std::unique_ptr<InitializationResult> InitializeOncePerProcess(
349349
}
350350

351351
enum OptionEnvvarSettings {
352-
kAllowedInEnvironment,
353-
kDisallowedInEnvironment
352+
// Allow the options to be set via the environment variable, like
353+
// `NODE_OPTIONS`.
354+
kAllowedInEnvvar = 0,
355+
// Disallow the options to be set via the environment variable, like
356+
// `NODE_OPTIONS`.
357+
kDisallowedInEnvvar = 1,
358+
// Deprecated, use kAllowedInEnvvar instead.
359+
kAllowedInEnvironment = kAllowedInEnvvar,
360+
// Deprecated, use kDisallowedInEnvvar instead.
361+
kDisallowedInEnvironment = kDisallowedInEnvvar,
354362
};
355363

364+
// Process the arguments and set up the per-process options.
365+
// If the `settings` is set as OptionEnvvarSettings::kAllowedInEnvvar, the
366+
// options that are allowed in the environment variable are processed. Options
367+
// that are disallowed to be set via environment variable are processed as
368+
// errors.
369+
// Otherwise all the options that are disallowed (and those are allowed) to be
370+
// set via environment variable are processed.
356371
NODE_EXTERN int ProcessGlobalArgs(std::vector<std::string>* args,
357372
std::vector<std::string>* exec_args,
358373
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)