Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a8412f5

Browse filesBrowse files
MoLowRafaelGSS
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 162bf0d commit a8412f5
Copy full SHA for a8412f5

File tree

Expand file treeCollapse file tree

4 files changed

+27
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+27
-20
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ MaybeLocal<Value> StartExecution(Environment* env, StartExecutionCallback cb) {
331331
return StartExecution(env, "internal/main/test_runner");
332332
}
333333

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

Collapse file

‎src/node_options-inl.h‎

Copy file name to clipboardExpand all lines: src/node_options-inl.h
+1-1Lines changed: 1 addition & 1 deletion
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
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+15-13Lines changed: 15 additions & 13 deletions
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");
@@ -161,15 +165,13 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
161165
if (watch_mode) {
162166
if (syntax_check_only) {
163167
errors->push_back("either --watch or --check can be used, not both");
164-
}
165-
166-
if (has_eval_string) {
168+
} else if (has_eval_string) {
167169
errors->push_back("either --watch or --eval can be used, not both");
168-
}
169-
170-
if (force_repl) {
170+
} else if (force_repl) {
171171
errors->push_back("either --watch or --interactive "
172172
"can be used, not both");
173+
} else if (argv->size() < 1 || (*argv)[1].empty()) {
174+
errors->push_back("--watch requires specifying a file");
173175
}
174176

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

217-
debug_options_.CheckOptions(errors);
219+
debug_options_.CheckOptions(errors, argv);
218220
#endif // HAVE_INSPECTOR
219221
}
220222

Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+10-5Lines changed: 10 additions & 5 deletions
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 {
@@ -203,7 +205,8 @@ class EnvironmentOptions : public Options {
203205
inline DebugOptions* get_debug_options() { return &debug_options_; }
204206
inline const DebugOptions& debug_options() const { return debug_options_; }
205207

206-
void CheckOptions(std::vector<std::string>* errors) override;
208+
void CheckOptions(std::vector<std::string>* errors,
209+
std::vector<std::string>* argv) override;
207210

208211
private:
209212
DebugOptions debug_options_;
@@ -218,7 +221,8 @@ class PerIsolateOptions : public Options {
218221
bool experimental_shadow_realm = false;
219222
std::string report_signal = "SIGUSR2";
220223
inline EnvironmentOptions* get_per_env_options();
221-
void CheckOptions(std::vector<std::string>* errors) override;
224+
void CheckOptions(std::vector<std::string>* errors,
225+
std::vector<std::string>* argv) override;
222226
};
223227

224228
class PerProcessOptions : public Options {
@@ -291,7 +295,8 @@ class PerProcessOptions : public Options {
291295
std::vector<std::string> cmdline;
292296

293297
inline PerIsolateOptions* get_per_isolate_options();
294-
void CheckOptions(std::vector<std::string>* errors) override;
298+
void CheckOptions(std::vector<std::string>* errors,
299+
std::vector<std::string>* argv) override;
295300
};
296301

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.