Skip to content

Commit

Permalink
src: clarify OptionEnvvarSettings member names
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
legendecas authored and danielleadams committed May 29, 2023
1 parent e8b5a61 commit 0d5e324
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 162 deletions.
6 changes: 3 additions & 3 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ const trailingValuesRegex = /=.*$/;
// from data in the config binding.
function buildAllowedFlags() {
const {
envSettings: { kAllowedInEnvironment },
envSettings: { kAllowedInEnvvar },
types: { kBoolean },
} = internalBinding('options');
const { options, aliases } = require('internal/options');

const allowedNodeEnvironmentFlags = [];
for (const { 0: name, 1: info } of options) {
if (info.envVarSettings === kAllowedInEnvironment) {
if (info.envVarSettings === kAllowedInEnvvar) {
ArrayPrototypePush(allowedNodeEnvironmentFlags, name);
if (info.type === kBoolean) {
const negatedName = `--no-${name.slice(2)}`;
Expand All @@ -301,7 +301,7 @@ function buildAllowedFlags() {
ArrayPrototypeSplice(recursiveExpansion, 0, 1);
return ArrayPrototypeEvery(recursiveExpansion, isAccepted);
}
return options.get(to).envVarSettings === kAllowedInEnvironment;
return options.get(to).envVarSettings === kAllowedInEnvvar;
}
for (const { 0: from, 1: expansion } of aliases) {
if (ArrayPrototypeEvery(expansion, isAccepted)) {
Expand Down
4 changes: 2 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
const int exit_code = ProcessGlobalArgs(&env_argv,
nullptr,
errors,
kAllowedInEnvironment);
kAllowedInEnvvar);
if (exit_code != 0) return exit_code;
}
}
Expand All @@ -827,7 +827,7 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
const int exit_code = ProcessGlobalArgs(argv,
exec_argv,
errors,
kDisallowedInEnvironment);
kDisallowedInEnvvar);
if (exit_code != 0) return exit_code;
}

Expand Down
19 changes: 17 additions & 2 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,25 @@ inline std::unique_ptr<InitializationResult> InitializeOncePerProcess(
}

enum OptionEnvvarSettings {
kAllowedInEnvironment,
kDisallowedInEnvironment
// Allow the options to be set via the environment variable, like
// `NODE_OPTIONS`.
kAllowedInEnvvar = 0,
// Disallow the options to be set via the environment variable, like
// `NODE_OPTIONS`.
kDisallowedInEnvvar = 1,
// Deprecated, use kAllowedInEnvvar instead.
kAllowedInEnvironment = kAllowedInEnvvar,
// Deprecated, use kDisallowedInEnvvar instead.
kDisallowedInEnvironment = kDisallowedInEnvvar,
};

// Process the arguments and set up the per-process options.
// If the `settings` is set as OptionEnvvarSettings::kAllowedInEnvvar, the
// options that are allowed in the environment variable are processed. Options
// that are disallowed to be set via environment variable are processed as
// errors.
// Otherwise all the options that are disallowed (and those are allowed) to be
// set via environment variable are processed.
NODE_EXTERN int ProcessGlobalArgs(std::vector<std::string>* args,
std::vector<std::string>* exec_args,
std::vector<std::string>* errors,
Expand Down
6 changes: 3 additions & 3 deletions src/node_options-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void OptionsParser<Options>::Parse(
const std::string arg = args.pop_first();

if (arg == "--") {
if (required_env_settings == kAllowedInEnvironment)
if (required_env_settings == kAllowedInEnvvar)
errors->push_back(NotAllowedInEnvErr("--"));
break;
}
Expand Down Expand Up @@ -374,8 +374,8 @@ void OptionsParser<Options>::Parse(
auto it = options_.find(name);

if ((it == options_.end() ||
it->second.env_setting == kDisallowedInEnvironment) &&
required_env_settings == kAllowedInEnvironment) {
it->second.env_setting == kDisallowedInEnvvar) &&
required_env_settings == kAllowedInEnvvar) {
errors->push_back(NotAllowedInEnvErr(original_name));
break;
}
Expand Down
Loading

0 comments on commit 0d5e324

Please sign in to comment.