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

src: forbid running watch mode in REPL #45058

Merged
merged 2 commits into from Oct 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion src/node.cc
Expand Up @@ -331,7 +331,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
return StartExecution(env, "internal/main/test_runner");
}

if (env->options()->watch_mode && !first_argv.empty()) {
if (env->options()->watch_mode) {
return StartExecution(env, "internal/main/watch_mode");
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_options-inl.h
Expand Up @@ -466,7 +466,7 @@ void OptionsParser<Options>::Parse(
UNREACHABLE();
}
}
options->CheckOptions(errors);
options->CheckOptions(errors, orig_args);
}

} // namespace options_parser
Expand Down
28 changes: 15 additions & 13 deletions src/node_options.cc
Expand Up @@ -34,7 +34,8 @@ Mutex cli_options_mutex;
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
} // namespace per_process

void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
void DebugOptions::CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) {
#if !NODE_USE_V8_PLATFORM && !HAVE_INSPECTOR
if (inspector_enabled) {
errors->push_back("Inspector is not available when Node is compiled "
Expand Down Expand Up @@ -64,7 +65,8 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
}
}

void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) {
#if HAVE_OPENSSL
if (use_openssl_ca && use_bundled_ca) {
errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
Expand All @@ -91,14 +93,16 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
use_largepages != "silent") {
errors->push_back("invalid value for --use-largepages");
}
per_isolate->CheckOptions(errors);
per_isolate->CheckOptions(errors, argv);
}

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

void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) {
if (has_policy_integrity_string && experimental_policy.empty()) {
errors->push_back("--policy-integrity requires "
"--experimental-policy be enabled");
Expand Down Expand Up @@ -161,15 +165,13 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
if (watch_mode) {
if (syntax_check_only) {
errors->push_back("either --watch or --check can be used, not both");
}

if (has_eval_string) {
} else if (has_eval_string) {
errors->push_back("either --watch or --eval can be used, not both");
}

if (force_repl) {
} else if (force_repl) {
errors->push_back("either --watch or --interactive "
"can be used, not both");
} else if (argv->size() < 1 || (*argv)[1].empty()) {
errors->push_back("--watch requires specifying a file");
}

#ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE
Expand Down Expand Up @@ -214,7 +216,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
heap_prof_dir = diagnostic_dir;
}

debug_options_.CheckOptions(errors);
debug_options_.CheckOptions(errors, argv);
#endif // HAVE_INSPECTOR
}

Expand Down
15 changes: 10 additions & 5 deletions src/node_options.h
Expand Up @@ -50,7 +50,8 @@ class HostPort {

class Options {
public:
virtual void CheckOptions(std::vector<std::string>* errors) {}
virtual void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) {}
virtual ~Options() = default;
};

Expand Down Expand Up @@ -99,7 +100,8 @@ class DebugOptions : public Options {
return break_first_line || break_node_first_line;
}

void CheckOptions(std::vector<std::string>* errors) override;
void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;
};

class EnvironmentOptions : public Options {
Expand Down Expand Up @@ -203,7 +205,8 @@ class EnvironmentOptions : public Options {
inline DebugOptions* get_debug_options() { return &debug_options_; }
inline const DebugOptions& debug_options() const { return debug_options_; }

void CheckOptions(std::vector<std::string>* errors) override;
void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;

private:
DebugOptions debug_options_;
Expand All @@ -218,7 +221,8 @@ class PerIsolateOptions : public Options {
bool experimental_shadow_realm = false;
std::string report_signal = "SIGUSR2";
inline EnvironmentOptions* get_per_env_options();
void CheckOptions(std::vector<std::string>* errors) override;
void CheckOptions(std::vector<std::string>* errors,
std::vector<std::string>* argv) override;
};

class PerProcessOptions : public Options {
Expand Down Expand Up @@ -291,7 +295,8 @@ class PerProcessOptions : public Options {
std::vector<std::string> cmdline;

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

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