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
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 RafaelGSS committed Nov 1, 2022
1 parent 7173cd8 commit 3657f6a
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 165 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 @@ -283,14 +283,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 @@ -307,7 +307,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
6 changes: 3 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,15 @@ static ExitCode InitializeNodeWithArgsInternal(
env_argv.insert(env_argv.begin(), argv->at(0));

const ExitCode exit_code = ProcessGlobalArgsInternal(
&env_argv, nullptr, errors, kAllowedInEnvironment);
&env_argv, nullptr, errors, kAllowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) return exit_code;
}
}
#endif

if (!(flags & ProcessInitializationFlags::kDisableCLIOptions)) {
const ExitCode exit_code = ProcessGlobalArgsInternal(
argv, exec_argv, errors, kDisallowedInEnvironment);
const ExitCode exit_code =
ProcessGlobalArgsInternal(argv, exec_argv, errors, kDisallowedInEnvvar);
if (exit_code != ExitCode::kNoFailure) 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 @@ -349,10 +349,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 3657f6a

Please sign in to comment.