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 |
122 |
Mutex cli_options_mutex; |
|
30 |
122 |
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()}; |
|
31 |
} // namespace per_process |
||
32 |
|||
33 |
115 |
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 |
✗✓ | 115 |
if (deprecated_debug) { |
42 |
errors->push_back("[DEP0062]: `node --debug` and `node --debug-brk` " |
||
43 |
"are invalid. Please use `node --inspect` and " |
||
44 |
"`node --inspect-brk` instead."); |
||
45 |
} |
||
46 |
|||
47 |
std::vector<std::string> destinations = |
||
48 |
230 |
SplitString(inspect_publish_uid_string, ','); |
|
49 |
115 |
inspect_publish_uid.console = false; |
|
50 |
115 |
inspect_publish_uid.http = false; |
|
51 |
✓✓ | 345 |
for (const std::string& destination : destinations) { |
52 |
✓✓ | 230 |
if (destination == "stderr") { |
53 |
115 |
inspect_publish_uid.console = true; |
|
54 |
✓✗ | 115 |
} else if (destination == "http") { |
55 |
115 |
inspect_publish_uid.http = true; |
|
56 |
} else { |
||
57 |
errors->push_back("--inspect-publish-uid destination can be " |
||
58 |
"stderr or http"); |
||
59 |
} |
||
60 |
} |
||
61 |
115 |
} |
|
62 |
|||
63 |
115 |
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) { |
|
64 |
#if HAVE_OPENSSL |
||
65 |
✗✓✗✗ |
115 |
if (use_openssl_ca && use_bundled_ca) { |
66 |
errors->push_back("either --use-openssl-ca or --use-bundled-ca can be " |
||
67 |
"used, not both"); |
||
68 |
} |
||
69 |
|||
70 |
// Any value less than 2 disables use of the secure heap. |
||
71 |
✗✓ | 115 |
if (secure_heap >= 2) { |
72 |
if ((secure_heap & (secure_heap - 1)) != 0) |
||
73 |
errors->push_back("--secure-heap must be a power of 2"); |
||
74 |
secure_heap_min = |
||
75 |
std::min({ |
||
76 |
secure_heap, |
||
77 |
secure_heap_min, |
||
78 |
static_cast<int64_t>(std::numeric_limits<int>::max())}); |
||
79 |
secure_heap_min = std::max(static_cast<int64_t>(2), secure_heap_min); |
||
80 |
if ((secure_heap_min & (secure_heap_min - 1)) != 0) |
||
81 |
errors->push_back("--secure-heap-min must be a power of 2"); |
||
82 |
} |
||
83 |
#endif |
||
84 |
✗✗✗✓ |
230 |
if (use_largepages != "off" && |
85 |
✗✓✗✗ |
115 |
use_largepages != "on" && |
86 |
use_largepages != "silent") { |
||
87 |
errors->push_back("invalid value for --use-largepages"); |
||
88 |
} |
||
89 |
115 |
per_isolate->CheckOptions(errors); |
|
90 |
115 |
} |
|
91 |
|||
92 |
115 |
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) { |
|
93 |
115 |
per_env->CheckOptions(errors); |
|
94 |
115 |
} |
|
95 |
|||
96 |
115 |
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { |
|
97 |
✗✓✗✗ ✗✓ |
115 |
if (has_policy_integrity_string && experimental_policy.empty()) { |
98 |
errors->push_back("--policy-integrity requires " |
||
99 |
"--experimental-policy be enabled"); |
||
100 |
} |
||
101 |
✗✓✗✗ ✗✓ |
115 |
if (has_policy_integrity_string && experimental_policy_integrity.empty()) { |
102 |
errors->push_back("--policy-integrity cannot be empty"); |
||
103 |
} |
||
104 |
|||
105 |
✗✓ | 115 |
if (!module_type.empty()) { |
106 |
if (module_type != "commonjs" && module_type != "module") { |
||
107 |
errors->push_back("--input-type must be \"module\" or \"commonjs\""); |
||
108 |
} |
||
109 |
} |
||
110 |
|||
111 |
✗✓ | 115 |
if (!experimental_specifier_resolution.empty()) { |
112 |
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 |
✗✓✗✗ |
115 |
if (syntax_check_only && has_eval_string) { |
120 |
errors->push_back("either --check or --eval can be used, not both"); |
||
121 |
} |
||
122 |
|||
123 |
✗✗✗✓ |
230 |
if (!unhandled_rejections.empty() && |
124 |
unhandled_rejections != "warn-with-error-code" && |
||
125 |
unhandled_rejections != "throw" && |
||
126 |
unhandled_rejections != "strict" && |
||
127 |
✗✓✗✗ |
115 |
unhandled_rejections != "warn" && |
128 |
unhandled_rejections != "none") { |
||
129 |
errors->push_back("invalid value for --unhandled-rejections"); |
||
130 |
} |
||
131 |
|||
132 |
✗✓✗✗ |
115 |
if (tls_min_v1_3 && tls_max_v1_2) { |
133 |
errors->push_back("either --tls-min-v1.3 or --tls-max-v1.2 can be " |
||
134 |
"used, not both"); |
||
135 |
} |
||
136 |
|||
137 |
✗✓ | 115 |
if (heap_snapshot_near_heap_limit < 0) { |
138 |
errors->push_back("--heap-snapshot-near-heap-limit must not be negative"); |
||
139 |
} |
||
140 |
|||
141 |
#if HAVE_INSPECTOR |
||
142 |
✓✗ | 115 |
if (!cpu_prof) { |
143 |
✗✓ | 115 |
if (!cpu_prof_name.empty()) { |
144 |
errors->push_back("--cpu-prof-name must be used with --cpu-prof"); |
||
145 |
} |
||
146 |
✗✓ | 115 |
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 |
✗✓ | 115 |
if (cpu_prof_interval != kDefaultCpuProfInterval) { |
152 |
errors->push_back("--cpu-prof-interval must be used with --cpu-prof"); |
||
153 |
} |
||
154 |
} |
||
155 |
|||
156 |
✗✓✗✗ ✗✗✗✓ |
115 |
if (cpu_prof && cpu_prof_dir.empty() && !diagnostic_dir.empty()) { |
157 |
cpu_prof_dir = diagnostic_dir; |
||
158 |
} |
||
159 |
|||
160 |
✓✗ | 115 |
if (!heap_prof) { |
161 |
✗✓ | 115 |
if (!heap_prof_name.empty()) { |
162 |
errors->push_back("--heap-prof-name must be used with --heap-prof"); |
||
163 |
} |
||
164 |
✗✓ | 115 |
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 |
✗✓ | 115 |
if (heap_prof_interval != kDefaultHeapProfInterval) { |
170 |
errors->push_back("--heap-prof-interval must be used with --heap-prof"); |
||
171 |
} |
||
172 |
} |
||
173 |
|||
174 |
✗✓✗✗ ✗✗✗✓ |
115 |
if (heap_prof && heap_prof_dir.empty() && !diagnostic_dir.empty()) { |
175 |
heap_prof_dir = diagnostic_dir; |
||
176 |
} |
||
177 |
|||
178 |
115 |
debug_options_.CheckOptions(errors); |
|
179 |
#endif // HAVE_INSPECTOR |
||
180 |
115 |
} |
|
181 |
|||
182 |
namespace options_parser { |
||
183 |
|||
184 |
122 |
class DebugOptionsParser : public OptionsParser<DebugOptions> { |
|
185 |
public: |
||
186 |
DebugOptionsParser(); |
||
187 |
}; |
||
188 |
|||
189 |
122 |
class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> { |
|
190 |
public: |
||
191 |
EnvironmentOptionsParser(); |
||
192 |
122 |
explicit EnvironmentOptionsParser(const DebugOptionsParser& dop) |
|
193 |
122 |
: EnvironmentOptionsParser() { |
|
194 |
122 |
Insert(dop, &EnvironmentOptions::get_debug_options); |
|
195 |
122 |
} |
|
196 |
}; |
||
197 |
|||
198 |
122 |
class PerIsolateOptionsParser : public OptionsParser<PerIsolateOptions> { |
|
199 |
public: |
||
200 |
PerIsolateOptionsParser() = delete; |
||
201 |
explicit PerIsolateOptionsParser(const EnvironmentOptionsParser& eop); |
||
202 |
}; |
||
203 |
|||
204 |
122 |
class PerProcessOptionsParser : public OptionsParser<PerProcessOptions> { |
|
205 |
public: |
||
206 |
PerProcessOptionsParser() = delete; |
||
207 |
explicit PerProcessOptionsParser(const PerIsolateOptionsParser& iop); |
||
208 |
}; |
||
209 |
|||
210 |
#if HAVE_INSPECTOR |
||
211 |
122 |
const DebugOptionsParser _dop_instance{}; |
|
212 |
122 |
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 |
122 |
const PerIsolateOptionsParser _piop_instance{_eop_instance}; |
|
228 |
122 |
const PerProcessOptionsParser _ppop_instance{_piop_instance}; |
|
229 |
|||
230 |
template <> |
||
231 |
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 |
args, exec_args, v8_args, options, required_env_settings, errors); |
||
238 |
} |
||
239 |
|||
240 |
template <> |
||
241 |
115 |
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 |
115 |
args, exec_args, v8_args, options, required_env_settings, errors); |
|
248 |
115 |
} |
|
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 |
122 |
DebugOptionsParser::DebugOptionsParser() { |
|
255 |
122 |
AddOption("--inspect-port", |
|
256 |
"set host:port for inspector", |
||
257 |
&DebugOptions::host_port, |
||
258 |
122 |
kAllowedInEnvironment); |
|
259 |
122 |
AddAlias("--debug-port", "--inspect-port"); |
|
260 |
|||
261 |
122 |
AddOption("--inspect", |
|
262 |
"activate inspector on host:port (default: 127.0.0.1:9229)", |
||
263 |
&DebugOptions::inspector_enabled, |
||
264 |
122 |
kAllowedInEnvironment); |
|
265 |
✓✓ | 122 |
AddAlias("--inspect=", { "--inspect-port", "--inspect" }); |
266 |
|||
267 |
122 |
AddOption("--debug", "", &DebugOptions::deprecated_debug); |
|
268 |
122 |
AddAlias("--debug=", "--debug"); |
|
269 |
122 |
AddOption("--debug-brk", "", &DebugOptions::deprecated_debug); |
|
270 |
122 |
AddAlias("--debug-brk=", "--debug-brk"); |
|
271 |
|||
272 |
122 |
AddOption("--inspect-brk", |
|
273 |
"activate inspector on host:port and break at start of user script", |
||
274 |
&DebugOptions::break_first_line, |
||
275 |
122 |
kAllowedInEnvironment); |
|
276 |
122 |
Implies("--inspect-brk", "--inspect"); |
|
277 |
✓✓ | 122 |
AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" }); |
278 |
|||
279 |
122 |
AddOption("--inspect-brk-node", "", &DebugOptions::break_node_first_line); |
|
280 |
122 |
Implies("--inspect-brk-node", "--inspect"); |
|
281 |
✓✓ | 122 |
AddAlias("--inspect-brk-node=", { "--inspect-port", "--inspect-brk-node" }); |
282 |
|||
283 |
122 |
AddOption("--inspect-publish-uid", |
|
284 |
"comma separated list of destinations for inspector uid" |
||
285 |
"(default: stderr,http)", |
||
286 |
&DebugOptions::inspect_publish_uid_string, |
||
287 |
122 |
kAllowedInEnvironment); |
|
288 |
122 |
} |
|
289 |
|||
290 |
122 |
EnvironmentOptionsParser::EnvironmentOptionsParser() { |
|
291 |
122 |
AddOption("--conditions", |
|
292 |
"additional user conditions for conditional exports and imports", |
||
293 |
&EnvironmentOptions::conditions, |
||
294 |
122 |
kAllowedInEnvironment); |
|
295 |
122 |
AddOption("--diagnostic-dir", |
|
296 |
"set dir for all output files" |
||
297 |
" (default: current working directory)", |
||
298 |
&EnvironmentOptions::diagnostic_dir, |
||
299 |
122 |
kAllowedInEnvironment); |
|
300 |
122 |
AddOption("--enable-source-maps", |
|
301 |
"experimental Source Map V3 support", |
||
302 |
&EnvironmentOptions::enable_source_maps, |
||
303 |
122 |
kAllowedInEnvironment); |
|
304 |
122 |
AddOption("--experimental-abortcontroller", "", |
|
305 |
122 |
NoOp{}, kAllowedInEnvironment); |
|
306 |
122 |
AddOption("--experimental-json-modules", |
|
307 |
"experimental JSON interop support for the ES Module loader", |
||
308 |
&EnvironmentOptions::experimental_json_modules, |
||
309 |
122 |
kAllowedInEnvironment); |
|
310 |
122 |
AddOption("--experimental-loader", |
|
311 |
"use the specified module as a custom loader", |
||
312 |
&EnvironmentOptions::userland_loader, |
||
313 |
122 |
kAllowedInEnvironment); |
|
314 |
122 |
AddAlias("--loader", "--experimental-loader"); |
|
315 |
122 |
AddOption("--experimental-modules", |
|
316 |
"", |
||
317 |
&EnvironmentOptions::experimental_modules, |
||
318 |
122 |
kAllowedInEnvironment); |
|
319 |
122 |
AddOption("--experimental-wasm-modules", |
|
320 |
"experimental ES Module support for webassembly modules", |
||
321 |
&EnvironmentOptions::experimental_wasm_modules, |
||
322 |
122 |
kAllowedInEnvironment); |
|
323 |
122 |
AddOption("--experimental-import-meta-resolve", |
|
324 |
"experimental ES Module import.meta.resolve() support", |
||
325 |
&EnvironmentOptions::experimental_import_meta_resolve, |
||
326 |
122 |
kAllowedInEnvironment); |
|
327 |
122 |
AddOption("--experimental-policy", |
|
328 |
"use the specified file as a " |
||
329 |
"security policy", |
||
330 |
&EnvironmentOptions::experimental_policy, |
||
331 |
122 |
kAllowedInEnvironment); |
|
332 |
122 |
AddOption("[has_policy_integrity_string]", |
|
333 |
"", |
||
334 |
122 |
&EnvironmentOptions::has_policy_integrity_string); |
|
335 |
122 |
AddOption("--policy-integrity", |
|
336 |
"ensure the security policy contents match " |
||
337 |
"the specified integrity", |
||
338 |
&EnvironmentOptions::experimental_policy_integrity, |
||
339 |
122 |
kAllowedInEnvironment); |
|
340 |
122 |
Implies("--policy-integrity", "[has_policy_integrity_string]"); |
|
341 |
122 |
AddOption("--experimental-repl-await", |
|
342 |
"experimental await keyword support in REPL", |
||
343 |
&EnvironmentOptions::experimental_repl_await, |
||
344 |
122 |
kAllowedInEnvironment); |
|
345 |
122 |
AddOption("--experimental-vm-modules", |
|
346 |
"experimental ES Module support in vm module", |
||
347 |
&EnvironmentOptions::experimental_vm_modules, |
||
348 |
122 |
kAllowedInEnvironment); |
|
349 |
122 |
AddOption("--experimental-worker", "", NoOp{}, kAllowedInEnvironment); |
|
350 |
122 |
AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvironment); |
|
351 |
122 |
AddOption("--experimental-wasi-unstable-preview1", |
|
352 |
"experimental WASI support", |
||
353 |
&EnvironmentOptions::experimental_wasi, |
||
354 |
122 |
kAllowedInEnvironment); |
|
355 |
122 |
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals); |
|
356 |
122 |
AddOption("--frozen-intrinsics", |
|
357 |
"experimental frozen intrinsics support", |
||
358 |
&EnvironmentOptions::frozen_intrinsics, |
||
359 |
122 |
kAllowedInEnvironment); |
|
360 |
122 |
AddOption("--heapsnapshot-signal", |
|
361 |
"Generate heap snapshot on specified signal", |
||
362 |
&EnvironmentOptions::heap_snapshot_signal, |
||
363 |
122 |
kAllowedInEnvironment); |
|
364 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
370 |
122 |
AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment); |
|
371 |
122 |
AddOption("--insecure-http-parser", |
|
372 |
"use an insecure HTTP parser that accepts invalid HTTP headers", |
||
373 |
&EnvironmentOptions::insecure_http_parser, |
||
374 |
122 |
kAllowedInEnvironment); |
|
375 |
122 |
AddOption("--input-type", |
|
376 |
"set module type for string input", |
||
377 |
&EnvironmentOptions::module_type, |
||
378 |
122 |
kAllowedInEnvironment); |
|
379 |
122 |
AddOption("--experimental-specifier-resolution", |
|
380 |
"Select extension resolution algorithm for es modules; " |
||
381 |
"either 'explicit' (default) or 'node'", |
||
382 |
&EnvironmentOptions::experimental_specifier_resolution, |
||
383 |
122 |
kAllowedInEnvironment); |
|
384 |
122 |
AddAlias("--es-module-specifier-resolution", |
|
385 |
122 |
"--experimental-specifier-resolution"); |
|
386 |
122 |
AddOption("--no-deprecation", |
|
387 |
"silence deprecation warnings", |
||
388 |
&EnvironmentOptions::no_deprecation, |
||
389 |
122 |
kAllowedInEnvironment); |
|
390 |
122 |
AddOption("--no-force-async-hooks-checks", |
|
391 |
"disable checks for async_hooks", |
||
392 |
&EnvironmentOptions::no_force_async_hooks_checks, |
||
393 |
122 |
kAllowedInEnvironment); |
|
394 |
122 |
AddOption("--no-warnings", |
|
395 |
"silence all process warnings", |
||
396 |
&EnvironmentOptions::no_warnings, |
||
397 |
122 |
kAllowedInEnvironment); |
|
398 |
122 |
AddOption("--force-context-aware", |
|
399 |
"disable loading non-context-aware addons", |
||
400 |
&EnvironmentOptions::force_context_aware, |
||
401 |
122 |
kAllowedInEnvironment); |
|
402 |
122 |
AddOption("--pending-deprecation", |
|
403 |
"emit pending deprecation warnings", |
||
404 |
&EnvironmentOptions::pending_deprecation, |
||
405 |
122 |
kAllowedInEnvironment); |
|
406 |
122 |
AddOption("--preserve-symlinks", |
|
407 |
"preserve symbolic links when resolving", |
||
408 |
&EnvironmentOptions::preserve_symlinks, |
||
409 |
122 |
kAllowedInEnvironment); |
|
410 |
122 |
AddOption("--preserve-symlinks-main", |
|
411 |
"preserve symbolic links when resolving the main module", |
||
412 |
&EnvironmentOptions::preserve_symlinks_main, |
||
413 |
122 |
kAllowedInEnvironment); |
|
414 |
122 |
AddOption("--prof", |
|
415 |
"Generate V8 profiler output.", |
||
416 |
122 |
V8Option{}); |
|
417 |
122 |
AddOption("--prof-process", |
|
418 |
"process V8 profiler output generated using --prof", |
||
419 |
122 |
&EnvironmentOptions::prof_process); |
|
420 |
// Options after --prof-process are passed through to the prof processor. |
||
421 |
✓✓ | 122 |
AddAlias("--prof-process", { "--prof-process", "--" }); |
422 |
#if HAVE_INSPECTOR |
||
423 |
122 |
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 |
122 |
&EnvironmentOptions::cpu_prof); |
|
428 |
122 |
AddOption("--cpu-prof-name", |
|
429 |
"specified file name of the V8 CPU profile generated with " |
||
430 |
"--cpu-prof", |
||
431 |
122 |
&EnvironmentOptions::cpu_prof_name); |
|
432 |
122 |
AddOption("--cpu-prof-interval", |
|
433 |
"specified sampling interval in microseconds for the V8 CPU " |
||
434 |
"profile generated with --cpu-prof. (default: 1000)", |
||
435 |
122 |
&EnvironmentOptions::cpu_prof_interval); |
|
436 |
122 |
AddOption("--cpu-prof-dir", |
|
437 |
"Directory where the V8 profiles generated by --cpu-prof will be " |
||
438 |
"placed. Does not affect --prof.", |
||
439 |
122 |
&EnvironmentOptions::cpu_prof_dir); |
|
440 |
122 |
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 |
122 |
&EnvironmentOptions::heap_prof); |
|
446 |
122 |
AddOption("--heap-prof-name", |
|
447 |
"specified file name of the V8 heap profile generated with " |
||
448 |
"--heap-prof", |
||
449 |
122 |
&EnvironmentOptions::heap_prof_name); |
|
450 |
122 |
AddOption("--heap-prof-dir", |
|
451 |
"Directory where the V8 heap profiles generated by --heap-prof " |
||
452 |
"will be placed.", |
||
453 |
122 |
&EnvironmentOptions::heap_prof_dir); |
|
454 |
122 |
AddOption("--heap-prof-interval", |
|
455 |
"specified sampling interval in bytes for the V8 heap " |
||
456 |
"profile generated with --heap-prof. (default: 512 * 1024)", |
||
457 |
122 |
&EnvironmentOptions::heap_prof_interval); |
|
458 |
#endif // HAVE_INSPECTOR |
||
459 |
122 |
AddOption("--max-http-header-size", |
|
460 |
"set the maximum size of HTTP headers (default: 16384 (16KB))", |
||
461 |
&EnvironmentOptions::max_http_header_size, |
||
462 |
122 |
kAllowedInEnvironment); |
|
463 |
122 |
AddOption("--redirect-warnings", |
|
464 |
"write warnings to file instead of stderr", |
||
465 |
&EnvironmentOptions::redirect_warnings, |
||
466 |
122 |
kAllowedInEnvironment); |
|
467 |
122 |
AddOption("--test-udp-no-try-send", "", // For testing only. |
|
468 |
122 |
&EnvironmentOptions::test_udp_no_try_send); |
|
469 |
122 |
AddOption("--throw-deprecation", |
|
470 |
"throw an exception on deprecations", |
||
471 |
&EnvironmentOptions::throw_deprecation, |
||
472 |
122 |
kAllowedInEnvironment); |
|
473 |
122 |
AddOption("--trace-atomics-wait", |
|
474 |
"trace Atomics.wait() operations", |
||
475 |
&EnvironmentOptions::trace_atomics_wait, |
||
476 |
122 |
kAllowedInEnvironment); |
|
477 |
122 |
AddOption("--trace-deprecation", |
|
478 |
"show stack traces on deprecations", |
||
479 |
&EnvironmentOptions::trace_deprecation, |
||
480 |
122 |
kAllowedInEnvironment); |
|
481 |
122 |
AddOption("--trace-exit", |
|
482 |
"show stack trace when an environment exits", |
||
483 |
&EnvironmentOptions::trace_exit, |
||
484 |
122 |
kAllowedInEnvironment); |
|
485 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
490 |
122 |
AddOption("--trace-tls", |
|
491 |
"prints TLS packet trace information to stderr", |
||
492 |
&EnvironmentOptions::trace_tls, |
||
493 |
122 |
kAllowedInEnvironment); |
|
494 |
122 |
AddOption("--trace-uncaught", |
|
495 |
"show stack traces for the `throw` behind uncaught exceptions", |
||
496 |
&EnvironmentOptions::trace_uncaught, |
||
497 |
122 |
kAllowedInEnvironment); |
|
498 |
122 |
AddOption("--trace-warnings", |
|
499 |
"show stack traces on process warnings", |
||
500 |
&EnvironmentOptions::trace_warnings, |
||
501 |
122 |
kAllowedInEnvironment); |
|
502 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
507 |
122 |
AddOption("--verify-base-objects", |
|
508 |
"", /* undocumented, only for debugging */ |
||
509 |
&EnvironmentOptions::verify_base_objects, |
||
510 |
122 |
kAllowedInEnvironment); |
|
511 |
|||
512 |
122 |
AddOption("--check", |
|
513 |
"syntax check script without executing", |
||
514 |
122 |
&EnvironmentOptions::syntax_check_only); |
|
515 |
122 |
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 |
122 |
AddOption("[has_eval_string]", "", &EnvironmentOptions::has_eval_string); |
|
523 |
122 |
AddOption("--eval", "evaluate script", &EnvironmentOptions::eval_string); |
|
524 |
122 |
Implies("--eval", "[has_eval_string]"); |
|
525 |
122 |
AddOption("--print", |
|
526 |
"evaluate script and print result", |
||
527 |
122 |
&EnvironmentOptions::print_eval); |
|
528 |
122 |
AddAlias("-e", "--eval"); |
|
529 |
122 |
AddAlias("--print <arg>", "-pe"); |
|
530 |
✓✓ | 122 |
AddAlias("-pe", { "--print", "--eval" }); |
531 |
122 |
AddAlias("-p", "--print"); |
|
532 |
122 |
AddOption("--require", |
|
533 |
"module to preload (option can be repeated)", |
||
534 |
&EnvironmentOptions::preload_modules, |
||
535 |
122 |
kAllowedInEnvironment); |
|
536 |
122 |
AddAlias("-r", "--require"); |
|
537 |
122 |
AddOption("--interactive", |
|
538 |
"always enter the REPL even if stdin does not appear " |
||
539 |
"to be a terminal", |
||
540 |
122 |
&EnvironmentOptions::force_repl); |
|
541 |
122 |
AddAlias("-i", "--interactive"); |
|
542 |
|||
543 |
122 |
AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment); |
|
544 |
|||
545 |
122 |
AddOption("--tls-keylog", |
|
546 |
"log TLS decryption keys to named file for traffic analysis", |
||
547 |
122 |
&EnvironmentOptions::tls_keylog, kAllowedInEnvironment); |
|
548 |
|||
549 |
122 |
AddOption("--tls-min-v1.0", |
|
550 |
"set default TLS minimum to TLSv1.0 (default: TLSv1.2)", |
||
551 |
&EnvironmentOptions::tls_min_v1_0, |
||
552 |
122 |
kAllowedInEnvironment); |
|
553 |
122 |
AddOption("--tls-min-v1.1", |
|
554 |
"set default TLS minimum to TLSv1.1 (default: TLSv1.2)", |
||
555 |
&EnvironmentOptions::tls_min_v1_1, |
||
556 |
122 |
kAllowedInEnvironment); |
|
557 |
122 |
AddOption("--tls-min-v1.2", |
|
558 |
"set default TLS minimum to TLSv1.2 (default: TLSv1.2)", |
||
559 |
&EnvironmentOptions::tls_min_v1_2, |
||
560 |
122 |
kAllowedInEnvironment); |
|
561 |
122 |
AddOption("--tls-min-v1.3", |
|
562 |
"set default TLS minimum to TLSv1.3 (default: TLSv1.2)", |
||
563 |
&EnvironmentOptions::tls_min_v1_3, |
||
564 |
122 |
kAllowedInEnvironment); |
|
565 |
122 |
AddOption("--tls-max-v1.2", |
|
566 |
"set default TLS maximum to TLSv1.2 (default: TLSv1.3)", |
||
567 |
&EnvironmentOptions::tls_max_v1_2, |
||
568 |
122 |
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 |
122 |
AddOption("--tls-max-v1.3", |
|
574 |
"set default TLS maximum to TLSv1.3 (default: TLSv1.3)", |
||
575 |
&EnvironmentOptions::tls_max_v1_3, |
||
576 |
122 |
kAllowedInEnvironment); |
|
577 |
122 |
} |
|
578 |
|||
579 |
122 |
PerIsolateOptionsParser::PerIsolateOptionsParser( |
|
580 |
122 |
const EnvironmentOptionsParser& eop) { |
|
581 |
122 |
AddOption("--track-heap-objects", |
|
582 |
"track heap object allocations for heap snapshots", |
||
583 |
&PerIsolateOptions::track_heap_objects, |
||
584 |
122 |
kAllowedInEnvironment); |
|
585 |
122 |
AddOption("--no-node-snapshot", |
|
586 |
"", // It's a debug-only option. |
||
587 |
&PerIsolateOptions::no_node_snapshot, |
||
588 |
122 |
kAllowedInEnvironment); |
|
589 |
|||
590 |
// Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS. |
||
591 |
122 |
AddOption("--abort-on-uncaught-exception", |
|
592 |
"aborting instead of exiting causes a core file to be generated " |
||
593 |
"for analysis", |
||
594 |
122 |
V8Option{}, |
|
595 |
122 |
kAllowedInEnvironment); |
|
596 |
122 |
AddOption("--interpreted-frames-native-stack", |
|
597 |
"help system profilers to translate JavaScript interpreted frames", |
||
598 |
122 |
V8Option{}, kAllowedInEnvironment); |
|
599 |
122 |
AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvironment); |
|
600 |
122 |
AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvironment); |
|
601 |
122 |
AddOption("--perf-basic-prof-only-functions", |
|
602 |
"", |
||
603 |
122 |
V8Option{}, |
|
604 |
122 |
kAllowedInEnvironment); |
|
605 |
122 |
AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvironment); |
|
606 |
122 |
AddOption("--perf-prof-unwinding-info", |
|
607 |
"", |
||
608 |
122 |
V8Option{}, |
|
609 |
122 |
kAllowedInEnvironment); |
|
610 |
122 |
AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment); |
|
611 |
122 |
AddOption("--disallow-code-generation-from-strings", |
|
612 |
"disallow eval and friends", |
||
613 |
122 |
V8Option{}, |
|
614 |
122 |
kAllowedInEnvironment); |
|
615 |
122 |
AddOption("--huge-max-old-generation-size", |
|
616 |
"increase default maximum heap size on machines with 16GB memory " |
||
617 |
"or more", |
||
618 |
122 |
V8Option{}, |
|
619 |
122 |
kAllowedInEnvironment); |
|
620 |
122 |
AddOption("--jitless", |
|
621 |
"disable runtime allocation of executable memory", |
||
622 |
122 |
V8Option{}, |
|
623 |
122 |
kAllowedInEnvironment); |
|
624 |
122 |
AddOption("--report-uncaught-exception", |
|
625 |
"generate diagnostic report on uncaught exceptions", |
||
626 |
&PerIsolateOptions::report_uncaught_exception, |
||
627 |
122 |
kAllowedInEnvironment); |
|
628 |
122 |
AddOption("--report-on-signal", |
|
629 |
"generate diagnostic report upon receiving signals", |
||
630 |
&PerIsolateOptions::report_on_signal, |
||
631 |
122 |
kAllowedInEnvironment); |
|
632 |
122 |
AddOption("--report-signal", |
|
633 |
"causes diagnostic report to be produced on provided signal," |
||
634 |
" unsupported in Windows. (default: SIGUSR2)", |
||
635 |
&PerIsolateOptions::report_signal, |
||
636 |
122 |
kAllowedInEnvironment); |
|
637 |
122 |
Implies("--report-signal", "--report-on-signal"); |
|
638 |
|||
639 |
122 |
AddOption("--experimental-top-level-await", |
|
640 |
"", |
||
641 |
&PerIsolateOptions::experimental_top_level_await, |
||
642 |
122 |
kAllowedInEnvironment); |
|
643 |
122 |
AddOption("--harmony-top-level-await", "", V8Option{}); |
|
644 |
122 |
Implies("--experimental-top-level-await", "--harmony-top-level-await"); |
|
645 |
122 |
Implies("--harmony-top-level-await", "--experimental-top-level-await"); |
|
646 |
122 |
ImpliesNot("--no-harmony-top-level-await", "--experimental-top-level-await"); |
|
647 |
|||
648 |
122 |
Insert(eop, &PerIsolateOptions::get_per_env_options); |
|
649 |
122 |
} |
|
650 |
|||
651 |
122 |
PerProcessOptionsParser::PerProcessOptionsParser( |
|
652 |
122 |
const PerIsolateOptionsParser& iop) { |
|
653 |
122 |
AddOption("--title", |
|
654 |
"the process title to use on startup", |
||
655 |
&PerProcessOptions::title, |
||
656 |
122 |
kAllowedInEnvironment); |
|
657 |
122 |
AddOption("--trace-event-categories", |
|
658 |
"comma separated list of trace event categories to record", |
||
659 |
&PerProcessOptions::trace_event_categories, |
||
660 |
122 |
kAllowedInEnvironment); |
|
661 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
666 |
✓✓ | 488 |
AddAlias("--trace-events-enabled", { |
667 |
366 |
"--trace-event-categories", "v8,node,node.async_hooks" }); |
|
668 |
122 |
AddOption("--v8-pool-size", |
|
669 |
"set V8's thread pool size", |
||
670 |
&PerProcessOptions::v8_thread_pool_size, |
||
671 |
122 |
kAllowedInEnvironment); |
|
672 |
122 |
AddOption("--zero-fill-buffers", |
|
673 |
"automatically zero-fill all newly allocated Buffer and " |
||
674 |
"SlowBuffer instances", |
||
675 |
&PerProcessOptions::zero_fill_all_buffers, |
||
676 |
122 |
kAllowedInEnvironment); |
|
677 |
122 |
AddOption("--debug-arraybuffer-allocations", |
|
678 |
"", /* undocumented, only for debugging */ |
||
679 |
&PerProcessOptions::debug_arraybuffer_allocations, |
||
680 |
122 |
kAllowedInEnvironment); |
|
681 |
122 |
AddOption("--disable-proto", |
|
682 |
"disable Object.prototype.__proto__", |
||
683 |
&PerProcessOptions::disable_proto, |
||
684 |
122 |
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 |
122 |
AddOption("--security-revert", "", &PerProcessOptions::security_reverts); |
|
690 |
122 |
AddAlias("--security-reverts", "--security-revert"); |
|
691 |
122 |
AddOption("--completion-bash", |
|
692 |
"print source-able bash completion script", |
||
693 |
122 |
&PerProcessOptions::print_bash_completion); |
|
694 |
122 |
AddOption("--help", |
|
695 |
"print node command line options", |
||
696 |
122 |
&PerProcessOptions::print_help); |
|
697 |
122 |
AddAlias("-h", "--help"); |
|
698 |
122 |
AddOption( |
|
699 |
122 |
"--version", "print Node.js version", &PerProcessOptions::print_version); |
|
700 |
122 |
AddAlias("-v", "--version"); |
|
701 |
122 |
AddOption("--v8-options", |
|
702 |
"print V8 command line options", |
||
703 |
122 |
&PerProcessOptions::print_v8_help); |
|
704 |
122 |
AddOption("--report-compact", |
|
705 |
"output compact single-line JSON", |
||
706 |
&PerProcessOptions::report_compact, |
||
707 |
122 |
kAllowedInEnvironment); |
|
708 |
122 |
AddOption("--report-dir", |
|
709 |
"define custom report pathname." |
||
710 |
" (default: current working directory)", |
||
711 |
&PerProcessOptions::report_directory, |
||
712 |
122 |
kAllowedInEnvironment); |
|
713 |
122 |
AddAlias("--report-directory", "--report-dir"); |
|
714 |
122 |
AddOption("--report-filename", |
|
715 |
"define custom report file name." |
||
716 |
" (default: YYYYMMDD.HHMMSS.PID.SEQUENCE#.txt)", |
||
717 |
&PerProcessOptions::report_filename, |
||
718 |
122 |
kAllowedInEnvironment); |
|
719 |
122 |
AddOption("--report-on-fatalerror", |
|
720 |
"generate diagnostic report on fatal (internal) errors", |
||
721 |
&PerProcessOptions::report_on_fatalerror, |
||
722 |
122 |
kAllowedInEnvironment); |
|
723 |
|||
724 |
#ifdef NODE_HAVE_I18N_SUPPORT |
||
725 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
733 |
#endif |
||
734 |
|||
735 |
#if HAVE_OPENSSL |
||
736 |
122 |
AddOption("--openssl-config", |
|
737 |
"load OpenSSL configuration from the specified file " |
||
738 |
"(overrides OPENSSL_CONF)", |
||
739 |
&PerProcessOptions::openssl_config, |
||
740 |
122 |
kAllowedInEnvironment); |
|
741 |
122 |
AddOption("--tls-cipher-list", |
|
742 |
"use an alternative default TLS cipher list", |
||
743 |
&PerProcessOptions::tls_cipher_list, |
||
744 |
122 |
kAllowedInEnvironment); |
|
745 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
753 |
122 |
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 |
122 |
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 |
122 |
AddOption("[ssl_openssl_cert_store]", |
|
765 |
"", |
||
766 |
122 |
&PerProcessOptions::ssl_openssl_cert_store); |
|
767 |
122 |
Implies("--use-openssl-ca", "[ssl_openssl_cert_store]"); |
|
768 |
122 |
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 |
122 |
AddOption("--secure-heap", |
|
780 |
"total size of the OpenSSL secure heap", |
||
781 |
&PerProcessOptions::secure_heap, |
||
782 |
122 |
kAllowedInEnvironment); |
|
783 |
122 |
AddOption("--secure-heap-min", |
|
784 |
"minimum allocation size from the OpenSSL secure heap", |
||
785 |
&PerProcessOptions::secure_heap_min, |
||
786 |
122 |
kAllowedInEnvironment); |
|
787 |
#endif |
||
788 |
122 |
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 |
122 |
kAllowedInEnvironment); |
|
795 |
|||
796 |
122 |
AddOption("--trace-sigint", |
|
797 |
"enable printing JavaScript stacktrace on SIGINT", |
||
798 |
&PerProcessOptions::trace_sigint, |
||
799 |
122 |
kAllowedInEnvironment); |
|
800 |
|||
801 |
122 |
Insert(iop, &PerProcessOptions::get_per_isolate_options); |
|
802 |
|||
803 |
122 |
AddOption("--node-memory-debug", |
|
804 |
"Run with extra debug checks for memory leaks in Node.js itself", |
||
805 |
122 |
NoOp{}, kAllowedInEnvironment); |
|
806 |
122 |
Implies("--node-memory-debug", "--debug-arraybuffer-allocations"); |
|
807 |
122 |
Implies("--node-memory-debug", "--verify-base-objects"); |
|
808 |
122 |
} |
|
809 |
|||
810 |
inline std::string RemoveBrackets(const std::string& host) { |
||
811 |
if (!host.empty() && host.front() == '[' && host.back() == ']') |
||
812 |
return host.substr(1, host.size() - 2); |
||
813 |
else |
||
814 |
return host; |
||
815 |
} |
||
816 |
|||
817 |
inline int ParseAndValidatePort(const std::string& port, |
||
818 |
std::vector<std::string>* errors) { |
||
819 |
char* endptr; |
||
820 |
errno = 0; |
||
821 |
const unsigned long result = // NOLINT(runtime/int) |
||
822 |
strtoul(port.c_str(), &endptr, 10); |
||
823 |
if (errno != 0 || *endptr != '\0'|| |
||
824 |
(result != 0 && result < 1024) || result > 65535) { |
||
825 |
errors->push_back(" must be 0 or in range 1024 to 65535."); |
||
826 |
} |
||
827 |
return static_cast<int>(result); |
||
828 |
} |
||
829 |
|||
830 |
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 |
std::string host = RemoveBrackets(arg); |
||
835 |
if (host.length() < arg.length()) |
||
836 |
return HostPort{host, DebugOptions::kDefaultInspectorPort}; |
||
837 |
|||
838 |
size_t colon = arg.rfind(':'); |
||
839 |
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 |
for (char c : arg) { |
||
843 |
if (c < '0' || c > '9') { |
||
844 |
return HostPort{arg, DebugOptions::kDefaultInspectorPort}; |
||
845 |
} |
||
846 |
} |
||
847 |
return HostPort { "", ParseAndValidatePort(arg, errors) }; |
||
848 |
} |
||
849 |
// Host and port found: |
||
850 |
return HostPort { RemoveBrackets(arg.substr(0, colon)), |
||
851 |
ParseAndValidatePort(arg.substr(colon + 1), errors) }; |
||
852 |
} |
||
853 |
|||
854 |
std::string GetBashCompletion() { |
||
855 |
Mutex::ScopedLock lock(per_process::cli_options_mutex); |
||
856 |
const auto& parser = _ppop_instance; |
||
857 |
|||
858 |
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 |
" COMPREPLY=( $(compgen -W '"; |
||
865 |
|||
866 |
for (const auto& item : parser.options_) { |
||
867 |
if (item.first[0] != '[') { |
||
868 |
out << item.first << " "; |
||
869 |
} |
||
870 |
} |
||
871 |
for (const auto& item : parser.aliases_) { |
||
872 |
if (item.first[0] != '[') { |
||
873 |
out << item.first << " "; |
||
874 |
} |
||
875 |
} |
||
876 |
if (parser.aliases_.size() > 0) { |
||
877 |
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 |
"-F _node_complete node node_g"; |
||
889 |
return out.str(); |
||
890 |
} |
||
891 |
|||
892 |
// Return a map containing all the options and their metadata as well |
||
893 |
// as the aliases |
||
894 |
120 |
void GetOptions(const FunctionCallbackInfo<Value>& args) { |
|
895 |
240 |
Mutex::ScopedLock lock(per_process::cli_options_mutex); |
|
896 |
120 |
Environment* env = Environment::GetCurrent(args); |
|
897 |
✗✓ | 120 |
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 |
120 |
env->set_has_serialized_options(true); |
|
903 |
|||
904 |
120 |
Isolate* isolate = env->isolate(); |
|
905 |
120 |
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 |
✓✗ | 240 |
auto original_per_isolate = per_process::cli_options->per_isolate; |
911 |
120 |
per_process::cli_options->per_isolate = env->isolate_data()->options(); |
|
912 |
✓✗ | 240 |
auto original_per_env = per_process::cli_options->per_isolate->per_env; |
913 |
120 |
per_process::cli_options->per_isolate->per_env = env->options(); |
|
914 |
120 |
auto on_scope_leave = OnScopeLeave([&]() { |
|
915 |
120 |
per_process::cli_options->per_isolate->per_env = original_per_env; |
|
916 |
120 |
per_process::cli_options->per_isolate = original_per_isolate; |
|
917 |
✓✗ | 360 |
}); |
918 |
|||
919 |
120 |
Local<Map> options = Map::New(isolate); |
|
920 |
✗✓ | 240 |
if (options |
921 |
360 |
->SetPrototype(context, env->primordials_safe_map_prototype_object()) |
|
922 |
.IsNothing()) { |
||
923 |
return; |
||
924 |
} |
||
925 |
|||
926 |
✓✓ | 14640 |
for (const auto& item : _ppop_instance.options_) { |
927 |
Local<Value> value; |
||
928 |
14520 |
const auto& option_info = item.second; |
|
929 |
29040 |
auto field = option_info.field; |
|
930 |
14520 |
PerProcessOptions* opts = per_process::cli_options.get(); |
|
931 |
✓✓✓✓ ✓✓✓✗ |
14520 |
switch (option_info.type) { |
932 |
case kNoOp: |
||
933 |
case kV8Option: |
||
934 |
// Special case for --abort-on-uncaught-exception which is also |
||
935 |
// respected by Node.js internals |
||
936 |
✓✓ | 2280 |
if (item.first == "--abort-on-uncaught-exception") { |
937 |
120 |
value = Boolean::New( |
|
938 |
240 |
isolate, original_per_env->abort_on_uncaught_exception); |
|
939 |
} else { |
||
940 |
2160 |
value = Undefined(isolate); |
|
941 |
} |
||
942 |
2280 |
break; |
|
943 |
case kBoolean: |
||
944 |
7680 |
value = Boolean::New(isolate, |
|
945 |
15360 |
*_ppop_instance.Lookup<bool>(field, opts)); |
|
946 |
7680 |
break; |
|
947 |
case kInteger: |
||
948 |
480 |
value = Number::New( |
|
949 |
isolate, |
||
950 |
960 |
static_cast<double>(*_ppop_instance.Lookup<int64_t>(field, opts))); |
|
951 |
480 |
break; |
|
952 |
case kUInteger: |
||
953 |
360 |
value = Number::New( |
|
954 |
isolate, |
||
955 |
720 |
static_cast<double>(*_ppop_instance.Lookup<uint64_t>(field, opts))); |
|
956 |
360 |
break; |
|
957 |
case kString: |
||
958 |
✗✓ | 9720 |
if (!ToV8Value(context, |
959 |
6480 |
*_ppop_instance.Lookup<std::string>(field, opts)) |
|
960 |
3240 |
.ToLocal(&value)) { |
|
961 |
return; |
||
962 |
} |
||
963 |
3240 |
break; |
|
964 |
case kStringList: |
||
965 |
✗✓ | 1080 |
if (!ToV8Value(context, |
966 |
720 |
*_ppop_instance.Lookup<StringVector>(field, opts)) |
|
967 |
360 |
.ToLocal(&value)) { |
|
968 |
return; |
||
969 |
} |
||
970 |
360 |
break; |
|
971 |
case kHostPort: { |
||
972 |
const HostPort& host_port = |
||
973 |
120 |
*_ppop_instance.Lookup<HostPort>(field, opts); |
|
974 |
120 |
Local<Object> obj = Object::New(isolate); |
|
975 |
Local<Value> host; |
||
976 |
✓✗✗✓ |
600 |
if (!ToV8Value(context, host_port.host()).ToLocal(&host) || |
977 |
✓✗✗✓ |
600 |
obj->Set(context, env->host_string(), host).IsNothing() || |
978 |
240 |
obj->Set(context, |
|
979 |
env->port_string(), |
||
980 |
480 |
Integer::New(isolate, host_port.port())) |
|
981 |
120 |
.IsNothing()) { |
|
982 |
return; |
||
983 |
} |
||
984 |
120 |
value = obj; |
|
985 |
120 |
break; |
|
986 |
} |
||
987 |
default: |
||
988 |
UNREACHABLE(); |
||
989 |
} |
||
990 |
✗✓ | 14520 |
CHECK(!value.IsEmpty()); |
991 |
|||
992 |
29040 |
Local<Value> name = ToV8Value(context, item.first).ToLocalChecked(); |
|
993 |
14520 |
Local<Object> info = Object::New(isolate); |
|
994 |
Local<Value> help_text; |
||
995 |
✓✗✗✓ |
72600 |
if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) || |
996 |
58080 |
!info->Set(context, env->help_text_string(), help_text) |
|
997 |
✓✗ | 58080 |
.FromMaybe(false) || |
998 |
43560 |
!info->Set(context, |
|
999 |
env->env_var_settings_string(), |
||
1000 |
Integer::New(isolate, |
||
1001 |
58080 |
static_cast<int>(option_info.env_setting))) |
|
1002 |
✓✗ | 58080 |
.FromMaybe(false) || |
1003 |
43560 |
!info->Set(context, |
|
1004 |
env->type_string(), |
||
1005 |
58080 |
Integer::New(isolate, static_cast<int>(option_info.type))) |
|
1006 |
✓✗ | 58080 |
.FromMaybe(false) || |
1007 |
✓✗✗✓ |
87120 |
info->Set(context, env->value_string(), value).IsNothing() || |
1008 |
43560 |
options->Set(context, name, info).IsEmpty()) { |
|
1009 |
return; |
||
1010 |
} |
||
1011 |
} |
||
1012 |
|||
1013 |
Local<Value> aliases; |
||
1014 |
✗✓ | 240 |
if (!ToV8Value(context, _ppop_instance.aliases_).ToLocal(&aliases)) return; |
1015 |
|||
1016 |
✗✓ | 480 |
if (aliases.As<Object>() |
1017 |
480 |
->SetPrototype(context, env->primordials_safe_map_prototype_object()) |
|
1018 |
.IsNothing()) { |
||
1019 |
return; |
||
1020 |
} |
||
1021 |
|||
1022 |
120 |
Local<Object> ret = Object::New(isolate); |
|
1023 |
✓✗✗✓ ✗✓ |
600 |
if (ret->Set(context, env->options_string(), options).IsNothing() || |
1024 |
480 |
ret->Set(context, env->aliases_string(), aliases).IsNothing()) { |
|
1025 |
return; |
||
1026 |
} |
||
1027 |
|||
1028 |
✓✗ | 240 |
args.GetReturnValue().Set(ret); |
1029 |
} |
||
1030 |
|||
1031 |
120 |
void Initialize(Local<Object> target, |
|
1032 |
Local<Value> unused, |
||
1033 |
Local<Context> context, |
||
1034 |
void* priv) { |
||
1035 |
120 |
Environment* env = Environment::GetCurrent(context); |
|
1036 |
120 |
Isolate* isolate = env->isolate(); |
|
1037 |
120 |
env->SetMethodNoSideEffect(target, "getOptions", GetOptions); |
|
1038 |
|||
1039 |
120 |
Local<Object> env_settings = Object::New(isolate); |
|
1040 |
240 |
NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment); |
|
1041 |
120 |
NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvironment); |
|
1042 |
480 |
target |
|
1043 |
600 |
->Set( |
|
1044 |
720 |
context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings) |
|
1045 |
240 |
.Check(); |
|
1046 |
|||
1047 |
target |
||
1048 |
240 |
->Set(context, |
|
1049 |
FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), |
||
1050 |
480 |
Boolean::New(isolate, env->should_not_register_esm_loader())) |
|
1051 |
.Check(); |
||
1052 |
|||
1053 |
120 |
Local<Object> types = Object::New(isolate); |
|
1054 |
120 |
NODE_DEFINE_CONSTANT(types, kNoOp); |
|
1055 |
360 |
NODE_DEFINE_CONSTANT(types, kV8Option); |
|
1056 |
480 |
NODE_DEFINE_CONSTANT(types, kBoolean); |
|
1057 |
840 |
NODE_DEFINE_CONSTANT(types, kInteger); |
|
1058 |
1080 |
NODE_DEFINE_CONSTANT(types, kUInteger); |
|
1059 |
1080 |
NODE_DEFINE_CONSTANT(types, kString); |
|
1060 |
1080 |
NODE_DEFINE_CONSTANT(types, kHostPort); |
|
1061 |
1080 |
NODE_DEFINE_CONSTANT(types, kStringList); |
|
1062 |
1320 |
target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "types"), types) |
|
1063 |
720 |
.Check(); |
|
1064 |
720 |
} |
|
1065 |
240 |
||
1066 |
} // namespace options_parser |
||
1067 |
|||
1068 |
115 |
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options) { |
|
1069 |
690 |
HandleEnvOptions(env_options, [](const char* name) { |
|
1070 |
920 |
std::string text; |
|
1071 |
✗✓✓✗ |
920 |
return credentials::SafeGetenv(name, &text) ? text : ""; |
1072 |
115 |
}); |
|
1073 |
115 |
} |
|
1074 |
|||
1075 |
115 |
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options, |
|
1076 |
std::function<std::string(const char*)> opt_getter) { |
||
1077 |
230 |
env_options->pending_deprecation = |
|
1078 |
230 |
opt_getter("NODE_PENDING_DEPRECATION") == "1"; |
|
1079 |
|||
1080 |
115 |
env_options->preserve_symlinks = opt_getter("NODE_PRESERVE_SYMLINKS") == "1"; |
|
1081 |
|||
1082 |
230 |
env_options->preserve_symlinks_main = |
|
1083 |
230 |
opt_getter("NODE_PRESERVE_SYMLINKS_MAIN") == "1"; |
|
1084 |
|||
1085 |
✓✗ | 115 |
if (env_options->redirect_warnings.empty()) |
1086 |
115 |
env_options->redirect_warnings = opt_getter("NODE_REDIRECT_WARNINGS"); |
|
1087 |
115 |
} |
|
1088 |
|||
1089 |
std::vector<std::string> ParseNodeOptionsEnvVar( |
||
1090 |
const std::string& node_options, std::vector<std::string>* errors) { |
||
1091 |
std::vector<std::string> env_argv; |
||
1092 |
|||
1093 |
bool is_in_string = false; |
||
1094 |
bool will_start_new_arg = true; |
||
1095 |
for (std::string::size_type index = 0; index < node_options.size(); ++index) { |
||
1096 |
char c = node_options.at(index); |
||
1097 |
|||
1098 |
// Backslashes escape the following character |
||
1099 |
if (c == '\\' && is_in_string) { |
||
1100 |
if (index + 1 == node_options.size()) { |
||
1101 |
errors->push_back("invalid value for NODE_OPTIONS " |
||
1102 |
"(invalid escape)\n"); |
||
1103 |
return env_argv; |
||
1104 |
} else { |
||
1105 |
c = node_options.at(++index); |
||
1106 |
} |
||
1107 |
} else if (c == ' ' && !is_in_string) { |
||
1108 |
will_start_new_arg = true; |
||
1109 |
continue; |
||
1110 |
} else if (c == '"') { |
||
1111 |
is_in_string = !is_in_string; |
||
1112 |
continue; |
||
1113 |
} |
||
1114 |
|||
1115 |
if (will_start_new_arg) { |
||
1116 |
env_argv.emplace_back(std::string(1, c)); |
||
1117 |
will_start_new_arg = false; |
||
1118 |
} else { |
||
1119 |
env_argv.back() += c; |
||
1120 |
} |
||
1121 |
} |
||
1122 |
|||
1123 |
if (is_in_string) { |
||
1124 |
errors->push_back("invalid value for NODE_OPTIONS " |
||
1125 |
"(unterminated string)\n"); |
||
1126 |
} |
||
1127 |
return env_argv; |
||
1128 |
} |
||
1129 |
} // namespace node |
||
1130 |
|||
1131 |
✓✗✓✗ |
481 |
NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize) |
Generated by: GCOVR (Version 3.4) |