Skip to content

Commit 169b33a

Browse files
MoLowdanielleadams
authored andcommitted
src: forbid running watch mode in REPL
PR-URL: #45058 Fixes: #45006 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 57b7023 commit 169b33a

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
347347
return StartExecution(env, "internal/main/test_runner");
348348
}
349349

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

src/node_options-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void OptionsParser<Options>::Parse(
466466
UNREACHABLE();
467467
}
468468
}
469-
options->CheckOptions(errors);
469+
options->CheckOptions(errors, orig_args);
470470
}
471471

472472
} // namespace options_parser

src/node_options.cc

+15-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Mutex cli_options_mutex;
3434
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
3535
} // namespace per_process
3636

37-
void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
37+
void DebugOptions::CheckOptions(std::vector<std::string>* errors,
38+
std::vector<std::string>* argv) {
3839
#if !NODE_USE_V8_PLATFORM && !HAVE_INSPECTOR
3940
if (inspector_enabled) {
4041
errors->push_back("Inspector is not available when Node is compiled "
@@ -64,7 +65,8 @@ void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
6465
}
6566
}
6667

67-
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
68+
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors,
69+
std::vector<std::string>* argv) {
6870
#if HAVE_OPENSSL
6971
if (use_openssl_ca && use_bundled_ca) {
7072
errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
@@ -91,14 +93,16 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
9193
use_largepages != "silent") {
9294
errors->push_back("invalid value for --use-largepages");
9395
}
94-
per_isolate->CheckOptions(errors);
96+
per_isolate->CheckOptions(errors, argv);
9597
}
9698

97-
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
98-
per_env->CheckOptions(errors);
99+
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors,
100+
std::vector<std::string>* argv) {
101+
per_env->CheckOptions(errors, argv);
99102
}
100103

101-
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
104+
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
105+
std::vector<std::string>* argv) {
102106
if (has_policy_integrity_string && experimental_policy.empty()) {
103107
errors->push_back("--policy-integrity requires "
104108
"--experimental-policy be enabled");
@@ -169,15 +173,13 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
169173
if (watch_mode) {
170174
if (syntax_check_only) {
171175
errors->push_back("either --watch or --check can be used, not both");
172-
}
173-
174-
if (has_eval_string) {
176+
} else if (has_eval_string) {
175177
errors->push_back("either --watch or --eval can be used, not both");
176-
}
177-
178-
if (force_repl) {
178+
} else if (force_repl) {
179179
errors->push_back("either --watch or --interactive "
180180
"can be used, not both");
181+
} else if (argv->size() < 1 || (*argv)[1].empty()) {
182+
errors->push_back("--watch requires specifying a file");
181183
}
182184

183185
#ifndef ALLOW_ATTACHING_DEBUGGER_IN_WATCH_MODE
@@ -222,7 +224,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
222224
heap_prof_dir = diagnostic_dir;
223225
}
224226

225-
debug_options_.CheckOptions(errors);
227+
debug_options_.CheckOptions(errors, argv);
226228
#endif // HAVE_INSPECTOR
227229
}
228230

src/node_options.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class HostPort {
5050

5151
class Options {
5252
public:
53-
virtual void CheckOptions(std::vector<std::string>* errors) {}
53+
virtual void CheckOptions(std::vector<std::string>* errors,
54+
std::vector<std::string>* argv) {}
5455
virtual ~Options() = default;
5556
};
5657

@@ -99,7 +100,8 @@ class DebugOptions : public Options {
99100
return break_first_line || break_node_first_line;
100101
}
101102

102-
void CheckOptions(std::vector<std::string>* errors) override;
103+
void CheckOptions(std::vector<std::string>* errors,
104+
std::vector<std::string>* argv) override;
103105
};
104106

105107
class EnvironmentOptions : public Options {
@@ -202,7 +204,8 @@ class EnvironmentOptions : public Options {
202204
inline DebugOptions* get_debug_options() { return &debug_options_; }
203205
inline const DebugOptions& debug_options() const { return debug_options_; }
204206

205-
void CheckOptions(std::vector<std::string>* errors) override;
207+
void CheckOptions(std::vector<std::string>* errors,
208+
std::vector<std::string>* argv) override;
206209

207210
private:
208211
DebugOptions debug_options_;
@@ -217,7 +220,8 @@ class PerIsolateOptions : public Options {
217220
bool experimental_shadow_realm = false;
218221
std::string report_signal = "SIGUSR2";
219222
inline EnvironmentOptions* get_per_env_options();
220-
void CheckOptions(std::vector<std::string>* errors) override;
223+
void CheckOptions(std::vector<std::string>* errors,
224+
std::vector<std::string>* argv) override;
221225
};
222226

223227
class PerProcessOptions : public Options {
@@ -290,7 +294,8 @@ class PerProcessOptions : public Options {
290294
std::vector<std::string> cmdline;
291295

292296
inline PerIsolateOptions* get_per_isolate_options();
293-
void CheckOptions(std::vector<std::string>* errors) override;
297+
void CheckOptions(std::vector<std::string>* errors,
298+
std::vector<std::string>* argv) override;
294299
};
295300

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

0 commit comments

Comments
 (0)