Skip to content

src: add function to reset arguments to default #22192

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

Closed
wants to merge 2 commits into from
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2600,6 +2600,9 @@ void Init(std::vector<std::string>* argv,
node_is_initialized = true;
}

NODE_EXTERN void ResetOptions() {
per_process_opts->Reset();
}
// TODO(addaleax): Deprecate and eventually remove this.
void Init(int* argc,
const char** argv,
Expand Down
1 change: 1 addition & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ NODE_EXTERN void Init(int* argc,
const char** argv,
int* exec_argc,
const char*** exec_argv);
NODE_EXTERN void ResetOptions();

class ArrayBufferAllocator;

Expand Down
74 changes: 74 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,51 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
per_isolate->CheckOptions(errors);
}

void PerProcessOptions::Reset() {
per_isolate->Reset();
title = "";
trace_event_categories = "";
trace_event_file_pattern = "node_trace.${rotation}.log";
v8_thread_pool_size = 4;
zero_fill_all_buffers = false;

security_reverts.clear();
print_bash_completion = false;
print_help = false;
print_v8_help = false;
print_version = false;

#ifdef NODE_HAVE_I18N_SUPPORT
icu_data_dir = "";
#endif

// TODO(addaleax): Some of these could probably be per-Environment.
#if HAVE_OPENSSL
openssl_config = "";
tls_cipher_list = DEFAULT_CIPHER_LIST_CORE;
#ifdef NODE_OPENSSL_CERT_STORE
ssl_openssl_cert_store = true;
#else
ssl_openssl_cert_store = false;
#endif
use_openssl_ca = false;
use_bundled_ca = false;
#if NODE_FIPS_MODE
enable_fips_crypto = false;
force_fips_crypto = false;
#endif
#endif
}

void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
per_env->CheckOptions(errors);
}

void PerIsolateOptions::Reset() {
per_env->Reset();
track_heap_objects = false;
}

void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
if (!userland_loader.empty() && !experimental_modules) {
errors->push_back("--loader requires --experimental-modules be enabled");
Expand All @@ -42,6 +83,39 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
debug_options->CheckOptions(errors);
}

void EnvironmentOptions::Reset() {
debug_options->Reset();
abort_on_uncaught_exception = false;
experimental_modules = false;
experimental_repl_await = false;
experimental_vm_modules = false;
experimental_worker = false;
expose_internals = false;
no_deprecation = false;
no_force_async_hooks_checks = false;
no_warnings = false;
pending_deprecation = false;
preserve_symlinks = false;
preserve_symlinks_main = false;
prof_process = false;
redirect_warnings = "";
throw_deprecation = false;
trace_deprecation = false;
trace_sync_io = false;
trace_warnings = false;
userland_loader = "";

syntax_check_only = false;
has_eval_string = false;
eval_string = "";
print_eval = false;
force_repl = false;

preload_modules.clear();

user_argv.clear();
}

namespace options_parser {

// XXX: If you add an option here, please also add it to doc/node.1 and
Expand Down
11 changes: 11 additions & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class DebugOptions : public Options {
int port() {
return host_port.port < 0 ? kDefaultInspectorPort : host_port.port;
}

void Reset() {
inspector_enabled = false;
deprecated_debug = false;
break_first_line = false;
break_node_first_line = false;
host_port = {"127.0.0.1", -1};
}
};

class EnvironmentOptions : public Options {
Expand Down Expand Up @@ -98,6 +106,7 @@ class EnvironmentOptions : public Options {

inline DebugOptions* get_debug_options();
void CheckOptions(std::vector<std::string>* errors);
void Reset();
};

class PerIsolateOptions : public Options {
Expand All @@ -107,6 +116,7 @@ class PerIsolateOptions : public Options {

inline EnvironmentOptions* get_per_env_options();
void CheckOptions(std::vector<std::string>* errors);
void Reset();
};

class PerProcessOptions : public Options {
Expand Down Expand Up @@ -148,6 +158,7 @@ class PerProcessOptions : public Options {

inline PerIsolateOptions* get_per_isolate_options();
void CheckOptions(std::vector<std::string>* errors);
void Reset();
};

// The actual options parser, as opposed to the structs containing them:
Expand Down