Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.x] src: clarify OptionEnvvarSettings member names #45994

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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