src: add CheckOptions to Options classes

This commit adds a CheckOptions function that the options classes can
optionally implement to check that options specified are correct
(dependencies between options are met or options that are mutually
exclusive).

In the process of doing this the error pointer passed to Parse was
changed to be of type vector so that potentially multiple options check
failures can be reported.

PR-URL: https://github.com/nodejs/node/pull/22943
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Daniel Bevenius authored and Anna Henningsen committed 2018-09-22 12:00:28 +02:00
1 parent 1f4d4c0da8
commit 36bdd19a6b
4 files changed
+61 -44

No files matched your search

+15 -6
View File
@@ -21,11 +21,16 @@ struct HostPort {
}
};
class Options {
public:
virtual void CheckOptions(std::vector<std::string>* errors) {}
};
// These options are currently essentially per-Environment, but it can be nice
// to keep them separate since they are a group of options applying to a very
// specific part of Node. It might also make more sense for them to be
// per-Isolate, rather than per-Environment.
class DebugOptions {
class DebugOptions : public Options {
public:
bool inspector_enabled = false;
bool deprecated_debug = false;
@@ -57,7 +62,7 @@ class DebugOptions {
}
};
class EnvironmentOptions {
class EnvironmentOptions : public Options {
public:
std::shared_ptr<DebugOptions> debug_options { new DebugOptions() };
bool abort_on_uncaught_exception = false;
@@ -91,17 +96,19 @@ class EnvironmentOptions {
std::vector<std::string> user_argv;
inline DebugOptions* get_debug_options();
void CheckOptions(std::vector<std::string>* errors);
};
class PerIsolateOptions {
class PerIsolateOptions : public Options {
public:
std::shared_ptr<EnvironmentOptions> per_env { new EnvironmentOptions() };
bool track_heap_objects = false;
inline EnvironmentOptions* get_per_env_options();
void CheckOptions(std::vector<std::string>* errors);
};
class PerProcessOptions {
class PerProcessOptions : public Options {
public:
std::shared_ptr<PerIsolateOptions> per_isolate { new PerIsolateOptions() };
@@ -139,13 +146,15 @@ class PerProcessOptions {
#endif
inline PerIsolateOptions* get_per_isolate_options();
void CheckOptions(std::vector<std::string>* errors);
};
// The actual options parser, as opposed to the structs containing them:
namespace options_parser {
HostPort SplitHostPort(const std::string& arg, std::string* error);
HostPort SplitHostPort(const std::string& arg,
std::vector<std::string>* errors);
void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args);
enum OptionEnvvarSettings {
@@ -255,7 +264,7 @@ class OptionsParser {
std::vector<std::string>* const v8_args,
Options* const options,
OptionEnvvarSettings required_env_settings,
std::string* const error);
std::vector<std::string>* const errors);
private:
// We support the wide variety of different option types by remembering