Skip to content

Commit fd0361b

Browse files
addaleaxMylesBorins
authored andcommitted
src: mark options parsers as const
These do not change their contents after being constructed. PR-URL: #25065 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7df59f8 commit fd0361b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/node_options-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ auto OptionsParser<Options>::Convert(
214214
template <typename Options>
215215
template <typename ChildOptions>
216216
void OptionsParser<Options>::Insert(
217-
OptionsParser<ChildOptions>* child_options_parser,
217+
const OptionsParser<ChildOptions>* child_options_parser,
218218
ChildOptions* (Options::* get_child)()) {
219219
aliases_.insert(child_options_parser->aliases_.begin(),
220220
child_options_parser->aliases_.end());
@@ -287,7 +287,7 @@ void OptionsParser<Options>::Parse(
287287
std::vector<std::string>* const v8_args,
288288
Options* const options,
289289
OptionEnvvarSettings required_env_settings,
290-
std::vector<std::string>* const errors) {
290+
std::vector<std::string>* const errors) const {
291291
ArgsInfo args(orig_args, exec_args);
292292

293293
// The first entry is the process name. Make sure it ends up in the V8 argv,

src/node_options.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ DebugOptionsParser::DebugOptionsParser() {
8888
}
8989

9090
#if HAVE_INSPECTOR
91-
DebugOptionsParser DebugOptionsParser::instance;
91+
const DebugOptionsParser DebugOptionsParser::instance;
9292
#endif // HAVE_INSPECTOR
9393

9494
EnvironmentOptionsParser::EnvironmentOptionsParser() {
@@ -211,7 +211,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
211211
#endif // HAVE_INSPECTOR
212212
}
213213

214-
EnvironmentOptionsParser EnvironmentOptionsParser::instance;
214+
const EnvironmentOptionsParser EnvironmentOptionsParser::instance;
215215

216216
PerIsolateOptionsParser::PerIsolateOptionsParser() {
217217
AddOption("--track-heap-objects",
@@ -234,7 +234,7 @@ PerIsolateOptionsParser::PerIsolateOptionsParser() {
234234
&PerIsolateOptions::get_per_env_options);
235235
}
236236

237-
PerIsolateOptionsParser PerIsolateOptionsParser::instance;
237+
const PerIsolateOptionsParser PerIsolateOptionsParser::instance;
238238

239239
PerProcessOptionsParser::PerProcessOptionsParser() {
240240
AddOption("--title",
@@ -342,7 +342,7 @@ PerProcessOptionsParser::PerProcessOptionsParser() {
342342
&PerProcessOptions::get_per_isolate_options);
343343
}
344344

345-
PerProcessOptionsParser PerProcessOptionsParser::instance;
345+
const PerProcessOptionsParser PerProcessOptionsParser::instance;
346346

347347
inline std::string RemoveBrackets(const std::string& host) {
348348
if (!host.empty() && host.front() == '[' && host.back() == ']')

src/node_options.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class OptionsParser {
281281
// a method that yields the target options type from this parser's options
282282
// type.
283283
template <typename ChildOptions>
284-
void Insert(OptionsParser<ChildOptions>* child_options_parser,
284+
void Insert(const OptionsParser<ChildOptions>* child_options_parser,
285285
ChildOptions* (Options::* get_child)());
286286

287287
// Parse a sequence of options into an options struct, a list of
@@ -306,7 +306,7 @@ class OptionsParser {
306306
std::vector<std::string>* const v8_args,
307307
Options* const options,
308308
OptionEnvvarSettings required_env_settings,
309-
std::vector<std::string>* const errors);
309+
std::vector<std::string>* const errors) const;
310310

311311
private:
312312
// We support the wide variety of different option types by remembering
@@ -397,28 +397,28 @@ class DebugOptionsParser : public OptionsParser<DebugOptions> {
397397
public:
398398
DebugOptionsParser();
399399

400-
static DebugOptionsParser instance;
400+
static const DebugOptionsParser instance;
401401
};
402402

403403
class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> {
404404
public:
405405
EnvironmentOptionsParser();
406406

407-
static EnvironmentOptionsParser instance;
407+
static const EnvironmentOptionsParser instance;
408408
};
409409

410410
class PerIsolateOptionsParser : public OptionsParser<PerIsolateOptions> {
411411
public:
412412
PerIsolateOptionsParser();
413413

414-
static PerIsolateOptionsParser instance;
414+
static const PerIsolateOptionsParser instance;
415415
};
416416

417417
class PerProcessOptionsParser : public OptionsParser<PerProcessOptions> {
418418
public:
419419
PerProcessOptionsParser();
420420

421-
static PerProcessOptionsParser instance;
421+
static const PerProcessOptionsParser instance;
422422
};
423423

424424
} // namespace options_parser

0 commit comments

Comments
 (0)