GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
#include "node_options.h" // NOLINT(build/include_inline) |
||
2 |
#include "node_options-inl.h" |
||
3 |
|||
4 |
#include "env-inl.h" |
||
5 |
#include "node_binding.h" |
||
6 |
#include "node_internals.h" |
||
7 |
|||
8 |
#include <errno.h> |
||
9 |
#include <sstream> |
||
10 |
#include <limits> |
||
11 |
#include <algorithm> |
||
12 |
#include <cstdlib> // strtoul, errno |
||
13 |
|||
14 |
using v8::Boolean; |
||
15 |
using v8::Context; |
||
16 |
using v8::FunctionCallbackInfo; |
||
17 |
using v8::Integer; |
||
18 |
using v8::Isolate; |
||
19 |
using v8::Local; |
||
20 |
using v8::Map; |
||
21 |
using v8::Number; |
||
22 |
using v8::Object; |
||
23 |
using v8::Undefined; |
||
24 |
using v8::Value; |
||
25 |
|||
26 |
namespace node { |
||
27 |
|||
28 |
namespace per_process { |
||
29 |
4665 |
Mutex cli_options_mutex; |
|
30 |
4665 |
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()}; |
|
31 |
} // namespace per_process |
||
32 |
|||
33 |
9385 |
void DebugOptions::CheckOptions(std::vector<std::string>* errors) { |
|
34 |
#if !NODE_USE_V8_PLATFORM && !HAVE_INSPECTOR |
||
35 |
if (inspector_enabled) { |
||
36 |
errors->push_back("Inspector is not available when Node is compiled " |
||
37 |
"--without-v8-platform and --without-inspector."); |
||
38 |
} |
||
39 |
#endif |
||
40 |
|||
41 |
✓✓ | 9385 |
if (deprecated_debug) { |
42 |
8 |
errors->push_back("[DEP0062]: `node --debug` and `node --debug-brk` " |
|
43 |
"are invalid. Please use `node --inspect` and " |
||
44 |
4 |
"`node --inspect-brk` instead."); |
|
45 |
} |
||
46 |
|||
47 |
std::vector<std::string> destinations = |
||
48 |
18770 |
SplitString(inspect_publish_uid_string, ','); |
|
49 |
9385 |
inspect_publish_uid.console = false; |
|
50 |
9385 |
inspect_publish_uid.http = false; |
|
51 |
✓✓ | 28153 |
for (const std::string& destination : destinations) { |
52 |
✓✓ | 18768 |
if (destination == "stderr") { |
53 |
9384 |
inspect_publish_uid.console = true; |
|
54 |
✓✗ | 9384 |
} else if (destination == "http") { |
55 |
9384 |
inspect_publish_uid.http = true; |
|
56 |
} else { |
||
57 |
errors->push_back("--inspect-publish-uid destination can be " |
||
58 |
"stderr or http"); |
||
59 |
} |
||
60 |
} |
||
61 |
9385 |
} |
|
62 |
|||
63 |
9181 |
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) { |
|
64 |
#if HAVE_OPENSSL |
||
65 |
✓✓✓✓ |
9181 |
if (use_openssl_ca && use_bundled_ca) { |
66 |
2 |
errors->push_back("either --use-openssl-ca or --use-bundled-ca can be " |
|
67 |
1 |
"used, not both"); |
|
68 |
} |
||
69 |
|||
70 |
// Any value less than 2 disables use of the secure heap. |
||
71 |
✓✓ | 9181 |
if (secure_heap >= 2) { |
72 |
✓✓ | 2 |
if ((secure_heap & (secure_heap - 1)) != 0) |
73 |
1 |
errors->push_back("--secure-heap must be a power of 2"); |
|
74 |
2 |
secure_heap_min = |
|
75 |
6 |
std::min({ |
|
76 |
2 |
secure_heap, |
|
77 |
2 |
secure_heap_min, |
|
78 |
static_cast<int64_t>(std::numeric_limits<int>::max())}); |
||
79 |
2 |
secure_heap_min = std::max(static_cast<int64_t>(2), secure_heap_min); |
|
80 |
✓✓ | 2 |
if ((secure_heap_min & (secure_heap_min - 1)) != 0) |
81 |
1 |
errors->push_back("--secure-heap-min must be a power of 2"); |
|
82 |
} |
||
83 |
#endif |
||
84 |
✓✓✓✓ |
18364 |
if (use_largepages != "off" && |
85 |
✓✓✓✗ |
9182 |
use_largepages != "on" && |
86 |
1 |
use_largepages != "silent") { |
|
87 |
1 |
errors->push_back("invalid value for --use-largepages"); |
|
88 |
} |
||
89 |
9181 |
per_isolate->CheckOptions(errors); |
|
90 |
9181 |
} |
|
91 |
|||
92 |
9385 |
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) { |
|
93 |
9385 |
per_env->CheckOptions(errors); |
|
94 |
9385 |
} |
|
95 |
|||
96 |
9385 |
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { |
|
97 |
✓✓✗✓ ✗✓ |
9385 |
if (has_policy_integrity_string && experimental_policy.empty()) { |
98 |
errors->push_back("--policy-integrity requires " |
||
99 |
"--experimental-policy be enabled"); |
||
100 |
} |
||
101 |
✓✓✓✓ ✓✓ |
9385 |
if (has_policy_integrity_string && experimental_policy_integrity.empty()) { |
102 |
1 |
errors->push_back("--policy-integrity cannot be empty"); |
|
103 |
} |
||
104 |
|||
105 |
✓✓ | 9385 |
if (!module_type.empty()) { |
106 |
✓✗✗✓ ✗✓ |
20 |
if (module_type != "commonjs" && module_type != "module") { |
107 |
errors->push_back("--input-type must be \"module\" or \"commonjs\""); |
||
108 |
} |
||
109 |
} |
||
110 |
|||
111 |
✓✓ | 9385 |
if (!experimental_specifier_resolution.empty()) { |
112 |
✗✓✗✗ ✗✓ |
10 |
if (experimental_specifier_resolution != "node" && |
113 |
experimental_specifier_resolution != "explicit") { |
||
114 |
errors->push_back( |
||
115 |
"invalid value for --experimental-specifier-resolution"); |
||
116 |
} |
||
117 |
} |
||
118 |
|||
119 |
✓✓✓✓ |
9385 |
if (syntax_check_only && has_eval_string) { |
120 |
4 |
errors->push_back("either --check or --eval can be used, not both"); |
|
121 |
} |
||
122 |
|||
123 |
✓✓✓✓ |
18787 |
if (!unhandled_rejections.empty() && |
124 |
✓✓ | 33 |
unhandled_rejections != "warn-with-error-code" && |
125 |
✓✓ | 30 |
unhandled_rejections != "throw" && |
126 |
✓✓ | 26 |
unhandled_rejections != "strict" && |
127 |
✓✓✓✓ |
9404 |
unhandled_rejections != "warn" && |
128 |
7 |
unhandled_rejections != "none") { |
|
129 |
1 |
errors->push_back("invalid value for --unhandled-rejections"); |
|
130 |
} |
||
131 |
|||
132 |
✓✓✓✓ |
9385 |
if (tls_min_v1_3 && tls_max_v1_2) { |
133 |
2 |
errors->push_back("either --tls-min-v1.3 or --tls-max-v1.2 can be " |
|
134 |
1 |
"used, not both"); |
|
135 |
} |
||
136 |
|||
137 |
✓✓ | 9385 |
if (heap_snapshot_near_heap_limit < 0) { |
138 |
1 |
errors->push_back("--heap-snapshot-near-heap-limit must not be negative"); |
|
139 |
} |
||
140 |
|||
141 |
#if HAVE_INSPECTOR |
||
142 |
✓✓ | 9385 |
if (!cpu_prof) { |
143 |
✓✓ | 9374 |
if (!cpu_prof_name.empty()) { |
144 |
1 |
errors->push_back("--cpu-prof-name must be used with --cpu-prof"); |
|
145 |
} |
||
146 |
✗✓ | 9374 |
if (!cpu_prof_dir.empty()) { |
147 |
errors->push_back("--cpu-prof-dir must be used with --cpu-prof"); |
||
148 |
} |
||
149 |
// We can't catch the case where the value passed is the default value, |
||
150 |
// then the option just becomes a noop which is fine. |
||
151 |
✗✓ | 9374 |
if (cpu_prof_interval != kDefaultCpuProfInterval) { |
152 |
errors->push_back("--cpu-prof-interval must be used with --cpu-prof"); |
||
153 |
} |
||
154 |
} |
||
155 |
|||
156 |
✓✓✓✓ ✓✓✓✓ |
9385 |
if (cpu_prof && cpu_prof_dir.empty() && !diagnostic_dir.empty()) { |
157 |
1 |
cpu_prof_dir = diagnostic_dir; |
|
158 |
} |
||
159 |
|||
160 |
✓✓ | 9385 |
if (!heap_prof) { |
161 |
✓✓ | 9379 |
if (!heap_prof_name.empty()) { |
162 |
1 |
errors->push_back("--heap-prof-name must be used with --heap-prof"); |
|
163 |
} |
||
164 |
✗✓ | 9379 |
if (!heap_prof_dir.empty()) { |
165 |
errors->push_back("--heap-prof-dir must be used with --heap-prof"); |
||
166 |
} |
||
167 |
// We can't catch the case where the value passed is the default value, |
||
168 |
// then the option just becomes a noop which is fine. |
||
169 |
✗✓ | 9379 |
if (heap_prof_interval != kDefaultHeapProfInterval) { |
170 |
errors->push_back("--heap-prof-interval must be used with --heap-prof"); |
||
171 |
} |
||
172 |
} |
||
173 |
|||
174 |
✓✓✓✓ ✓✓✓✓ |
9385 |
if (heap_prof && heap_prof_dir.empty() && !diagnostic_dir.empty()) { |
175 |
1 |
heap_prof_dir = diagnostic_dir; |
|
176 |
} |
||
177 |
|||
178 |
9385 |
debug_options_.CheckOptions(errors); |
|
179 |
#endif // HAVE_INSPECTOR |
||
180 |
9385 |
} |
|
181 |
|||
182 |
namespace options_parser { |
||
183 |
|||
184 |
4665 |
class DebugOptionsParser : public OptionsParser<DebugOptions> { |
|
185 |
public: |
||
186 |
DebugOptionsParser(); |
||
187 |
}; |
||
188 |
|||
189 |
4665 |
class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> { |
|
190 |
public: |
||
191 |
EnvironmentOptionsParser(); |
||
192 |
4665 |
explicit EnvironmentOptionsParser(const DebugOptionsParser& dop) |
|
193 |
4665 |
: EnvironmentOptionsParser() { |
|
194 |
4665 |
Insert(dop, &EnvironmentOptions::get_debug_options); |
|
195 |
4665 |
} |
|
196 |
}; |
||
197 |
|||
198 |
4665 |
class PerIsolateOptionsParser : public OptionsParser<PerIsolateOptions> { |
|
199 |
public: |
||
200 |
PerIsolateOptionsParser() = delete; |
||
201 |
explicit PerIsolateOptionsParser(const EnvironmentOptionsParser& eop); |
||
202 |
}; |
||
203 |
|||
204 |
4665 |
class PerProcessOptionsParser : public OptionsParser<PerProcessOptions> { |
|
205 |
public: |
||
206 |
PerProcessOptionsParser() = delete; |
||
207 |
explicit PerProcessOptionsParser(const PerIsolateOptionsParser& iop); |
||
208 |
}; |
||
209 |
|||
210 |
#if HAVE_INSPECTOR |
||
211 |
4665 |
const DebugOptionsParser _dop_instance{}; |
|
212 |
4665 |
const EnvironmentOptionsParser _eop_instance{_dop_instance}; |
|
213 |
|||
214 |
// This Parse is not dead code. It is used by embedders (e.g., Electron). |
||
215 |
template <> |
||
216 |
void Parse( |
||
217 |
StringVector* const args, StringVector* const exec_args, |
||
218 |
StringVector* const v8_args, |
||
219 |
DebugOptions* const options, |
||
220 |
OptionEnvvarSettings required_env_settings, StringVector* const errors) { |
||
221 |
_dop_instance.Parse( |
||
222 |
args, exec_args, v8_args, options, required_env_settings, errors); |
||
223 |
} |
||
224 |
#else |
||
225 |
const EnvironmentOptionsParser _eop_instance{}; |
||
226 |
#endif // HAVE_INSPECTOR |
||
227 |
4665 |
const PerIsolateOptionsParser _piop_instance{_eop_instance}; |
|
228 |
4665 |
const PerProcessOptionsParser _ppop_instance{_piop_instance}; |
|
229 |
|||
230 |
template <> |
||
231 |
204 |
void Parse( |
|
232 |
StringVector* const args, StringVector* const exec_args, |
||
233 |
StringVector* const v8_args, |
||
234 |
PerIsolateOptions* const options, |
||
235 |
OptionEnvvarSettings required_env_settings, StringVector* const errors) { |
||
236 |
_piop_instance.Parse( |
||
237 |
204 |
args, exec_args, v8_args, options, required_env_settings, errors); |
|
238 |
204 |
} |
|
239 |
|||
240 |
template <> |
||
241 |
9181 |
void Parse( |
|
242 |
StringVector* const args, StringVector* const exec_args, |
||
243 |
StringVector* const v8_args, |
||
244 |
PerProcessOptions* const options, |
||
245 |
OptionEnvvarSettings required_env_settings, StringVector* const errors) { |
||
246 |
_ppop_instance.Parse( |
||
247 |
9181 |
args, exec_args, v8_args, options, required_env_settings, errors); |
|
248 |
9181 |
} |
|
249 |
|||
250 |
// XXX: If you add an option here, please also add it to doc/node.1 and |
||
251 |
// doc/api/cli.md |
||
252 |
// TODO(addaleax): Make that unnecessary. |
||
253 |
|||
254 |
4665 |
DebugOptionsParser::DebugOptionsParser() { |
|
255 |
4665 |
AddOption("--inspect-port", |
|
256 |
"set host:port for inspector", |
||
257 |
&DebugOptions::host_port, |
||
258 |
4665 |
kAllowedInEnvironment); |
|
259 |
4665 |
AddAlias("--debug-port", "--inspect-port"); |
|
260 |
|||
261 |
4665 |
AddOption("--inspect", |
|
262 |
"activate inspector on host:port (default: 127.0.0.1:9229)", |
||
263 |
&DebugOptions::inspector_enabled, |
||
264 |
4665 |
kAllowedInEnvironment); |
|
265 |
✓✓ | 4665 |
AddAlias("--inspect=", { "--inspect-port", "--inspect" }); |
266 |
|||
267 |
4665 |
AddOption("--debug", "", &DebugOptions::deprecated_debug); |
|
268 |
4665 |
AddAlias("--debug=", "--debug"); |
|
269 |
4665 |
AddOption("--debug-brk", "", &DebugOptions::deprecated_debug); |
|
270 |
4665 |
AddAlias("--debug-brk=", "--debug-brk"); |
|
271 |
|||
272 |
4665 |
AddOption("--inspect-brk", |
|
273 |
"activate inspector on host:port and break at start of user script", |
||
274 |
&DebugOptions::break_first_line, |
||
275 |
4665 |
kAllowedInEnvironment); |
|
276 |
4665 |
Implies("--inspect-brk", "--inspect"); |
|
277 |
✓✓ | 4665 |
AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" }); |
278 |
|||
279 |
4665 |
AddOption("--inspect-brk-node", "", &DebugOptions::break_node_first_line); |
|
280 |
4665 |
Implies("--inspect-brk-node", "--inspect"); |
|
281 |
✓✓ | 4665 |
AddAlias("--inspect-brk-node=", { "--inspect-port", "--inspect-brk-node" }); |
282 |
|||
283 |
4665 |
AddOption("--inspect-publish-uid", |
|
284 |
"comma separated list of destinations for inspector uid" |
||
285 |
"(default: stderr,http)", |
||
286 |
&DebugOptions::inspect_publish_uid_string, |
||
287 |
4665 |
kAllowedInEnvironment); |
|
288 |
4665 |
} |
|
289 |
|||
290 |
4665 |
EnvironmentOptionsParser::EnvironmentOptionsParser() { |
|
291 |
4665 |
AddOption("--conditions", |
|
292 |
"additional user conditions for conditional exports and imports", |
||
293 |
&EnvironmentOptions::conditions, |
||
294 |
4665 |
kAllowedInEnvironment); |
|
295 |
4665 |
AddOption("--diagnostic-dir", |
|
296 |
"set dir for all output files" |
||
297 |
" (default: current working directory)", |
||
298 |
&EnvironmentOptions::diagnostic_dir, |
||
299 |
4665 |
kAllowedInEnvironment); |
|
300 |
4665 |
AddOption("--enable-source-maps", |
|
301 |
"experimental Source Map V3 support", |
||
302 |
&EnvironmentOptions::enable_source_maps, |
||
303 |
4665 |
kAllowedInEnvironment); |
|
304 |
4665 |
AddOption("--experimental-abortcontroller", "", |
|
305 |
4665 |
NoOp{}, kAllowedInEnvironment); |
|
306 |
4665 |
AddOption("--experimental-json-modules", |
|
307 |
"experimental JSON interop support for the ES Module loader", |
||
308 |
&EnvironmentOptions::experimental_json_modules, |
||
309 |
4665 |
kAllowedInEnvironment); |
|
310 |
4665 |
AddOption("--experimental-loader", |
|
311 |
"use the specified module as a custom loader", |
||
312 |
&EnvironmentOptions::userland_loader, |
||
313 |
4665 |
kAllowedInEnvironment); |
|
314 |
4665 |
AddAlias("--loader", "--experimental-loader"); |
|
315 |
4665 |
AddOption("--experimental-modules", |
|
316 |
"", |
||
317 |
&EnvironmentOptions::experimental_modules, |
||
318 |
4665 |
kAllowedInEnvironment); |
|
319 |
4665 |
AddOption("--experimental-wasm-modules", |
|
320 |
"experimental ES Module support for webassembly modules", |
||
321 |
&EnvironmentOptions::experimental_wasm_modules, |
||
322 |
4665 |
kAllowedInEnvironment); |
|
323 |
4665 |
AddOption("--experimental-import-meta-resolve", |
|
324 |
"experimental ES Module import.meta.resolve() support", |
||
325 |
&EnvironmentOptions::experimental_import_meta_resolve, |
||
326 |
4665 |
kAllowedInEnvironment); |
|
327 |
4665 |
AddOption("--experimental-policy", |
|
328 |
"use the specified file as a " |
||
329 |
"security policy", |
||
330 |
&EnvironmentOptions::experimental_policy, |
||
331 |
4665 |
kAllowedInEnvironment); |
|
332 |
4665 |
AddOption("[has_policy_integrity_string]", |
|
333 |
"", |
||
334 |
4665 |
&EnvironmentOptions::has_policy_integrity_string); |
|
335 |
4665 |
AddOption("--policy-integrity", |
|
336 |
"ensure the security policy contents match " |
||
337 |
"the specified integrity", |
||
338 |
&EnvironmentOptions::experimental_policy_integrity, |
||
339 |
4665 |
kAllowedInEnvironment); |
|
340 |
4665 |
Implies("--policy-integrity", "[has_policy_integrity_string]"); |
|
341 |
4665 |
AddOption("--experimental-repl-await", |
|
342 |
"experimental await keyword support in REPL", |
||
343 |
&EnvironmentOptions::experimental_repl_await, |
||
344 |
4665 |
kAllowedInEnvironment); |
|
345 |
4665 |
AddOption("--experimental-vm-modules", |
|
346 |
"experimental ES Module support in vm module", |
||
347 |
&EnvironmentOptions::experimental_vm_modules, |
||
348 |
4665 |
kAllowedInEnvironment); |
|
349 |
4665 |
AddOption("--experimental-worker", "", NoOp{}, kAllowedInEnvironment); |
|
350 |
4665 |
AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvironment); |
|
351 |
4665 |
AddOption("--experimental-wasi-unstable-preview1", |
|
352 |
"experimental WASI support", |
||
353 |
&EnvironmentOptions::experimental_wasi, |
||
354 |
4665 |
kAllowedInEnvironment); |
|
355 |
4665 |
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals); |
|
356 |
4665 |
AddOption("--frozen-intrinsics", |
|
357 |
"experimental frozen intrinsics support", |
||
358 |
&EnvironmentOptions::frozen_intrinsics, |
||
359 |
4665 |
kAllowedInEnvironment); |
|
360 |
4665 |
AddOption("--heapsnapshot-signal", |
|
361 |
"Generate heap snapshot on specified signal", |
||
362 |
&EnvironmentOptions::heap_snapshot_signal, |
||
363 |
4665 |
kAllowedInEnvironment); |
|
364 |
4665 |
AddOption("--heapsnapshot-near-heap-limit", |
|
365 |
"Generate heap snapshots whenever V8 is approaching " |
||
366 |
"the heap limit. No more than the specified number of " |
||
367 |
"heap snapshots will be generated.", |
||
368 |
&EnvironmentOptions::heap_snapshot_near_heap_limit, |
||
369 |
4665 |
kAllowedInEnvironment); |
|
370 |
4665 |
AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment); |
|
371 |
4665 |
AddOption("--insecure-http-parser", |
|
372 |
"use an insecure HTTP parser that accepts invalid HTTP headers", |
||
373 |
&EnvironmentOptions::insecure_http_parser, |
||
374 |
4665 |
kAllowedInEnvironment); |
|
375 |
4665 |
AddOption("--input-type", |
|
376 |
"set module type for string input", |
||
377 |
&EnvironmentOptions::module_type, |
||
378 |
4665 |
kAllowedInEnvironment); |
|
379 |
4665 |
AddOption("--experimental-specifier-resolution", |
|
380 |
"Select extension resolution algorithm for es modules; " |
||
381 |
"either 'explicit' (default) or 'node'", |
||
382 |
&EnvironmentOptions::experimental_specifier_resolution, |
||
383 |
4665 |
kAllowedInEnvironment); |
|
384 |
4665 |
AddAlias("--es-module-specifier-resolution", |
|
385 |
4665 |
"--experimental-specifier-resolution"); |
|
386 |
4665 |
AddOption("--no-deprecation", |
|
387 |
"silence deprecation warnings", |
||
388 |
&EnvironmentOptions::no_deprecation, |
||
389 |
4665 |
kAllowedInEnvironment); |
|
390 |
4665 |
AddOption("--no-force-async-hooks-checks", |
|
391 |
"disable checks for async_hooks", |
||
392 |
&EnvironmentOptions::no_force_async_hooks_checks, |
||
393 |
4665 |
kAllowedInEnvironment); |
|
394 |
4665 |
AddOption("--no-warnings", |
|
395 |
"silence all process warnings", |
||
396 |
&EnvironmentOptions::no_warnings, |
||
397 |
4665 |
kAllowedInEnvironment); |
|
398 |
4665 |
AddOption("--force-context-aware", |
|
399 |
"disable loading non-context-aware addons", |
||
400 |
&EnvironmentOptions::force_context_aware, |
||
401 |
4665 |
kAllowedInEnvironment); |
|
402 |
4665 |
AddOption("--pending-deprecation", |
|
403 |
"emit pending deprecation warnings", |
||
404 |
&EnvironmentOptions::pending_deprecation, |
||
405 |
4665 |
kAllowedInEnvironment); |
|
406 |
4665 |
AddOption("--preserve-symlinks", |
|
407 |
"preserve symbolic links when resolving", |
||
408 |
&EnvironmentOptions::preserve_symlinks, |
||
409 |
4665 |
kAllowedInEnvironment); |
|
410 |
4665 |
AddOption("--preserve-symlinks-main", |
|
411 |
"preserve symbolic links when resolving the main module", |
||
412 |
&EnvironmentOptions::preserve_symlinks_main, |
||
413 |
4665 |
kAllowedInEnvironment); |
|
414 |
4665 |
AddOption("--prof", |
|
415 |
"Generate V8 profiler output.", |
||
416 |
4665 |
V8Option{}); |
|
417 |
4665 |
AddOption("--prof-process", |
|
418 |
"process V8 profiler output generated using --prof", |
||
419 |
4665 |
&EnvironmentOptions::prof_process); |
|
420 |
// Options after --prof-process are passed through to the prof processor. |
||
421 |
✓✓ | 4665 |
AddAlias("--prof-process", { "--prof-process", "--" }); |
422 |
#if HAVE_INSPECTOR |
||
423 |
4665 |
AddOption("--cpu-prof", |
|
424 |
"Start the V8 CPU profiler on start up, and write the CPU profile " |
||
425 |
"to disk before exit. If --cpu-prof-dir is not specified, write " |
||
426 |
"the profile to the current working directory.", |
||
427 |
4665 |
&EnvironmentOptions::cpu_prof); |
|
428 |
4665 |
AddOption("--cpu-prof-name", |
|
429 |
"specified file name of the V8 CPU profile generated with " |
||
430 |
"--cpu-prof", |
||
431 |
4665 |
&EnvironmentOptions::cpu_prof_name); |
|
432 |
4665 |
AddOption("--cpu-prof-interval", |
|
433 |
"specified sampling interval in microseconds for the V8 CPU " |
||
434 |
"profile generated with --cpu-prof. (default: 1000)", |
||
435 |
4665 |
&EnvironmentOptions::cpu_prof_interval); |
|
436 |
4665 |
AddOption("--cpu-prof-dir", |
|
437 |
"Directory where the V8 profiles generated by --cpu-prof will be " |
||
438 |
"placed. Does not affect --prof.", |
||
439 |
4665 |
&EnvironmentOptions::cpu_prof_dir); |
|
440 |
4665 |
AddOption( |
|
441 |
"--heap-prof", |
||
442 |
"Start the V8 heap profiler on start up, and write the heap profile " |
||
443 |
"to disk before exit. If --heap-prof-dir is not specified, write " |
||
444 |
"the profile to the current working directory.", |
||
445 |
4665 |
&EnvironmentOptions::heap_prof); |
|
446 |
4665 |
AddOption("--heap-prof-name", |
|
447 |
"specified file name of the V8 heap profile generated with " |
||
448 |
"--heap-prof", |
||
449 |
4665 |
&EnvironmentOptions::heap_prof_name); |
|
450 |
4665 |
AddOption("--heap-prof-dir", |
|
451 |
"Directory where the V8 heap profiles generated by --heap-prof " |
||
452 |
"will be placed.", |
||
453 |
4665 |
&EnvironmentOptions::heap_prof_dir); |
|
454 |
4665 |
AddOption("--heap-prof-interval", |
|
455 |
"specified sampling interval in bytes for the V8 heap " |
||
456 |
"profile generated with --heap-prof. (default: 512 * 1024)", |
||
457 |
4665 |
&EnvironmentOptions::heap_prof_interval); |
|
458 |
#endif // HAVE_INSPECTOR |
||
459 |
4665 |
AddOption("--max-http-header-size", |
|
460 |
"set the maximum size of HTTP headers (default: 16384 (16KB))", |
||
461 |
&EnvironmentOptions::max_http_header_size, |
||
462 |
4665 |
kAllowedInEnvironment); |
|
463 |
4665 |
AddOption("--redirect-warnings", |
|
464 |
"write warnings to file instead of stderr", |
||
465 |
&EnvironmentOptions::redirect_warnings, |
||
466 |
4665 |
kAllowedInEnvironment); |
|
467 |
4665 |
AddOption("--test-udp-no-try-send", "", // For testing only. |
|
468 |
4665 |
&EnvironmentOptions::test_udp_no_try_send); |
|
469 |
4665 |
AddOption("--throw-deprecation", |
|
470 |
"throw an exception on deprecations", |
||
471 |
&EnvironmentOptions::throw_deprecation, |
||
472 |
4665 |
kAllowedInEnvironment); |
|
473 |
4665 |
AddOption("--trace-atomics-wait", |
|
474 |
"trace Atomics.wait() operations", |
||
475 |
&EnvironmentOptions::trace_atomics_wait, |
||
476 |
4665 |
kAllowedInEnvironment); |
|
477 |
4665 |
AddOption("--trace-deprecation", |
|
478 |
"show stack traces on deprecations", |
||
479 |
&EnvironmentOptions::trace_deprecation, |
||
480 |
4665 |
kAllowedInEnvironment); |
|
481 |
4665 |
AddOption("--trace-exit", |
|
482 |
"show stack trace when an environment exits", |
||
483 |
&EnvironmentOptions::trace_exit, |
||
484 |
4665 |
kAllowedInEnvironment); |
|
485 |
4665 |
AddOption("--trace-sync-io", |
|
486 |
"show stack trace when use of sync IO is detected after the " |
||
487 |
"first tick", |
||
488 |
&EnvironmentOptions::trace_sync_io, |
||
489 |
4665 |
kAllowedInEnvironment); |
|
490 |
4665 |
AddOption("--trace-tls", |
|
491 |
"prints TLS packet trace information to stderr", |
||
492 |
&EnvironmentOptions::trace_tls, |
||
493 |
4665 |
kAllowedInEnvironment); |
|
494 |
4665 |
AddOption("--trace-uncaught", |
|
495 |
"show stack traces for the `throw` behind uncaught exceptions", |
||
496 |
&EnvironmentOptions::trace_uncaught, |
||
497 |
4665 |
kAllowedInEnvironment); |
|
498 |
4665 |
AddOption("--trace-warnings", |
|
499 |
"show stack traces on process warnings", |
||
500 |
&EnvironmentOptions::trace_warnings, |
||
501 |
4665 |
kAllowedInEnvironment); |
|
502 |
4665 |
AddOption("--unhandled-rejections", |
|
503 |
"define unhandled rejections behavior. Options are 'strict' (raise " |
||
504 |
"an error), 'warn' (enforce warnings) or 'none' (silence warnings)", |
||
505 |
&EnvironmentOptions::unhandled_rejections, |
||
506 |
4665 |
kAllowedInEnvironment); |
|
507 |
4665 |
AddOption("--verify-base-objects", |
|
508 |
"", /* undocumented, only for debugging */ |
||
509 |
&EnvironmentOptions::verify_base_objects, |
||
510 |
4665 |
kAllowedInEnvironment); |
|
511 |
|||
512 |
4665 |
AddOption("--check", |
|
513 |
"syntax check script without executing", |
||
514 |
4665 |
&EnvironmentOptions::syntax_check_only); |
|
515 |
4665 |
AddAlias("-c", "--check"); |
|
516 |
// This option is only so that we can tell --eval with an empty string from |
||
517 |
// no eval at all. Having it not start with a dash makes it inaccessible |
||
518 |
// from the parser itself, but available for using Implies(). |
||
519 |
// TODO(addaleax): When moving --help over to something generated from the |
||
520 |
// programmatic descriptions, this will need some special care. |
||
521 |
// (See also [ssl_openssl_cert_store] below.) |
||
522 |
4665 |
AddOption("[has_eval_string]", "", &EnvironmentOptions::has_eval_string); |
|
523 |
4665 |
AddOption("--eval", "evaluate script", &EnvironmentOptions::eval_string); |
|
524 |
4665 |
Implies("--eval", "[has_eval_string]"); |
|
525 |
4665 |
AddOption("--print", |
|
526 |
"evaluate script and print result", |
||
527 |
4665 |
&EnvironmentOptions::print_eval); |
|
528 |
4665 |
AddAlias("-e", "--eval"); |
|
529 |
4665 |
AddAlias("--print <arg>", "-pe"); |
|
530 |
✓✓ | 4665 |
AddAlias("-pe", { "--print", "--eval" }); |
531 |
4665 |
AddAlias("-p", "--print"); |
|
532 |
4665 |
AddOption("--require", |
|
533 |
"module to preload (option can be repeated)", |
||
534 |
&EnvironmentOptions::preload_modules, |
||
535 |
4665 |
kAllowedInEnvironment); |
|
536 |
4665 |
AddAlias("-r", "--require"); |
|
537 |
4665 |
AddOption("--interactive", |
|
538 |
"always enter the REPL even if stdin does not appear " |
||
539 |
"to be a terminal", |
||
540 |
4665 |
&EnvironmentOptions::force_repl); |
|
541 |
4665 |
AddAlias("-i", "--interactive"); |
|
542 |
|||
543 |
4665 |
AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment); |
|
544 |
|||
545 |
4665 |
AddOption("--tls-keylog", |
|
546 |
"log TLS decryption keys to named file for traffic analysis", |
||
547 |
4665 |
&EnvironmentOptions::tls_keylog, kAllowedInEnvironment); |
|
548 |
|||
549 |
4665 |
AddOption("--tls-min-v1.0", |
|
550 |
"set default TLS minimum to TLSv1.0 (default: TLSv1.2)", |
||
551 |
&EnvironmentOptions::tls_min_v1_0, |
||
552 |
4665 |
kAllowedInEnvironment); |
|
553 |
4665 |
AddOption("--tls-min-v1.1", |
|
554 |
"set default TLS minimum to TLSv1.1 (default: TLSv1.2)", |
||
555 |
&EnvironmentOptions::tls_min_v1_1, |
||
556 |
4665 |
kAllowedInEnvironment); |
|
557 |
4665 |
AddOption("--tls-min-v1.2", |
|
558 |
"set default TLS minimum to TLSv1.2 (default: TLSv1.2)", |
||
559 |
&EnvironmentOptions::tls_min_v1_2, |
||
560 |
4665 |
kAllowedInEnvironment); |
|
561 |
4665 |
AddOption("--tls-min-v1.3", |
|
562 |
"set default TLS minimum to TLSv1.3 (default: TLSv1.2)", |
||
563 |
&EnvironmentOptions::tls_min_v1_3, |
||
564 |
4665 |
kAllowedInEnvironment); |
|
565 |
4665 |
AddOption("--tls-max-v1.2", |
|
566 |
"set default TLS maximum to TLSv1.2 (default: TLSv1.3)", |
||
567 |
&EnvironmentOptions::tls_max_v1_2, |
||
568 |
4665 |
kAllowedInEnvironment); |
|
569 |
// Current plan is: |
||
570 |
// - 11.x and below: TLS1.3 is opt-in with --tls-max-v1.3 |
||
571 |
// - 12.x: TLS1.3 is opt-out with --tls-max-v1.2 |
||
572 |
// In either case, support both options they are uniformly available. |
||
573 |
4665 |
AddOption("--tls-max-v1.3", |
|
574 |
"set default TLS maximum to TLSv1.3 (default: TLSv1.3)", |
||
575 |
&EnvironmentOptions::tls_max_v1_3, |
||
576 |
4665 |
kAllowedInEnvironment); |
|
577 |
4665 |
} |
|
578 |
|||
579 |
4665 |
PerIsolateOptionsParser::PerIsolateOptionsParser( |
|
580 |
4665 |
const EnvironmentOptionsParser& eop) { |
|
581 |
4665 |
AddOption("--track-heap-objects", |
|
582 |
"track heap object allocations for heap snapshots", |
||
583 |
&PerIsolateOptions::track_heap_objects, |
||
584 |
4665 |
kAllowedInEnvironment); |
|
585 |
4665 |
AddOption("--no-node-snapshot", |
|
586 |
"", // It's a debug-only option. |
||
587 |
&PerIsolateOptions::no_node_snapshot, |
||
588 |
4665 |
kAllowedInEnvironment); |
|
589 |
|||
590 |
// Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS. |
||
591 |
4665 |
AddOption("--abort-on-uncaught-exception", |
|
592 |
"aborting instead of exiting causes a core file to be generated " |
||
593 |
"for analysis", |
||
594 |
4665 |
V8Option{}, |
|
595 |
4665 |
kAllowedInEnvironment); |
|
596 |
4665 |
AddOption("--interpreted-frames-native-stack", |
|
597 |
"help system profilers to translate JavaScript interpreted frames", |
||
598 |
4665 |
V8Option{}, kAllowedInEnvironment); |
|
599 |
4665 |
AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvironment); |
|
600 |
4665 |
AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvironment); |
|
601 |
4665 |
AddOption("--perf-basic-prof-only-functions", |
|
602 |
"", |
||
603 |
4665 |
V8Option{}, |
|
604 |
4665 |
kAllowedInEnvironment); |
|
605 |
4665 |
AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvironment); |
|
606 |
4665 |
AddOption("--perf-prof-unwinding-info", |
|
607 |
"", |
||
608 |
4665 |
V8Option{}, |
|
609 |
4665 |
kAllowedInEnvironment); |
|
610 |
4665 |
AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment); |
|
611 |
4665 |
AddOption("--disallow-code-generation-from-strings", |
|
612 |
"disallow eval and friends", |
||
613 |
4665 |
V8Option{}, |
|
614 |
4665 |
kAllowedInEnvironment); |
|
615 |
4665 |
AddOption("--huge-max-old-generation-size", |
|
616 |
"increase default maximum heap size on machines with 16GB memory " |
||
617 |
"or more", |
||
618 |
4665 |
V8Option{}, |
|
619 |
4665 |
kAllowedInEnvironment); |
|
620 |
4665 |
AddOption("--jitless", |
|
621 |
"disable runtime allocation of executable memory", |
||
622 |
4665 |
V8Option{}, |
|
623 |
4665 |
kAllowedInEnvironment); |
|
624 |
4665 |
AddOption("--report-uncaught-exception", |
|
625 |
"generate diagnostic report on uncaught exceptions", |
||
626 |
&PerIsolateOptions::report_uncaught_exception, |
||
627 |
4665 |
kAllowedInEnvironment); |
|
628 |
4665 |
AddOption("--report-on-signal", |
|
629 |
"generate diagnostic report upon receiving signals", |
||
630 |
&PerIsolateOptions::report_on_signal, |
||
631 |
4665 |
kAllowedInEnvironment); |
|
632 |
4665 |
AddOption("--report-signal", |
|
633 |
"causes diagnostic report to be produced on provided signal," |
||
634 |
" unsupported in Windows. (default: SIGUSR2)", |
||
635 |
&PerIsolateOptions::report_signal, |
||
636 |
4665 |
kAllowedInEnvironment); |
|
637 |
4665 |
Implies("--report-signal", "--report-on-signal"); |
|
638 |
|||
639 |
4665 |
AddOption("--experimental-top-level-await", |
|
640 |
"", |
||
641 |
&PerIsolateOptions::experimental_top_level_await, |
||
642 |
4665 |
kAllowedInEnvironment); |
|
643 |
4665 |
AddOption("--harmony-top-level-await", "", V8Option{}); |
|
644 |
4665 |
Implies("--experimental-top-level-await", "--harmony-top-level-await"); |
|
645 |
4665 |
Implies("--harmony-top-level-await", "--experimental-top-level-await"); |
|
646 |
4665 |
ImpliesNot("--no-harmony-top-level-await", "--experimental-top-level-await"); |
|
647 |
|||
648 |
4665 |
Insert(eop, &PerIsolateOptions::get_per_env_options); |
|
649 |
4665 |
} |
|
650 |
|||
651 |
4665 |
PerProcessOptionsParser::PerProcessOptionsParser( |
|
652 |
4665 |
const PerIsolateOptionsParser& iop) { |
|
653 |
4665 |
AddOption("--title", |
|
654 |
"the process title to use on startup", |
||
655 |
&PerProcessOptions::title, |
||
656 |
4665 |
kAllowedInEnvironment); |
|
657 |
4665 |
AddOption("--trace-event-categories", |
|
658 |
"comma separated list of trace event categories to record", |
||
659 |
&PerProcessOptions::trace_event_categories, |
||
660 |
4665 |
kAllowedInEnvironment); |
|
661 |
4665 |
AddOption("--trace-event-file-pattern", |
|
662 |
"Template string specifying the filepath for the trace-events " |
||
663 |
"data, it supports ${rotation} and ${pid}.", |
||
664 |
&PerProcessOptions::trace_event_file_pattern, |
||
665 |
4665 |
kAllowedInEnvironment); |
|
666 |
✓✓ | 18660 |
AddAlias("--trace-events-enabled", { |
667 |
13995 |
"--trace-event-categories", "v8,node,node.async_hooks" }); |
|
668 |
4665 |
AddOption("--v8-pool-size", |
|
669 |
"set V8's thread pool size", |
||
670 |
&PerProcessOptions::v8_thread_pool_size, |
||
671 |
4665 |
kAllowedInEnvironment); |
|
672 |
4665 |
AddOption("--zero-fill-buffers", |
|
673 |
"automatically zero-fill all newly allocated Buffer and " |
||
674 |
"SlowBuffer instances", |
||
675 |
&PerProcessOptions::zero_fill_all_buffers, |
||
676 |
4665 |
kAllowedInEnvironment); |
|
677 |
4665 |
AddOption("--debug-arraybuffer-allocations", |
|
678 |
"", /* undocumented, only for debugging */ |
||
679 |
&PerProcessOptions::debug_arraybuffer_allocations, |
||
680 |
4665 |
kAllowedInEnvironment); |
|
681 |
4665 |
AddOption("--disable-proto", |
|
682 |
"disable Object.prototype.__proto__", |
||
683 |
&PerProcessOptions::disable_proto, |
||
684 |
4665 |
kAllowedInEnvironment); |
|
685 |
|||
686 |
// 12.x renamed this inadvertently, so alias it for consistency within the |
||
687 |
// release line, while using the original name for consistency with older |
||
688 |
// release lines. |
||
689 |
4665 |
AddOption("--security-revert", "", &PerProcessOptions::security_reverts); |
|
690 |
4665 |
AddAlias("--security-reverts", "--security-revert"); |
|
691 |
4665 |
AddOption("--completion-bash", |
|
692 |
"print source-able bash completion script", |
||
693 |
4665 |
&PerProcessOptions::print_bash_completion); |
|
694 |
4665 |
AddOption("--help", |
|
695 |
"print node command line options", |
||
696 |
4665 |
&PerProcessOptions::print_help); |
|
697 |
4665 |
AddAlias("-h", "--help"); |
|
698 |
4665 |
AddOption( |
|
699 |
4665 |
"--version", "print Node.js version", &PerProcessOptions::print_version); |
|
700 |
4665 |
AddAlias("-v", "--version"); |
|
701 |
4665 |
AddOption("--v8-options", |
|
702 |
"print V8 command line options", |
||
703 |
4665 |
&PerProcessOptions::print_v8_help); |
|
704 |
4665 |
AddOption("--report-compact", |
|
705 |
"output compact single-line JSON", |
||
706 |
&PerProcessOptions::report_compact, |
||
707 |
4665 |
kAllowedInEnvironment); |
|
708 |
4665 |
AddOption("--report-dir", |
|
709 |
"define custom report pathname." |
||
710 |
" (default: current working directory)", |
||
711 |
&PerProcessOptions::report_directory, |
||
712 |
4665 |
kAllowedInEnvironment); |
|
713 |
4665 |
AddAlias("--report-directory", "--report-dir"); |
|
714 |
4665 |
AddOption("--report-filename", |
|
715 |
"define custom report file name." |
||
716 |
" (default: YYYYMMDD.HHMMSS.PID.SEQUENCE#.txt)", |
||
717 |
&PerProcessOptions::report_filename, |
||
718 |
4665 |
kAllowedInEnvironment); |
|
719 |
4665 |
AddOption("--report-on-fatalerror", |
|
720 |
"generate diagnostic report on fatal (internal) errors", |
||
721 |
&PerProcessOptions::report_on_fatalerror, |
||
722 |
4665 |
kAllowedInEnvironment); |
|
723 |
|||
724 |
#ifdef NODE_HAVE_I18N_SUPPORT |
||
725 |
4665 |
AddOption("--icu-data-dir", |
|
726 |
"set ICU data load path to dir (overrides NODE_ICU_DATA)" |
||
727 |
#ifndef NODE_HAVE_SMALL_ICU |
||
728 |
" (note: linked-in ICU data is present)\n" |
||
729 |
#endif |
||
730 |
, |
||
731 |
&PerProcessOptions::icu_data_dir, |
||
732 |
4665 |
kAllowedInEnvironment); |
|
733 |
#endif |
||
734 |
|||
735 |
#if HAVE_OPENSSL |
||
736 |
4665 |
AddOption("--openssl-config", |
|
737 |
"load OpenSSL configuration from the specified file " |
||
738 |
"(overrides OPENSSL_CONF)", |
||
739 |
&PerProcessOptions::openssl_config, |
||
740 |
4665 |
kAllowedInEnvironment); |
|
741 |
4665 |
AddOption("--tls-cipher-list", |
|
742 |
"use an alternative default TLS cipher list", |
||
743 |
&PerProcessOptions::tls_cipher_list, |
||
744 |
4665 |
kAllowedInEnvironment); |
|
745 |
4665 |
AddOption("--use-openssl-ca", |
|
746 |
"use OpenSSL's default CA store" |
||
747 |
#if defined(NODE_OPENSSL_CERT_STORE) |
||
748 |
" (default)" |
||
749 |
#endif |
||
750 |
, |
||
751 |
&PerProcessOptions::use_openssl_ca, |
||
752 |
4665 |
kAllowedInEnvironment); |
|
753 |
4665 |
AddOption("--use-bundled-ca", |
|
754 |
"use bundled CA store" |
||
755 |
#if !defined(NODE_OPENSSL_CERT_STORE) |
||
756 |
" (default)" |
||
757 |
#endif |
||
758 |
, |
||
759 |
&PerProcessOptions::use_bundled_ca, |
||
760 |
4665 |
kAllowedInEnvironment); |
|
761 |
// Similar to [has_eval_string] above, except that the separation between |
||
762 |
// this and use_openssl_ca only exists for option validation after parsing. |
||
763 |
// This is not ideal. |
||
764 |
4665 |
AddOption("[ssl_openssl_cert_store]", |
|
765 |
"", |
||
766 |
4665 |
&PerProcessOptions::ssl_openssl_cert_store); |
|
767 |
4665 |
Implies("--use-openssl-ca", "[ssl_openssl_cert_store]"); |
|
768 |
4665 |
ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]"); |
|
769 |
#if NODE_FIPS_MODE |
||
770 |
AddOption("--enable-fips", |
||
771 |
"enable FIPS crypto at startup", |
||
772 |
&PerProcessOptions::enable_fips_crypto, |
||
773 |
kAllowedInEnvironment); |
||
774 |
AddOption("--force-fips", |
||
775 |
"force FIPS crypto (cannot be disabled)", |
||
776 |
&PerProcessOptions::force_fips_crypto, |
||
777 |
kAllowedInEnvironment); |
||
778 |
#endif |
||
779 |
4665 |
AddOption("--secure-heap", |
|
780 |
"total size of the OpenSSL secure heap", |
||
781 |
&PerProcessOptions::secure_heap, |
||
782 |
4665 |
kAllowedInEnvironment); |
|
783 |
4665 |
AddOption("--secure-heap-min", |
|
784 |
"minimum allocation size from the OpenSSL secure heap", |
||
785 |
&PerProcessOptions::secure_heap_min, |
||
786 |
4665 |
kAllowedInEnvironment); |
|
787 |
#endif |
||
788 |
4665 |
AddOption("--use-largepages", |
|
789 |
"Map the Node.js static code to large pages. Options are " |
||
790 |
"'off' (the default value, meaning do not map), " |
||
791 |
"'on' (map and ignore failure, reporting it to stderr), " |
||
792 |
"or 'silent' (map and silently ignore failure)", |
||
793 |
&PerProcessOptions::use_largepages, |
||
794 |
4665 |
kAllowedInEnvironment); |
|
795 |
|||
796 |
4665 |
AddOption("--trace-sigint", |
|
797 |
"enable printing JavaScript stacktrace on SIGINT", |
||
798 |
&PerProcessOptions::trace_sigint, |
||
799 |
4665 |
kAllowedInEnvironment); |
|
800 |
|||
801 |
4665 |
Insert(iop, &PerProcessOptions::get_per_isolate_options); |
|
802 |
|||
803 |
4665 |
AddOption("--node-memory-debug", |
|
804 |
"Run with extra debug checks for memory leaks in Node.js itself", |
||
805 |
4665 |
NoOp{}, kAllowedInEnvironment); |
|
806 |
4665 |
Implies("--node-memory-debug", "--debug-arraybuffer-allocations"); |
|
807 |
4665 |
Implies("--node-memory-debug", "--verify-base-objects"); |
|
808 |
4665 |
} |
|
809 |
|||
810 |
112 |
inline std::string RemoveBrackets(const std::string& host) { |
|
811 |
✓✗✓✓ ✓✓✓✓ |
112 |
if (!host.empty() && host.front() == '[' && host.back() == ']') |
812 |
4 |
return host.substr(1, host.size() - 2); |
|
813 |
else |
||
814 |
108 |
return host; |
|
815 |
} |
||
816 |
|||
817 |
100 |
inline int ParseAndValidatePort(const std::string& port, |
|
818 |
std::vector<std::string>* errors) { |
||
819 |
char* endptr; |
||
820 |
100 |
errno = 0; |
|
821 |
const unsigned long result = // NOLINT(runtime/int) |
||
822 |
100 |
strtoul(port.c_str(), &endptr, 10); |
|
823 |
✓✗✓✗ ✓✓ |
100 |
if (errno != 0 || *endptr != '\0'|| |
824 |
✓✗✗✓ |
63 |
(result != 0 && result < 1024) || result > 65535) { |
825 |
errors->push_back(" must be 0 or in range 1024 to 65535."); |
||
826 |
} |
||
827 |
100 |
return static_cast<int>(result); |
|
828 |
} |
||
829 |
|||
830 |
100 |
HostPort SplitHostPort(const std::string& arg, |
|
831 |
std::vector<std::string>* errors) { |
||
832 |
// remove_brackets only works if no port is specified |
||
833 |
// so if it has an effect only an IPv6 address was specified. |
||
834 |
200 |
std::string host = RemoveBrackets(arg); |
|
835 |
✗✓ | 100 |
if (host.length() < arg.length()) |
836 |
return HostPort{host, DebugOptions::kDefaultInspectorPort}; |
||
837 |
|||
838 |
100 |
size_t colon = arg.rfind(':'); |
|
839 |
✓✓ | 100 |
if (colon == std::string::npos) { |
840 |
// Either a port number or a host name. Assume that |
||
841 |
// if it's not all decimal digits, it's a host name. |
||
842 |
✓✓ | 390 |
for (char c : arg) { |
843 |
✓✗✗✓ |
302 |
if (c < '0' || c > '9') { |
844 |
return HostPort{arg, DebugOptions::kDefaultInspectorPort}; |
||
845 |
} |
||
846 |
} |
||
847 |
88 |
return HostPort { "", ParseAndValidatePort(arg, errors) }; |
|
848 |
} |
||
849 |
// Host and port found: |
||
850 |
24 |
return HostPort { RemoveBrackets(arg.substr(0, colon)), |
|
851 |
12 |
ParseAndValidatePort(arg.substr(colon + 1), errors) }; |
|
852 |
} |
||
853 |
|||
854 |
1 |
std::string GetBashCompletion() { |
|
855 |
2 |
Mutex::ScopedLock lock(per_process::cli_options_mutex); |
|
856 |
1 |
const auto& parser = _ppop_instance; |
|
857 |
|||
858 |
2 |
std::ostringstream out; |
|
859 |
|||
860 |
out << "_node_complete() {\n" |
||
861 |
" local cur_word options\n" |
||
862 |
" cur_word=\"${COMP_WORDS[COMP_CWORD]}\"\n" |
||
863 |
" if [[ \"${cur_word}\" == -* ]] ; then\n" |
||
864 |
1 |
" COMPREPLY=( $(compgen -W '"; |
|
865 |
|||
866 |
✓✓ | 122 |
for (const auto& item : parser.options_) { |
867 |
✓✓ | 121 |
if (item.first[0] != '[') { |
868 |
118 |
out << item.first << " "; |
|
869 |
} |
||
870 |
} |
||
871 |
✓✓ | 22 |
for (const auto& item : parser.aliases_) { |
872 |
✓✗ | 21 |
if (item.first[0] != '[') { |
873 |
21 |
out << item.first << " "; |
|
874 |
} |
||
875 |
} |
||
876 |
✓✗ | 1 |
if (parser.aliases_.size() > 0) { |
877 |
1 |
out.seekp(-1, out.cur); // Strip the trailing space |
|
878 |
} |
||
879 |
|||
880 |
out << "' -- \"${cur_word}\") )\n" |
||
881 |
" return 0\n" |
||
882 |
" else\n" |
||
883 |
" COMPREPLY=( $(compgen -f \"${cur_word}\") )\n" |
||
884 |
" return 0\n" |
||
885 |
" fi\n" |
||
886 |
"}\n" |
||
887 |
"complete -o filenames -o nospace -o bashdefault " |
||
888 |
1 |
"-F _node_complete node node_g"; |
|
889 |
2 |
return out.str(); |
|
890 |
} |
||
891 |
|||
892 |
// Return a map containing all the options and their metadata as well |
||
893 |
// as the aliases |
||
894 |
4989 |
void GetOptions(const FunctionCallbackInfo<Value>& args) { |
|
895 |
9978 |
Mutex::ScopedLock lock(per_process::cli_options_mutex); |
|
896 |
4989 |
Environment* env = Environment::GetCurrent(args); |
|
897 |
✗✓ | 4989 |
if (!env->has_run_bootstrapping_code()) { |
898 |
// No code because this is an assertion. |
||
899 |
return env->ThrowError( |
||
900 |
"Should not query options before bootstrapping is done"); |
||
901 |
} |
||
902 |
4989 |
env->set_has_serialized_options(true); |
|
903 |
|||
904 |
4989 |
Isolate* isolate = env->isolate(); |
|
905 |
4989 |
Local<Context> context = env->context(); |
|
906 |
|||
907 |
// Temporarily act as if the current Environment's/IsolateData's options were |
||
908 |
// the default options, i.e. like they are the ones we'd access for global |
||
909 |
// options parsing, so that all options are available from the main parser. |
||
910 |
✓✗ | 9978 |
auto original_per_isolate = per_process::cli_options->per_isolate; |
911 |
4989 |
per_process::cli_options->per_isolate = env->isolate_data()->options(); |
|
912 |
✓✗ | 9978 |
auto original_per_env = per_process::cli_options->per_isolate->per_env; |
913 |
4989 |
per_process::cli_options->per_isolate->per_env = env->options(); |
|
914 |
4989 |
auto on_scope_leave = OnScopeLeave([&]() { |
|
915 |
4989 |
per_process::cli_options->per_isolate->per_env = original_per_env; |
|
916 |
4989 |
per_process::cli_options->per_isolate = original_per_isolate; |
|
917 |
✓✗ | 14967 |
}); |
918 |
|||
919 |
4989 |
Local<Map> options = Map::New(isolate); |
|
920 |
✓✓ | 608658 |
for (const auto& item : _ppop_instance.options_) { |
921 |
Local<Value> value; |
||
922 |
603669 |
const auto& option_info = item.second; |
|
923 |
1207338 |
auto field = option_info.field; |
|
924 |
603669 |
PerProcessOptions* opts = per_process::cli_options.get(); |
|
925 |
✓✓✓✓ ✓✓✓✗ |
603669 |
switch (option_info.type) { |
926 |
case kNoOp: |
||
927 |
case kV8Option: |
||
928 |
// Special case for --abort-on-uncaught-exception which is also |
||
929 |
// respected by Node.js internals |
||
930 |
✓✓ | 94791 |
if (item.first == "--abort-on-uncaught-exception") { |
931 |
4989 |
value = Boolean::New( |
|
932 |
9978 |
isolate, original_per_env->abort_on_uncaught_exception); |
|
933 |
} else { |
||
934 |
89802 |
value = Undefined(isolate); |
|
935 |
} |
||
936 |
94791 |
break; |
|
937 |
case kBoolean: |
||
938 |
319296 |
value = Boolean::New(isolate, |
|
939 |
638592 |
*_ppop_instance.Lookup<bool>(field, opts)); |
|
940 |
319296 |
break; |
|
941 |
case kInteger: |
||
942 |
19956 |
value = Number::New(isolate, |
|
943 |
39912 |
*_ppop_instance.Lookup<int64_t>(field, opts)); |
|
944 |
19956 |
break; |
|
945 |
case kUInteger: |
||
946 |
14967 |
value = Number::New(isolate, |
|
947 |
29934 |
*_ppop_instance.Lookup<uint64_t>(field, opts)); |
|
948 |
14967 |
break; |
|
949 |
case kString: |
||
950 |
✗✓ | 404109 |
if (!ToV8Value(context, |
951 |
269406 |
*_ppop_instance.Lookup<std::string>(field, opts)) |
|
952 |
134703 |
.ToLocal(&value)) { |
|
953 |
return; |
||
954 |
} |
||
955 |
134703 |
break; |
|
956 |
case kStringList: |
||
957 |
✗✓ | 44901 |
if (!ToV8Value(context, |
958 |
29934 |
*_ppop_instance.Lookup<StringVector>(field, opts)) |
|
959 |
14967 |
.ToLocal(&value)) { |
|
960 |
return; |
||
961 |
} |
||
962 |
14967 |
break; |
|
963 |
case kHostPort: { |
||
964 |
const HostPort& host_port = |
||
965 |
4989 |
*_ppop_instance.Lookup<HostPort>(field, opts); |
|
966 |
4989 |
Local<Object> obj = Object::New(isolate); |
|
967 |
Local<Value> host; |
||
968 |
✓✗✗✓ |
24945 |
if (!ToV8Value(context, host_port.host()).ToLocal(&host) || |
969 |
✓✗✗✓ |
24945 |
obj->Set(context, env->host_string(), host).IsNothing() || |
970 |
9978 |
obj->Set(context, |
|
971 |
env->port_string(), |
||
972 |
19956 |
Integer::New(isolate, host_port.port())) |
|
973 |
4989 |
.IsNothing()) { |
|
974 |
return; |
||
975 |
} |
||
976 |
4989 |
value = obj; |
|
977 |
4989 |
break; |
|
978 |
} |
||
979 |
default: |
||
980 |
UNREACHABLE(); |
||
981 |
} |
||
982 |
✗✓ | 603669 |
CHECK(!value.IsEmpty()); |
983 |
|||
984 |
1207338 |
Local<Value> name = ToV8Value(context, item.first).ToLocalChecked(); |
|
985 |
603669 |
Local<Object> info = Object::New(isolate); |
|
986 |
Local<Value> help_text; |
||
987 |
✓✗✗✓ |
3018345 |
if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) || |
988 |
2414676 |
!info->Set(context, env->help_text_string(), help_text) |
|
989 |
✓✗ | 2414676 |
.FromMaybe(false) || |
990 |
1811007 |
!info->Set(context, |
|
991 |
env->env_var_settings_string(), |
||
992 |
Integer::New(isolate, |
||
993 |
2414676 |
static_cast<int>(option_info.env_setting))) |
|
994 |
✓✗ | 2414676 |
.FromMaybe(false) || |
995 |
1811007 |
!info->Set(context, |
|
996 |
env->type_string(), |
||
997 |
2414676 |
Integer::New(isolate, static_cast<int>(option_info.type))) |
|
998 |
✓✗ | 2414676 |
.FromMaybe(false) || |
999 |
✓✗✗✓ |
3622014 |
info->Set(context, env->value_string(), value).IsNothing() || |
1000 |
1811007 |
options->Set(context, name, info).IsEmpty()) { |
|
1001 |
return; |
||
1002 |
} |
||
1003 |
} |
||
1004 |
|||
1005 |
Local<Value> aliases; |
||
1006 |
✗✓ | 9978 |
if (!ToV8Value(context, _ppop_instance.aliases_).ToLocal(&aliases)) return; |
1007 |
|||
1008 |
4989 |
Local<Object> ret = Object::New(isolate); |
|
1009 |
✓✗✗✓ ✗✓ |
24945 |
if (ret->Set(context, env->options_string(), options).IsNothing() || |
1010 |
19956 |
ret->Set(context, env->aliases_string(), aliases).IsNothing()) { |
|
1011 |
return; |
||
1012 |
} |
||
1013 |
|||
1014 |
✓✗ | 9978 |
args.GetReturnValue().Set(ret); |
1015 |
} |
||
1016 |
|||
1017 |
4989 |
void Initialize(Local<Object> target, |
|
1018 |
Local<Value> unused, |
||
1019 |
Local<Context> context, |
||
1020 |
void* priv) { |
||
1021 |
4989 |
Environment* env = Environment::GetCurrent(context); |
|
1022 |
4989 |
Isolate* isolate = env->isolate(); |
|
1023 |
4989 |
env->SetMethodNoSideEffect(target, "getOptions", GetOptions); |
|
1024 |
|||
1025 |
4989 |
Local<Object> env_settings = Object::New(isolate); |
|
1026 |
9978 |
NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment); |
|
1027 |
4989 |
NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvironment); |
|
1028 |
19956 |
target |
|
1029 |
24945 |
->Set( |
|
1030 |
29934 |
context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings) |
|
1031 |
9978 |
.Check(); |
|
1032 |
|||
1033 |
target |
||
1034 |
9978 |
->Set(context, |
|
1035 |
FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), |
||
1036 |
19956 |
Boolean::New(isolate, env->should_not_register_esm_loader())) |
|
1037 |
.Check(); |
||
1038 |
|||
1039 |
4989 |
Local<Object> types = Object::New(isolate); |
|
1040 |
4989 |
NODE_DEFINE_CONSTANT(types, kNoOp); |
|
1041 |
14967 |
NODE_DEFINE_CONSTANT(types, kV8Option); |
|
1042 |
19956 |
NODE_DEFINE_CONSTANT(types, kBoolean); |
|
1043 |
34923 |
NODE_DEFINE_CONSTANT(types, kInteger); |
|
1044 |
44901 |
NODE_DEFINE_CONSTANT(types, kUInteger); |
|
1045 |
44901 |
NODE_DEFINE_CONSTANT(types, kString); |
|
1046 |
44901 |
NODE_DEFINE_CONSTANT(types, kHostPort); |
|
1047 |
44901 |
NODE_DEFINE_CONSTANT(types, kStringList); |
|
1048 |
54879 |
target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "types"), types) |
|
1049 |
29934 |
.Check(); |
|
1050 |
29934 |
} |
|
1051 |
9978 |
||
1052 |
} // namespace options_parser |
||
1053 |
|||
1054 |
4657 |
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options) { |
|
1055 |
27942 |
HandleEnvOptions(env_options, [](const char* name) { |
|
1056 |
37256 |
std::string text; |
|
1057 |
✓✓✓✓ |
37256 |
return credentials::SafeGetenv(name, &text) ? text : ""; |
1058 |
4657 |
}); |
|
1059 |
4657 |
} |
|
1060 |
|||
1061 |
4761 |
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options, |
|
1062 |
std::function<std::string(const char*)> opt_getter) { |
||
1063 |
9522 |
env_options->pending_deprecation = |
|
1064 |
9522 |
opt_getter("NODE_PENDING_DEPRECATION") == "1"; |
|
1065 |
|||
1066 |
4761 |
env_options->preserve_symlinks = opt_getter("NODE_PRESERVE_SYMLINKS") == "1"; |
|
1067 |
|||
1068 |
9522 |
env_options->preserve_symlinks_main = |
|
1069 |
9522 |
opt_getter("NODE_PRESERVE_SYMLINKS_MAIN") == "1"; |
|
1070 |
|||
1071 |
✓✗ | 4761 |
if (env_options->redirect_warnings.empty()) |
1072 |
4761 |
env_options->redirect_warnings = opt_getter("NODE_REDIRECT_WARNINGS"); |
|
1073 |
4761 |
} |
|
1074 |
|||
1075 |
4644 |
std::vector<std::string> ParseNodeOptionsEnvVar( |
|
1076 |
const std::string& node_options, std::vector<std::string>* errors) { |
||
1077 |
4644 |
std::vector<std::string> env_argv; |
|
1078 |
|||
1079 |
4644 |
bool is_in_string = false; |
|
1080 |
4644 |
bool will_start_new_arg = true; |
|
1081 |
✓✓ | 7366 |
for (std::string::size_type index = 0; index < node_options.size(); ++index) { |
1082 |
2722 |
char c = node_options.at(index); |
|
1083 |
|||
1084 |
// Backslashes escape the following character |
||
1085 |
✗✓✗✗ |
2722 |
if (c == '\\' && is_in_string) { |
1086 |
if (index + 1 == node_options.size()) { |
||
1087 |
errors->push_back("invalid value for NODE_OPTIONS " |
||
1088 |
"(invalid escape)\n"); |
||
1089 |
return env_argv; |
||
1090 |
} else { |
||
1091 |
c = node_options.at(++index); |
||
1092 |
} |
||
1093 |
✓✓✓✓ |
2722 |
} else if (c == ' ' && !is_in_string) { |
1094 |
32 |
will_start_new_arg = true; |
|
1095 |
32 |
continue; |
|
1096 |
✓✓ | 2690 |
} else if (c == '"') { |
1097 |
4 |
is_in_string = !is_in_string; |
|
1098 |
4 |
continue; |
|
1099 |
} |
||
1100 |
|||
1101 |
✓✓ | 2686 |
if (will_start_new_arg) { |
1102 |
107 |
env_argv.emplace_back(std::string(1, c)); |
|
1103 |
107 |
will_start_new_arg = false; |
|
1104 |
} else { |
||
1105 |
2579 |
env_argv.back() += c; |
|
1106 |
} |
||
1107 |
} |
||
1108 |
|||
1109 |
✗✓ | 4644 |
if (is_in_string) { |
1110 |
errors->push_back("invalid value for NODE_OPTIONS " |
||
1111 |
"(unterminated string)\n"); |
||
1112 |
} |
||
1113 |
4644 |
return env_argv; |
|
1114 |
} |
||
1115 |
} // namespace node |
||
1116 |
|||
1117 |
✓✗✓✗ |
18652 |
NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize) |
Generated by: GCOVR (Version 3.4) |