Skip to content

Commit

Permalink
src: forbid running watch mode in REPL
Browse files Browse the repository at this point in the history
PR-URL: #45058
Fixes: #45006
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
MoLow authored and danielleadams committed Jan 3, 2023
1 parent 57b7023 commit 169b33a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -169,15 +173,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 @@ -222,7 +224,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
Original file line number Diff line number Diff line change
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 @@ -202,7 +204,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 @@ -217,7 +220,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 @@ -290,7 +294,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

0 comments on commit 169b33a

Please sign in to comment.