| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fed6411 commit 3c7a7d9
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,7 +140,7 @@ function setupWarningHandler() { | |||
| 140 | 140 | const { | |
| 141 | 141 | onWarning | |
| 142 | 142 | } = require('internal/process/warning'); | |
| 143 | - if (!getOptionValue('--no-warnings') && | ||
| 143 | + if (getOptionValue('--warnings') && | ||
| 144 | 144 | process.env.NODE_NO_WARNINGS !== '1') { | |
| 145 | 145 | process.on('warning', onWarning); | |
| 146 | 146 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,8 @@ const { | |||
| 8 | 8 | MathMax, | |
| 9 | 9 | ObjectKeys, | |
| 10 | 10 | RegExp, | |
| 11 | + StringPrototypeLocaleCompare, | ||
| 12 | + StringPrototypeSlice, | ||
| 11 | 13 | StringPrototypeTrimLeft, | |
| 12 | 14 | StringPrototypeRepeat, | |
| 13 | 15 | StringPrototypeReplace, | |
@@ -110,12 +112,30 @@ function format( | |||
| 110 | 112 | let text = ''; | |
| 111 | 113 | let maxFirstColumnUsed = 0; | |
| 112 | 114 | ||
| 115 | + const sortedOptions = ArrayPrototypeSort( | ||
| 116 | + [...options.entries()], | ||
| 117 | + ({ 0: name1, 1: option1 }, { 0: name2, 1: option2 }) => { | ||
| 118 | + if (option1.defaultIsTrue) { | ||
| 119 | + name1 = `--no-${StringPrototypeSlice(name1, 2)}`; | ||
| 120 | + } | ||
| 121 | + if (option2.defaultIsTrue) { | ||
| 122 | + name2 = `--no-${StringPrototypeSlice(name2, 2)}`; | ||
| 123 | + } | ||
| 124 | + return StringPrototypeLocaleCompare(name1, name2); | ||
| 125 | + }, | ||
| 126 | + ); | ||
| 127 | + | ||
| 113 | 128 | for (const { | |
| 114 | - 0: name, 1: { helpText, type, value } | ||
| 115 | - } of ArrayPrototypeSort([...options.entries()])) { | ||
| 129 | + 0: name, 1: { helpText, type, value, defaultIsTrue } | ||
| 130 | + } of sortedOptions) { | ||
| 116 | 131 | if (!helpText) continue; | |
| 117 | 132 | ||
| 118 | 133 | let displayName = name; | |
| 134 | + | ||
| 135 | + if (defaultIsTrue) { | ||
| 136 | + displayName = `--no-${StringPrototypeSlice(displayName, 2)}`; | ||
| 137 | + } | ||
| 138 | + | ||
| 119 | 139 | const argDescription = getArgDescription(type); | |
| 120 | 140 | if (argDescription) | |
| 121 | 141 | displayName += `=${argDescription}`; | |
@@ -138,7 +158,7 @@ function format( | |||
| 138 | 158 | } | |
| 139 | 159 | ||
| 140 | 160 | let displayHelpText = helpText; | |
| 141 | - if (value === true) { | ||
| 161 | + if (value === !defaultIsTrue) { | ||
| 142 | 162 | // Mark boolean options we currently have enabled. | |
| 143 | 163 | // In particular, it indicates whether --use-openssl-ca | |
| 144 | 164 | // or --use-bundled-ca is the (current) default. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,13 @@ function getAliasesFromBinding() { | |||
| 25 | 25 | return aliasesMap; | |
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | - function getOptionValue(option) { | ||
| 29 | - return getOptionsFromBinding().get(option)?.value; | ||
| 28 | + function getOptionValue(optionName) { | ||
| 29 | + const options = getOptionsFromBinding(); | ||
| 30 | + if (optionName.startsWith('--no-')) { | ||
| 31 | + const option = options.get('--' + optionName.slice(5)); | ||
| 32 | + return option && !option.value; | ||
| 33 | + } | ||
| 34 | + return options.get(optionName)?.value; | ||
| 30 | 35 | } | |
| 31 | 36 | ||
| 32 | 37 | function getAllowUnauthorized() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -259,14 +259,19 @@ const trailingValuesRegex = /=.*$/; | |||
| 259 | 259 | // from data in the config binding. | |
| 260 | 260 | function buildAllowedFlags() { | |
| 261 | 261 | const { | |
| 262 | - envSettings: { kAllowedInEnvironment } | ||
| 262 | + envSettings: { kAllowedInEnvironment }, | ||
| 263 | + types: { kBoolean }, | ||
| 263 | 264 | } = internalBinding('options'); | |
| 264 | 265 | const { options, aliases } = require('internal/options'); | |
| 265 | 266 | ||
| 266 | 267 | const allowedNodeEnvironmentFlags = []; | |
| 267 | 268 | for (const { 0: name, 1: info } of options) { | |
| 268 | 269 | if (info.envVarSettings === kAllowedInEnvironment) { | |
| 269 | 270 | ArrayPrototypePush(allowedNodeEnvironmentFlags, name); | |
| 271 | + if (info.type === kBoolean) { | ||
| 272 | + const negatedName = `--no-${name.slice(2)}`; | ||
| 273 | + ArrayPrototypePush(allowedNodeEnvironmentFlags, negatedName); | ||
| 274 | + } | ||
| 270 | 275 | } | |
| 271 | 276 | } | |
| 272 | 277 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -447,7 +447,7 @@ void Environment::InitializeMainContext(Local<Context> context, | |||
| 447 | 447 | CreateProperties(); | |
| 448 | 448 | } | |
| 449 | 449 | ||
| 450 | - if (options_->no_force_async_hooks_checks) { | ||
| 450 | + if (!options_->force_async_hooks_checks) { | ||
| 451 | 451 | async_hooks_.no_force_checks(); | |
| 452 | 452 | } | |
| 453 | 453 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -211,6 +211,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 211 | 211 | V(crypto_rsa_pss_string, "rsa-pss") \ | |
| 212 | 212 | V(cwd_string, "cwd") \ | |
| 213 | 213 | V(data_string, "data") \ | |
| 214 | + V(default_is_true_string, "defaultIsTrue") \ | ||
| 214 | 215 | V(deserialize_info_string, "deserializeInfo") \ | |
| 215 | 216 | V(dest_string, "dest") \ | |
| 216 | 217 | V(destroyed_string, "destroyed") \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1132,9 +1132,9 @@ int Start(int argc, char** argv) { | |||
| 1132 | 1132 | Isolate::CreateParams params; | |
| 1133 | 1133 | const std::vector<size_t>* indices = nullptr; | |
| 1134 | 1134 | const EnvSerializeInfo* env_info = nullptr; | |
| 1135 | - bool force_no_snapshot = | ||
| 1136 | - per_process::cli_options->per_isolate->no_node_snapshot; | ||
| 1137 | - if (!force_no_snapshot) { | ||
| 1135 | + bool use_node_snapshot = | ||
| 1136 | + per_process::cli_options->per_isolate->node_snapshot; | ||
| 1137 | + if (use_node_snapshot) { | ||
| 1138 | 1138 | v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob(); | |
| 1139 | 1139 | if (blob != nullptr) { | |
| 1140 | 1140 | params.snapshot_blob = blob; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,12 +23,14 @@ template <typename Options> | |||
| 23 | 23 | void OptionsParser<Options>::AddOption(const char* name, | |
| 24 | 24 | const char* help_text, | |
| 25 | 25 | bool Options::* field, | |
| 26 | - OptionEnvvarSettings env_setting) { | ||
| 26 | + OptionEnvvarSettings env_setting, | ||
| 27 | + bool default_is_true) { | ||
| 27 | 28 | options_.emplace(name, | |
| 28 | 29 | OptionInfo{kBoolean, | |
| 29 | 30 | std::make_shared<SimpleOptionField<bool>>(field), | |
| 30 | 31 | env_setting, | |
| 31 | - help_text}); | ||
| 32 | + help_text, | ||
| 33 | + default_is_true}); | ||
| 32 | 34 | } | |
| 33 | 35 | ||
| 34 | 36 | template <typename Options> | |
@@ -186,7 +188,8 @@ auto OptionsParser<Options>::Convert( | |||
| 186 | 188 | return OptionInfo{original.type, | |
| 187 | 189 | Convert(original.field, get_child), | |
| 188 | 190 | original.env_setting, | |
| 189 | - original.help_text}; | ||
| 191 | + original.help_text, | ||
| 192 | + original.default_is_true}; | ||
| 190 | 193 | } | |
| 191 | 194 | ||
| 192 | 195 | template <typename Options> | |
@@ -225,6 +228,10 @@ inline std::string RequiresArgumentErr(const std::string& arg) { | |||
| 225 | 228 | return arg + " requires an argument"; | |
| 226 | 229 | } | |
| 227 | 230 | ||
| 231 | + inline std::string NegationImpliesBooleanError(const std::string& arg) { | ||
| 232 | + return arg + " is an invalid negation because it is not a boolean option"; | ||
| 233 | + } | ||
| 234 | + | ||
| 228 | 235 | // We store some of the basic information around a single Parse call inside | |
| 229 | 236 | // this struct, to separate storage of command line arguments and their | |
| 230 | 237 | // handling. In particular, this makes it easier to introduce 'synthetic' | |
@@ -325,6 +332,13 @@ void OptionsParser<Options>::Parse( | |||
| 325 | 332 | name[i] = '-'; | |
| 326 | 333 | } | |
| 327 | 334 | ||
| 335 | + // Convert --no-foo to --foo and keep in mind that we're negating. | ||
| 336 | + bool is_negation = false; | ||
| 337 | + if (name.find("--no-") == 0) { | ||
| 338 | + name.erase(2, 3); // remove no- | ||
| 339 | + is_negation = true; | ||
| 340 | + } | ||
| 341 | + | ||
| 328 | 342 | { | |
| 329 | 343 | auto it = aliases_.end(); | |
| 330 | 344 | // Expand aliases: | |
@@ -367,7 +381,12 @@ void OptionsParser<Options>::Parse( | |||
| 367 | 381 | } | |
| 368 | 382 | ||
| 369 | 383 | { | |
| 370 | - auto implications = implications_.equal_range(name); | ||
| 384 | + std::string implied_name = name; | ||
| 385 | + if (is_negation) { | ||
| 386 | + // Implications for negated options are defined with "--no-". | ||
| 387 | + implied_name.insert(2, "no-"); | ||
| 388 | + } | ||
| 389 | + auto implications = implications_.equal_range(implied_name); | ||
| 371 | 390 | for (auto it = implications.first; it != implications.second; ++it) { | |
| 372 | 391 | if (it->second.type == kV8Option) { | |
| 373 | 392 | v8_args->push_back(it->second.name); | |
@@ -384,6 +403,13 @@ void OptionsParser<Options>::Parse( | |||
| 384 | 403 | } | |
| 385 | 404 | ||
| 386 | 405 | const OptionInfo& info = it->second; | |
| 406 | + | ||
| 407 | + // Some V8 options can be negated and they are validated by V8 later. | ||
| 408 | + if (is_negation && info.type != kBoolean && info.type != kV8Option) { | ||
| 409 | + errors->push_back(NegationImpliesBooleanError(arg)); | ||
| 410 | + break; | ||
| 411 | + } | ||
| 412 | + | ||
| 387 | 413 | std::string value; | |
| 388 | 414 | if (info.type != kBoolean && info.type != kNoOp && info.type != kV8Option) { | |
| 389 | 415 | if (equals_index != std::string::npos) { | |
@@ -412,7 +438,7 @@ void OptionsParser<Options>::Parse( | |||
| 412 | 438 | ||
| 413 | 439 | switch (info.type) { | |
| 414 | 440 | case kBoolean: | |
| 415 | - *Lookup<bool>(info.field, options) = true; | ||
| 441 | + *Lookup<bool>(info.field, options) = !is_negation; | ||
| 416 | 442 | break; | |
| 417 | 443 | case kInteger: | |
| 418 | 444 | *Lookup<int64_t>(info.field, options) = std::atoll(value.c_str()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -391,18 +391,21 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | |||
| 391 | 391 | kAllowedInEnvironment); | |
| 392 | 392 | AddAlias("--es-module-specifier-resolution", | |
| 393 | 393 | "--experimental-specifier-resolution"); | |
| 394 | - AddOption("--no-deprecation", | ||
| 394 | + AddOption("--deprecation", | ||
| 395 | 395 | "silence deprecation warnings", | |
| 396 | - &EnvironmentOptions::no_deprecation, | ||
| 397 | - kAllowedInEnvironment); | ||
| 398 | - AddOption("--no-force-async-hooks-checks", | ||
| 396 | + &EnvironmentOptions::deprecation, | ||
| 397 | + kAllowedInEnvironment, | ||
| 398 | + true); | ||
| 399 | + AddOption("--force-async-hooks-checks", | ||
| 399 | 400 | "disable checks for async_hooks", | |
| 400 | - &EnvironmentOptions::no_force_async_hooks_checks, | ||
| 401 | - kAllowedInEnvironment); | ||
| 402 | - AddOption("--no-warnings", | ||
| 401 | + &EnvironmentOptions::force_async_hooks_checks, | ||
| 402 | + kAllowedInEnvironment, | ||
| 403 | + true); | ||
| 404 | + AddOption("--warnings", | ||
| 403 | 405 | "silence all process warnings", | |
| 404 | - &EnvironmentOptions::no_warnings, | ||
| 405 | - kAllowedInEnvironment); | ||
| 406 | + &EnvironmentOptions::warnings, | ||
| 407 | + kAllowedInEnvironment, | ||
| 408 | + true); | ||
| 406 | 409 | AddOption("--force-context-aware", | |
| 407 | 410 | "disable loading non-context-aware addons", | |
| 408 | 411 | &EnvironmentOptions::force_context_aware, | |
@@ -594,9 +597,9 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( | |||
| 594 | 597 | "track heap object allocations for heap snapshots", | |
| 595 | 598 | &PerIsolateOptions::track_heap_objects, | |
| 596 | 599 | kAllowedInEnvironment); | |
| 597 | - AddOption("--no-node-snapshot", | ||
| 600 | + AddOption("--node-snapshot", | ||
| 598 | 601 | "", // It's a debug-only option. | |
| 599 | - &PerIsolateOptions::no_node_snapshot, | ||
| 602 | + &PerIsolateOptions::node_snapshot, | ||
| 600 | 603 | kAllowedInEnvironment); | |
| 601 | 604 | ||
| 602 | 605 | // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS. | |
@@ -1014,6 +1017,10 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) { | |||
| 1014 | 1017 | env->type_string(), | |
| 1015 | 1018 | Integer::New(isolate, static_cast<int>(option_info.type))) | |
| 1016 | 1019 | .FromMaybe(false) || | |
| 1020 | + !info->Set(context, | ||
| 1021 | + env->default_is_true_string(), | ||
| 1022 | + Boolean::New(isolate, option_info.default_is_true)) | ||
| 1023 | + .FromMaybe(false) || | ||
| 1017 | 1024 | info->Set(context, env->value_string(), value).IsNothing() || | |
| 1018 | 1025 | options->Set(context, name, info).IsEmpty()) { | |
| 1019 | 1026 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,9 +119,9 @@ class EnvironmentOptions : public Options { | |||
| 119 | 119 | int64_t heap_snapshot_near_heap_limit = 0; | |
| 120 | 120 | std::string heap_snapshot_signal; | |
| 121 | 121 | uint64_t max_http_header_size = 16 * 1024; | |
| 122 | - bool no_deprecation = false; | ||
| 123 | - bool no_force_async_hooks_checks = false; | ||
| 124 | - bool no_warnings = false; | ||
| 122 | + bool deprecation = true; | ||
| 123 | + bool force_async_hooks_checks = true; | ||
| 124 | + bool warnings = true; | ||
| 125 | 125 | bool force_context_aware = false; | |
| 126 | 126 | bool pending_deprecation = false; | |
| 127 | 127 | bool preserve_symlinks = false; | |
@@ -193,7 +193,7 @@ class PerIsolateOptions : public Options { | |||
| 193 | 193 | public: | |
| 194 | 194 | std::shared_ptr<EnvironmentOptions> per_env { new EnvironmentOptions() }; | |
| 195 | 195 | bool track_heap_objects = false; | |
| 196 | - bool no_node_snapshot = false; | ||
| 196 | + bool node_snapshot = true; | ||
| 197 | 197 | bool report_uncaught_exception = false; | |
| 198 | 198 | bool report_on_signal = false; | |
| 199 | 199 | bool experimental_top_level_await = true; | |
@@ -301,7 +301,8 @@ class OptionsParser { | |||
| 301 | 301 | void AddOption(const char* name, | |
| 302 | 302 | const char* help_text, | |
| 303 | 303 | bool Options::* field, | |
| 304 | - OptionEnvvarSettings env_setting = kDisallowedInEnvironment); | ||
| 304 | + OptionEnvvarSettings env_setting = kDisallowedInEnvironment, | ||
| 305 | + bool default_is_true = false); | ||
| 305 | 306 | void AddOption(const char* name, | |
| 306 | 307 | const char* help_text, | |
| 307 | 308 | uint64_t Options::* field, | |
@@ -424,6 +425,7 @@ class OptionsParser { | |||
| 424 | 425 | std::shared_ptr<BaseOptionField> field; | |
| 425 | 426 | OptionEnvvarSettings env_setting; | |
| 426 | 427 | std::string help_text; | |
| 428 | + bool default_is_true = false; | ||
| 427 | 429 | }; | |
| 428 | 430 | ||
| 429 | 431 | // An implied option is composed of the information on where to store a | |
| Back | FazBrowse Home | New Git URL |
0 commit comments