GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_options.cc Lines: 518 548 94.5 %
Date: 2020-08-07 22:13:19 Branches: 191 250 76.4 %

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 <cstdlib>  // strtoul, errno
11
12
using v8::Boolean;
13
using v8::Context;
14
using v8::FunctionCallbackInfo;
15
using v8::Integer;
16
using v8::Isolate;
17
using v8::Local;
18
using v8::Map;
19
using v8::Number;
20
using v8::Object;
21
using v8::Undefined;
22
using v8::Value;
23
24
namespace node {
25
26
namespace per_process {
27
4441
Mutex cli_options_mutex;
28
4441
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
29
}  // namespace per_process
30
31
8838
void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
32
#if !NODE_USE_V8_PLATFORM && !HAVE_INSPECTOR
33
  if (inspector_enabled) {
34
    errors->push_back("Inspector is not available when Node is compiled "
35
                      "--without-v8-platform and --without-inspector.");
36
  }
37
#endif
38
39
8838
  if (deprecated_debug) {
40
8
    errors->push_back("[DEP0062]: `node --debug` and `node --debug-brk` "
41
                      "are invalid. Please use `node --inspect` and "
42
4
                      "`node --inspect-brk` instead.");
43
  }
44
45
  std::vector<std::string> destinations =
46
17676
      SplitString(inspect_publish_uid_string, ',');
47
8838
  inspect_publish_uid.console = false;
48
8838
  inspect_publish_uid.http = false;
49
26512
  for (const std::string& destination : destinations) {
50
17674
    if (destination == "stderr") {
51
8837
      inspect_publish_uid.console = true;
52
8837
    } else if (destination == "http") {
53
8837
      inspect_publish_uid.http = true;
54
    } else {
55
      errors->push_back("--inspect-publish-uid destination can be "
56
                        "stderr or http");
57
    }
58
  }
59
8838
}
60
61
8755
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
62
#if HAVE_OPENSSL
63

8755
  if (use_openssl_ca && use_bundled_ca) {
64
2
    errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
65
1
                      "used, not both");
66
  }
67
#endif
68

17512
  if (use_largepages != "off" &&
69

8756
      use_largepages != "on" &&
70
1
      use_largepages != "silent") {
71
1
    errors->push_back("invalid value for --use-largepages");
72
  }
73
8755
  per_isolate->CheckOptions(errors);
74
8755
}
75
76
8838
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
77
8838
  per_env->CheckOptions(errors);
78
8838
}
79
80
8838
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
81

8838
  if (has_policy_integrity_string && experimental_policy.empty()) {
82
    errors->push_back("--policy-integrity requires "
83
                      "--experimental-policy be enabled");
84
  }
85

8838
  if (has_policy_integrity_string && experimental_policy_integrity.empty()) {
86
1
    errors->push_back("--policy-integrity cannot be empty");
87
  }
88
89
8838
  if (!module_type.empty()) {
90

16
    if (module_type != "commonjs" && module_type != "module") {
91
      errors->push_back("--input-type must be \"module\" or \"commonjs\"");
92
    }
93
  }
94
95
8838
  if (!es_module_specifier_resolution.empty()) {
96
6
    if (!experimental_specifier_resolution.empty()) {
97
2
      errors->push_back(
98
        "bad option: cannot use --es-module-specifier-resolution"
99
1
        " and --experimental-specifier-resolution at the same time");
100
    } else {
101
5
      experimental_specifier_resolution = es_module_specifier_resolution;
102

5
      if (experimental_specifier_resolution != "node" &&
103
          experimental_specifier_resolution != "explicit") {
104
        errors->push_back(
105
          "invalid value for --es-module-specifier-resolution");
106
      }
107
    }
108
8832
  } else if (!experimental_specifier_resolution.empty()) {
109

1
    if (experimental_specifier_resolution != "node" &&
110
        experimental_specifier_resolution != "explicit") {
111
      errors->push_back(
112
        "invalid value for --experimental-specifier-resolution");
113
    }
114
  }
115
116

8838
  if (syntax_check_only && has_eval_string) {
117
4
    errors->push_back("either --check or --eval can be used, not both");
118
  }
119
120

17690
  if (!unhandled_rejections.empty() &&
121
27
      unhandled_rejections != "warn-with-error-code" &&
122
24
      unhandled_rejections != "throw" &&
123
20
      unhandled_rejections != "strict" &&
124

8854
      unhandled_rejections != "warn" &&
125
7
      unhandled_rejections != "none") {
126
1
    errors->push_back("invalid value for --unhandled-rejections");
127
  }
128
129

8838
  if (tls_min_v1_3 && tls_max_v1_2) {
130
2
    errors->push_back("either --tls-min-v1.3 or --tls-max-v1.2 can be "
131
1
                      "used, not both");
132
  }
133
134
#if HAVE_INSPECTOR
135
8838
  if (!cpu_prof) {
136
8827
    if (!cpu_prof_name.empty()) {
137
1
      errors->push_back("--cpu-prof-name must be used with --cpu-prof");
138
    }
139
8827
    if (!cpu_prof_dir.empty()) {
140
1
      errors->push_back("--cpu-prof-dir must be used with --cpu-prof");
141
    }
142
    // We can't catch the case where the value passed is the default value,
143
    // then the option just becomes a noop which is fine.
144
8827
    if (cpu_prof_interval != kDefaultCpuProfInterval) {
145
1
      errors->push_back("--cpu-prof-interval must be used with --cpu-prof");
146
    }
147
  }
148
149


8838
  if (cpu_prof && cpu_prof_dir.empty() && !diagnostic_dir.empty()) {
150
1
      cpu_prof_dir = diagnostic_dir;
151
    }
152
153
8838
  if (!heap_prof) {
154
8827
    if (!heap_prof_name.empty()) {
155
1
      errors->push_back("--heap-prof-name must be used with --heap-prof");
156
    }
157
8827
    if (!heap_prof_dir.empty()) {
158
1
      errors->push_back("--heap-prof-dir must be used with --heap-prof");
159
    }
160
    // We can't catch the case where the value passed is the default value,
161
    // then the option just becomes a noop which is fine.
162
8827
    if (heap_prof_interval != kDefaultHeapProfInterval) {
163
1
      errors->push_back("--heap-prof-interval must be used with --heap-prof");
164
    }
165
  }
166
167


8838
  if (heap_prof && heap_prof_dir.empty() && !diagnostic_dir.empty()) {
168
1
    heap_prof_dir = diagnostic_dir;
169
  }
170
171
8838
  debug_options_.CheckOptions(errors);
172
#endif  // HAVE_INSPECTOR
173
8838
}
174
175
namespace options_parser {
176
177
4441
class DebugOptionsParser : public OptionsParser<DebugOptions> {
178
 public:
179
  DebugOptionsParser();
180
};
181
182
4441
class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> {
183
 public:
184
  EnvironmentOptionsParser();
185
4441
  explicit EnvironmentOptionsParser(const DebugOptionsParser& dop)
186
4441
    : EnvironmentOptionsParser() {
187
4441
    Insert(dop, &EnvironmentOptions::get_debug_options);
188
4441
  }
189
};
190
191
4441
class PerIsolateOptionsParser : public OptionsParser<PerIsolateOptions> {
192
 public:
193
  PerIsolateOptionsParser() = delete;
194
  explicit PerIsolateOptionsParser(const EnvironmentOptionsParser& eop);
195
};
196
197
4441
class PerProcessOptionsParser : public OptionsParser<PerProcessOptions> {
198
 public:
199
  PerProcessOptionsParser() = delete;
200
  explicit PerProcessOptionsParser(const PerIsolateOptionsParser& iop);
201
};
202
203
#if HAVE_INSPECTOR
204
4441
const DebugOptionsParser _dop_instance{};
205
4441
const EnvironmentOptionsParser _eop_instance{_dop_instance};
206
207
// This Parse is not dead code. It is used by embedders (e.g., Electron).
208
template <>
209
void Parse(
210
  StringVector* const args, StringVector* const exec_args,
211
  StringVector* const v8_args,
212
  DebugOptions* const options,
213
  OptionEnvvarSettings required_env_settings, StringVector* const errors) {
214
  _dop_instance.Parse(
215
    args, exec_args, v8_args, options, required_env_settings, errors);
216
}
217
#else
218
const EnvironmentOptionsParser _eop_instance{};
219
#endif  // HAVE_INSPECTOR
220
4441
const PerIsolateOptionsParser _piop_instance{_eop_instance};
221
4441
const PerProcessOptionsParser _ppop_instance{_piop_instance};
222
223
template <>
224
83
void Parse(
225
  StringVector* const args, StringVector* const exec_args,
226
  StringVector* const v8_args,
227
  PerIsolateOptions* const options,
228
  OptionEnvvarSettings required_env_settings, StringVector* const errors) {
229
  _piop_instance.Parse(
230
83
    args, exec_args, v8_args, options, required_env_settings, errors);
231
83
}
232
233
template <>
234
8755
void Parse(
235
  StringVector* const args, StringVector* const exec_args,
236
  StringVector* const v8_args,
237
  PerProcessOptions* const options,
238
  OptionEnvvarSettings required_env_settings, StringVector* const errors) {
239
  _ppop_instance.Parse(
240
8755
    args, exec_args, v8_args, options, required_env_settings, errors);
241
8755
}
242
243
// XXX: If you add an option here, please also add it to doc/node.1 and
244
// doc/api/cli.md
245
// TODO(addaleax): Make that unnecessary.
246
247
4441
DebugOptionsParser::DebugOptionsParser() {
248
4441
  AddOption("--inspect-port",
249
            "set host:port for inspector",
250
            &DebugOptions::host_port,
251
4441
            kAllowedInEnvironment);
252
4441
  AddAlias("--debug-port", "--inspect-port");
253
254
4441
  AddOption("--inspect",
255
            "activate inspector on host:port (default: 127.0.0.1:9229)",
256
            &DebugOptions::inspector_enabled,
257
4441
            kAllowedInEnvironment);
258
4441
  AddAlias("--inspect=", { "--inspect-port", "--inspect" });
259
260
4441
  AddOption("--debug", "", &DebugOptions::deprecated_debug);
261
4441
  AddAlias("--debug=", "--debug");
262
4441
  AddOption("--debug-brk", "", &DebugOptions::deprecated_debug);
263
4441
  AddAlias("--debug-brk=", "--debug-brk");
264
265
4441
  AddOption("--inspect-brk",
266
            "activate inspector on host:port and break at start of user script",
267
            &DebugOptions::break_first_line,
268
4441
            kAllowedInEnvironment);
269
4441
  Implies("--inspect-brk", "--inspect");
270
4441
  AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" });
271
272
4441
  AddOption("--inspect-brk-node", "", &DebugOptions::break_node_first_line);
273
4441
  Implies("--inspect-brk-node", "--inspect");
274
4441
  AddAlias("--inspect-brk-node=", { "--inspect-port", "--inspect-brk-node" });
275
276
4441
  AddOption("--inspect-publish-uid",
277
            "comma separated list of destinations for inspector uid"
278
            "(default: stderr,http)",
279
            &DebugOptions::inspect_publish_uid_string,
280
4441
            kAllowedInEnvironment);
281
4441
}
282
283
4441
EnvironmentOptionsParser::EnvironmentOptionsParser() {
284
4441
  AddOption("--diagnostic-dir",
285
            "set dir for all output files"
286
            " (default: current working directory)",
287
            &EnvironmentOptions::diagnostic_dir,
288
4441
            kAllowedInEnvironment);
289
4441
  AddOption("--enable-source-maps",
290
            "experimental Source Map V3 support",
291
            &EnvironmentOptions::enable_source_maps,
292
4441
            kAllowedInEnvironment);
293
4441
  AddOption("--experimental-abortcontroller", "",
294
4441
            NoOp{}, kAllowedInEnvironment);
295
4441
  AddOption("--experimental-json-modules",
296
            "experimental JSON interop support for the ES Module loader",
297
            &EnvironmentOptions::experimental_json_modules,
298
4441
            kAllowedInEnvironment);
299
4441
  AddOption("--experimental-loader",
300
            "use the specified module as a custom loader",
301
            &EnvironmentOptions::userland_loader,
302
4441
            kAllowedInEnvironment);
303
4441
  AddAlias("--loader", "--experimental-loader");
304
4441
  AddOption("--experimental-modules",
305
            "",
306
            &EnvironmentOptions::experimental_modules,
307
4441
            kAllowedInEnvironment);
308
4441
  AddOption("--experimental-wasm-modules",
309
            "experimental ES Module support for webassembly modules",
310
            &EnvironmentOptions::experimental_wasm_modules,
311
4441
            kAllowedInEnvironment);
312
4441
  AddOption("--experimental-import-meta-resolve",
313
            "experimental ES Module import.meta.resolve() support",
314
            &EnvironmentOptions::experimental_import_meta_resolve,
315
4441
            kAllowedInEnvironment);
316
4441
  AddOption("--experimental-policy",
317
            "use the specified file as a "
318
            "security policy",
319
            &EnvironmentOptions::experimental_policy,
320
4441
            kAllowedInEnvironment);
321
4441
  AddOption("[has_policy_integrity_string]",
322
            "",
323
4441
            &EnvironmentOptions::has_policy_integrity_string);
324
4441
  AddOption("--policy-integrity",
325
            "ensure the security policy contents match "
326
            "the specified integrity",
327
            &EnvironmentOptions::experimental_policy_integrity,
328
4441
            kAllowedInEnvironment);
329
4441
  Implies("--policy-integrity", "[has_policy_integrity_string]");
330
4441
  AddOption("--experimental-repl-await",
331
            "experimental await keyword support in REPL",
332
            &EnvironmentOptions::experimental_repl_await,
333
4441
            kAllowedInEnvironment);
334
4441
  AddOption("--experimental-vm-modules",
335
            "experimental ES Module support in vm module",
336
            &EnvironmentOptions::experimental_vm_modules,
337
4441
            kAllowedInEnvironment);
338
4441
  AddOption("--experimental-worker", "", NoOp{}, kAllowedInEnvironment);
339
4441
  AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvironment);
340
4441
  AddOption("--experimental-wasi-unstable-preview1",
341
            "experimental WASI support",
342
            &EnvironmentOptions::experimental_wasi,
343
4441
            kAllowedInEnvironment);
344
4441
  AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
345
4441
  AddOption("--frozen-intrinsics",
346
            "experimental frozen intrinsics support",
347
            &EnvironmentOptions::frozen_intrinsics,
348
4441
            kAllowedInEnvironment);
349
4441
  AddOption("--heapsnapshot-signal",
350
            "Generate heap snapshot on specified signal",
351
            &EnvironmentOptions::heap_snapshot_signal,
352
4441
            kAllowedInEnvironment);
353
4441
  AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment);
354
4441
  AddOption("--insecure-http-parser",
355
            "use an insecure HTTP parser that accepts invalid HTTP headers",
356
            &EnvironmentOptions::insecure_http_parser,
357
4441
            kAllowedInEnvironment);
358
4441
  AddOption("--input-type",
359
            "set module type for string input",
360
            &EnvironmentOptions::module_type,
361
4441
            kAllowedInEnvironment);
362
4441
  AddOption("--experimental-specifier-resolution",
363
            "Select extension resolution algorithm for es modules; "
364
            "either 'explicit' (default) or 'node'",
365
            &EnvironmentOptions::experimental_specifier_resolution,
366
4441
            kAllowedInEnvironment);
367
4441
  AddOption("--es-module-specifier-resolution",
368
            "",
369
            &EnvironmentOptions::es_module_specifier_resolution,
370
4441
            kAllowedInEnvironment);
371
4441
  AddOption("--no-deprecation",
372
            "silence deprecation warnings",
373
            &EnvironmentOptions::no_deprecation,
374
4441
            kAllowedInEnvironment);
375
4441
  AddOption("--no-force-async-hooks-checks",
376
            "disable checks for async_hooks",
377
            &EnvironmentOptions::no_force_async_hooks_checks,
378
4441
            kAllowedInEnvironment);
379
4441
  AddOption("--no-warnings",
380
            "silence all process warnings",
381
            &EnvironmentOptions::no_warnings,
382
4441
            kAllowedInEnvironment);
383
4441
  AddOption("--force-context-aware",
384
            "disable loading non-context-aware addons",
385
            &EnvironmentOptions::force_context_aware,
386
4441
            kAllowedInEnvironment);
387
4441
  AddOption("--pending-deprecation",
388
            "emit pending deprecation warnings",
389
            &EnvironmentOptions::pending_deprecation,
390
4441
            kAllowedInEnvironment);
391
4441
  AddOption("--preserve-symlinks",
392
            "preserve symbolic links when resolving",
393
            &EnvironmentOptions::preserve_symlinks,
394
4441
            kAllowedInEnvironment);
395
4441
  AddOption("--preserve-symlinks-main",
396
            "preserve symbolic links when resolving the main module",
397
            &EnvironmentOptions::preserve_symlinks_main,
398
4441
            kAllowedInEnvironment);
399
4441
  AddOption("--prof-process",
400
            "process V8 profiler output generated using --prof",
401
4441
            &EnvironmentOptions::prof_process);
402
  // Options after --prof-process are passed through to the prof processor.
403
4441
  AddAlias("--prof-process", { "--prof-process", "--" });
404
#if HAVE_INSPECTOR
405
4441
  AddOption("--cpu-prof",
406
            "Start the V8 CPU profiler on start up, and write the CPU profile "
407
            "to disk before exit. If --cpu-prof-dir is not specified, write "
408
            "the profile to the current working directory.",
409
4441
            &EnvironmentOptions::cpu_prof);
410
4441
  AddOption("--cpu-prof-name",
411
            "specified file name of the V8 CPU profile generated with "
412
            "--cpu-prof",
413
4441
            &EnvironmentOptions::cpu_prof_name);
414
4441
  AddOption("--cpu-prof-interval",
415
            "specified sampling interval in microseconds for the V8 CPU "
416
            "profile generated with --cpu-prof. (default: 1000)",
417
4441
            &EnvironmentOptions::cpu_prof_interval);
418
4441
  AddOption("--cpu-prof-dir",
419
            "Directory where the V8 profiles generated by --cpu-prof will be "
420
            "placed. Does not affect --prof.",
421
4441
            &EnvironmentOptions::cpu_prof_dir);
422
4441
  AddOption(
423
      "--heap-prof",
424
      "Start the V8 heap profiler on start up, and write the heap profile "
425
      "to disk before exit. If --heap-prof-dir is not specified, write "
426
      "the profile to the current working directory.",
427
4441
      &EnvironmentOptions::heap_prof);
428
4441
  AddOption("--heap-prof-name",
429
            "specified file name of the V8 heap profile generated with "
430
            "--heap-prof",
431
4441
            &EnvironmentOptions::heap_prof_name);
432
4441
  AddOption("--heap-prof-dir",
433
            "Directory where the V8 heap profiles generated by --heap-prof "
434
            "will be placed.",
435
4441
            &EnvironmentOptions::heap_prof_dir);
436
4441
  AddOption("--heap-prof-interval",
437
            "specified sampling interval in bytes for the V8 heap "
438
            "profile generated with --heap-prof. (default: 512 * 1024)",
439
4441
            &EnvironmentOptions::heap_prof_interval);
440
#endif  // HAVE_INSPECTOR
441
4441
  AddOption("--max-http-header-size",
442
            "set the maximum size of HTTP headers (default: 16384 (16KB))",
443
            &EnvironmentOptions::max_http_header_size,
444
4441
            kAllowedInEnvironment);
445
4441
  AddOption("--redirect-warnings",
446
            "write warnings to file instead of stderr",
447
            &EnvironmentOptions::redirect_warnings,
448
4441
            kAllowedInEnvironment);
449
4441
  AddOption("--test-udp-no-try-send", "",  // For testing only.
450
4441
            &EnvironmentOptions::test_udp_no_try_send);
451
4441
  AddOption("--throw-deprecation",
452
            "throw an exception on deprecations",
453
            &EnvironmentOptions::throw_deprecation,
454
4441
            kAllowedInEnvironment);
455
4441
  AddOption("--trace-atomics-wait",
456
            "trace Atomics.wait() operations",
457
            &EnvironmentOptions::trace_atomics_wait,
458
4441
            kAllowedInEnvironment);
459
4441
  AddOption("--trace-deprecation",
460
            "show stack traces on deprecations",
461
            &EnvironmentOptions::trace_deprecation,
462
4441
            kAllowedInEnvironment);
463
4441
  AddOption("--trace-exit",
464
            "show stack trace when an environment exits",
465
            &EnvironmentOptions::trace_exit,
466
4441
            kAllowedInEnvironment);
467
4441
  AddOption("--trace-sync-io",
468
            "show stack trace when use of sync IO is detected after the "
469
            "first tick",
470
            &EnvironmentOptions::trace_sync_io,
471
4441
            kAllowedInEnvironment);
472
4441
  AddOption("--trace-tls",
473
            "prints TLS packet trace information to stderr",
474
            &EnvironmentOptions::trace_tls,
475
4441
            kAllowedInEnvironment);
476
4441
  AddOption("--trace-uncaught",
477
            "show stack traces for the `throw` behind uncaught exceptions",
478
            &EnvironmentOptions::trace_uncaught,
479
4441
            kAllowedInEnvironment);
480
4441
  AddOption("--trace-warnings",
481
            "show stack traces on process warnings",
482
            &EnvironmentOptions::trace_warnings,
483
4441
            kAllowedInEnvironment);
484
4441
  AddOption("--unhandled-rejections",
485
            "define unhandled rejections behavior. Options are 'strict' (raise "
486
            "an error), 'warn' (enforce warnings) or 'none' (silence warnings)",
487
            &EnvironmentOptions::unhandled_rejections,
488
4441
            kAllowedInEnvironment);
489
490
4441
  AddOption("--check",
491
            "syntax check script without executing",
492
4441
            &EnvironmentOptions::syntax_check_only);
493
4441
  AddAlias("-c", "--check");
494
  // This option is only so that we can tell --eval with an empty string from
495
  // no eval at all. Having it not start with a dash makes it inaccessible
496
  // from the parser itself, but available for using Implies().
497
  // TODO(addaleax): When moving --help over to something generated from the
498
  // programmatic descriptions, this will need some special care.
499
  // (See also [ssl_openssl_cert_store] below.)
500
4441
  AddOption("[has_eval_string]", "", &EnvironmentOptions::has_eval_string);
501
4441
  AddOption("--eval", "evaluate script", &EnvironmentOptions::eval_string);
502
4441
  Implies("--eval", "[has_eval_string]");
503
4441
  AddOption("--print",
504
            "evaluate script and print result",
505
4441
            &EnvironmentOptions::print_eval);
506
4441
  AddAlias("-e", "--eval");
507
4441
  AddAlias("--print <arg>", "-pe");
508
4441
  AddAlias("-pe", { "--print", "--eval" });
509
4441
  AddAlias("-p", "--print");
510
4441
  AddOption("--require",
511
            "module to preload (option can be repeated)",
512
            &EnvironmentOptions::preload_modules,
513
4441
            kAllowedInEnvironment);
514
4441
  AddAlias("-r", "--require");
515
4441
  AddOption("--interactive",
516
            "always enter the REPL even if stdin does not appear "
517
            "to be a terminal",
518
4441
            &EnvironmentOptions::force_repl);
519
4441
  AddAlias("-i", "--interactive");
520
521
4441
  AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment);
522
523
4441
  AddOption("--tls-keylog",
524
            "log TLS decryption keys to named file for traffic analysis",
525
4441
            &EnvironmentOptions::tls_keylog, kAllowedInEnvironment);
526
527
4441
  AddOption("--tls-min-v1.0",
528
            "set default TLS minimum to TLSv1.0 (default: TLSv1.2)",
529
            &EnvironmentOptions::tls_min_v1_0,
530
4441
            kAllowedInEnvironment);
531
4441
  AddOption("--tls-min-v1.1",
532
            "set default TLS minimum to TLSv1.1 (default: TLSv1.2)",
533
            &EnvironmentOptions::tls_min_v1_1,
534
4441
            kAllowedInEnvironment);
535
4441
  AddOption("--tls-min-v1.2",
536
            "set default TLS minimum to TLSv1.2 (default: TLSv1.2)",
537
            &EnvironmentOptions::tls_min_v1_2,
538
4441
            kAllowedInEnvironment);
539
4441
  AddOption("--tls-min-v1.3",
540
            "set default TLS minimum to TLSv1.3 (default: TLSv1.2)",
541
            &EnvironmentOptions::tls_min_v1_3,
542
4441
            kAllowedInEnvironment);
543
4441
  AddOption("--tls-max-v1.2",
544
            "set default TLS maximum to TLSv1.2 (default: TLSv1.3)",
545
            &EnvironmentOptions::tls_max_v1_2,
546
4441
            kAllowedInEnvironment);
547
  // Current plan is:
548
  // - 11.x and below: TLS1.3 is opt-in with --tls-max-v1.3
549
  // - 12.x: TLS1.3 is opt-out with --tls-max-v1.2
550
  // In either case, support both options they are uniformly available.
551
4441
  AddOption("--tls-max-v1.3",
552
            "set default TLS maximum to TLSv1.3 (default: TLSv1.3)",
553
            &EnvironmentOptions::tls_max_v1_3,
554
4441
            kAllowedInEnvironment);
555
4441
}
556
557
4441
PerIsolateOptionsParser::PerIsolateOptionsParser(
558
4441
  const EnvironmentOptionsParser& eop) {
559
4441
  AddOption("--track-heap-objects",
560
            "track heap object allocations for heap snapshots",
561
            &PerIsolateOptions::track_heap_objects,
562
4441
            kAllowedInEnvironment);
563
4441
  AddOption("--no-node-snapshot",
564
            "",  // It's a debug-only option.
565
            &PerIsolateOptions::no_node_snapshot,
566
4441
            kAllowedInEnvironment);
567
568
  // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
569
4441
  AddOption("--abort-on-uncaught-exception",
570
            "aborting instead of exiting causes a core file to be generated "
571
            "for analysis",
572
4441
            V8Option{},
573
4441
            kAllowedInEnvironment);
574
4441
  AddOption("--interpreted-frames-native-stack",
575
            "help system profilers to translate JavaScript interpreted frames",
576
4441
            V8Option{}, kAllowedInEnvironment);
577
4441
  AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvironment);
578
4441
  AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvironment);
579
4441
  AddOption("--perf-basic-prof-only-functions",
580
            "",
581
4441
            V8Option{},
582
4441
            kAllowedInEnvironment);
583
4441
  AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvironment);
584
4441
  AddOption("--perf-prof-unwinding-info",
585
            "",
586
4441
            V8Option{},
587
4441
            kAllowedInEnvironment);
588
4441
  AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment);
589
4441
  AddOption("--disallow-code-generation-from-strings",
590
            "disallow eval and friends",
591
4441
            V8Option{},
592
4441
            kAllowedInEnvironment);
593
4441
  AddOption("--huge-max-old-generation-size",
594
             "increase default maximum heap size on machines with 16GB memory "
595
             "or more",
596
4441
             V8Option{},
597
4441
             kAllowedInEnvironment);
598
4441
  AddOption("--jitless",
599
             "disable runtime allocation of executable memory",
600
4441
             V8Option{},
601
4441
             kAllowedInEnvironment);
602
4441
  AddOption("--report-uncaught-exception",
603
            "generate diagnostic report on uncaught exceptions",
604
            &PerIsolateOptions::report_uncaught_exception,
605
4441
            kAllowedInEnvironment);
606
4441
  AddOption("--report-on-signal",
607
            "generate diagnostic report upon receiving signals",
608
            &PerIsolateOptions::report_on_signal,
609
4441
            kAllowedInEnvironment);
610
4441
  AddOption("--report-signal",
611
            "causes diagnostic report to be produced on provided signal,"
612
            " unsupported in Windows. (default: SIGUSR2)",
613
            &PerIsolateOptions::report_signal,
614
4441
            kAllowedInEnvironment);
615
4441
  Implies("--report-signal", "--report-on-signal");
616
617
4441
  AddOption("--experimental-top-level-await",
618
            "",
619
            &PerIsolateOptions::experimental_top_level_await,
620
4441
            kAllowedInEnvironment);
621
4441
  AddOption("--harmony-top-level-await", "", V8Option{});
622
4441
  Implies("--experimental-top-level-await", "--harmony-top-level-await");
623
4441
  Implies("--harmony-top-level-await", "--experimental-top-level-await");
624
4441
  ImpliesNot("--no-harmony-top-level-await", "--experimental-top-level-await");
625
626
4441
  Insert(eop, &PerIsolateOptions::get_per_env_options);
627
4441
}
628
629
4441
PerProcessOptionsParser::PerProcessOptionsParser(
630
4441
  const PerIsolateOptionsParser& iop) {
631
4441
  AddOption("--title",
632
            "the process title to use on startup",
633
            &PerProcessOptions::title,
634
4441
            kAllowedInEnvironment);
635
4441
  AddOption("--trace-event-categories",
636
            "comma separated list of trace event categories to record",
637
            &PerProcessOptions::trace_event_categories,
638
4441
            kAllowedInEnvironment);
639
4441
  AddOption("--trace-event-file-pattern",
640
            "Template string specifying the filepath for the trace-events "
641
            "data, it supports ${rotation} and ${pid}.",
642
            &PerProcessOptions::trace_event_file_pattern,
643
4441
            kAllowedInEnvironment);
644
17764
  AddAlias("--trace-events-enabled", {
645
13323
    "--trace-event-categories", "v8,node,node.async_hooks" });
646
4441
  AddOption("--v8-pool-size",
647
            "set V8's thread pool size",
648
            &PerProcessOptions::v8_thread_pool_size,
649
4441
            kAllowedInEnvironment);
650
4441
  AddOption("--zero-fill-buffers",
651
            "automatically zero-fill all newly allocated Buffer and "
652
            "SlowBuffer instances",
653
            &PerProcessOptions::zero_fill_all_buffers,
654
4441
            kAllowedInEnvironment);
655
4441
  AddOption("--debug-arraybuffer-allocations",
656
            "", /* undocumented, only for debugging */
657
            &PerProcessOptions::debug_arraybuffer_allocations,
658
4441
            kAllowedInEnvironment);
659
4441
  AddOption("--disable-proto",
660
            "disable Object.prototype.__proto__",
661
            &PerProcessOptions::disable_proto,
662
4441
            kAllowedInEnvironment);
663
664
  // 12.x renamed this inadvertently, so alias it for consistency within the
665
  // release line, while using the original name for consistency with older
666
  // release lines.
667
4441
  AddOption("--security-revert", "", &PerProcessOptions::security_reverts);
668
4441
  AddAlias("--security-reverts", "--security-revert");
669
4441
  AddOption("--completion-bash",
670
            "print source-able bash completion script",
671
4441
            &PerProcessOptions::print_bash_completion);
672
4441
  AddOption("--help",
673
            "print node command line options",
674
4441
            &PerProcessOptions::print_help);
675
4441
  AddAlias("-h", "--help");
676
4441
  AddOption(
677
4441
      "--version", "print Node.js version", &PerProcessOptions::print_version);
678
4441
  AddAlias("-v", "--version");
679
4441
  AddOption("--v8-options",
680
            "print V8 command line options",
681
4441
            &PerProcessOptions::print_v8_help);
682
4441
  AddOption("--report-compact",
683
            "output compact single-line JSON",
684
            &PerProcessOptions::report_compact,
685
4441
            kAllowedInEnvironment);
686
4441
  AddOption("--report-dir",
687
            "define custom report pathname."
688
            " (default: current working directory)",
689
            &PerProcessOptions::report_directory,
690
4441
            kAllowedInEnvironment);
691
4441
  AddAlias("--report-directory", "--report-dir");
692
4441
  AddOption("--report-filename",
693
            "define custom report file name."
694
            " (default: YYYYMMDD.HHMMSS.PID.SEQUENCE#.txt)",
695
            &PerProcessOptions::report_filename,
696
4441
            kAllowedInEnvironment);
697
4441
  AddOption("--report-on-fatalerror",
698
              "generate diagnostic report on fatal (internal) errors",
699
              &PerProcessOptions::report_on_fatalerror,
700
4441
              kAllowedInEnvironment);
701
702
#ifdef NODE_HAVE_I18N_SUPPORT
703
4441
  AddOption("--icu-data-dir",
704
            "set ICU data load path to dir (overrides NODE_ICU_DATA)"
705
#ifndef NODE_HAVE_SMALL_ICU
706
            " (note: linked-in ICU data is present)\n"
707
#endif
708
            ,
709
            &PerProcessOptions::icu_data_dir,
710
4441
            kAllowedInEnvironment);
711
#endif
712
713
#if HAVE_OPENSSL
714
4441
  AddOption("--openssl-config",
715
            "load OpenSSL configuration from the specified file "
716
            "(overrides OPENSSL_CONF)",
717
            &PerProcessOptions::openssl_config,
718
4441
            kAllowedInEnvironment);
719
4441
  AddOption("--tls-cipher-list",
720
            "use an alternative default TLS cipher list",
721
            &PerProcessOptions::tls_cipher_list,
722
4441
            kAllowedInEnvironment);
723
4441
  AddOption("--use-openssl-ca",
724
            "use OpenSSL's default CA store"
725
#if defined(NODE_OPENSSL_CERT_STORE)
726
            " (default)"
727
#endif
728
            ,
729
            &PerProcessOptions::use_openssl_ca,
730
4441
            kAllowedInEnvironment);
731
4441
  AddOption("--use-bundled-ca",
732
            "use bundled CA store"
733
#if !defined(NODE_OPENSSL_CERT_STORE)
734
            " (default)"
735
#endif
736
            ,
737
            &PerProcessOptions::use_bundled_ca,
738
4441
            kAllowedInEnvironment);
739
  // Similar to [has_eval_string] above, except that the separation between
740
  // this and use_openssl_ca only exists for option validation after parsing.
741
  // This is not ideal.
742
4441
  AddOption("[ssl_openssl_cert_store]",
743
            "",
744
4441
            &PerProcessOptions::ssl_openssl_cert_store);
745
4441
  Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
746
4441
  ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]");
747
#if NODE_FIPS_MODE
748
  AddOption("--enable-fips",
749
            "enable FIPS crypto at startup",
750
            &PerProcessOptions::enable_fips_crypto,
751
            kAllowedInEnvironment);
752
  AddOption("--force-fips",
753
            "force FIPS crypto (cannot be disabled)",
754
            &PerProcessOptions::force_fips_crypto,
755
            kAllowedInEnvironment);
756
#endif
757
#endif
758
4441
  AddOption("--use-largepages",
759
            "Map the Node.js static code to large pages. Options are "
760
            "'off' (the default value, meaning do not map), "
761
            "'on' (map and ignore failure, reporting it to stderr), "
762
            "or 'silent' (map and silently ignore failure)",
763
            &PerProcessOptions::use_largepages,
764
4441
            kAllowedInEnvironment);
765
766
4441
  AddOption("--trace-sigint",
767
            "enable printing JavaScript stacktrace on SIGINT",
768
            &PerProcessOptions::trace_sigint,
769
4441
            kAllowedInEnvironment);
770
771
4441
  Insert(iop, &PerProcessOptions::get_per_isolate_options);
772
4441
}
773
774
112
inline std::string RemoveBrackets(const std::string& host) {
775


112
  if (!host.empty() && host.front() == '[' && host.back() == ']')
776
4
    return host.substr(1, host.size() - 2);
777
  else
778
108
    return host;
779
}
780
781
100
inline int ParseAndValidatePort(const std::string& port,
782
                                std::vector<std::string>* errors) {
783
  char* endptr;
784
100
  errno = 0;
785
  const unsigned long result =                 // NOLINT(runtime/int)
786
100
    strtoul(port.c_str(), &endptr, 10);
787

100
  if (errno != 0 || *endptr != '\0'||
788

63
      (result != 0 && result < 1024) || result > 65535) {
789
    errors->push_back(" must be 0 or in range 1024 to 65535.");
790
  }
791
100
  return static_cast<int>(result);
792
}
793
794
100
HostPort SplitHostPort(const std::string& arg,
795
                      std::vector<std::string>* errors) {
796
  // remove_brackets only works if no port is specified
797
  // so if it has an effect only an IPv6 address was specified.
798
200
  std::string host = RemoveBrackets(arg);
799
100
  if (host.length() < arg.length())
800
    return HostPort{host, DebugOptions::kDefaultInspectorPort};
801
802
100
  size_t colon = arg.rfind(':');
803
100
  if (colon == std::string::npos) {
804
    // Either a port number or a host name.  Assume that
805
    // if it's not all decimal digits, it's a host name.
806
390
    for (char c : arg) {
807

302
      if (c < '0' || c > '9') {
808
        return HostPort{arg, DebugOptions::kDefaultInspectorPort};
809
      }
810
    }
811
88
    return HostPort { "", ParseAndValidatePort(arg, errors) };
812
  }
813
  // Host and port found:
814
24
  return HostPort { RemoveBrackets(arg.substr(0, colon)),
815
12
                    ParseAndValidatePort(arg.substr(colon + 1), errors) };
816
}
817
818
1
std::string GetBashCompletion() {
819
2
  Mutex::ScopedLock lock(per_process::cli_options_mutex);
820
1
  const auto& parser = _ppop_instance;
821
822
2
  std::ostringstream out;
823
824
  out << "_node_complete() {\n"
825
         "  local cur_word options\n"
826
         "  cur_word=\"${COMP_WORDS[COMP_CWORD]}\"\n"
827
         "  if [[ \"${cur_word}\" == -* ]] ; then\n"
828
1
         "    COMPREPLY=( $(compgen -W '";
829
830
116
  for (const auto& item : parser.options_) {
831
115
    if (item.first[0] != '[') {
832
112
      out << item.first << " ";
833
    }
834
  }
835
21
  for (const auto& item : parser.aliases_) {
836
20
    if (item.first[0] != '[') {
837
20
      out << item.first << " ";
838
    }
839
  }
840
1
  if (parser.aliases_.size() > 0) {
841
1
    out.seekp(-1, out.cur);  // Strip the trailing space
842
  }
843
844
  out << "' -- \"${cur_word}\") )\n"
845
         "    return 0\n"
846
         "  else\n"
847
         "    COMPREPLY=( $(compgen -f \"${cur_word}\") )\n"
848
         "    return 0\n"
849
         "  fi\n"
850
         "}\n"
851
         "complete -o filenames -o nospace -o bashdefault "
852
1
         "-F _node_complete node node_g";
853
2
  return out.str();
854
}
855
856
// Return a map containing all the options and their metadata as well
857
// as the aliases
858
4732
void GetOptions(const FunctionCallbackInfo<Value>& args) {
859
9464
  Mutex::ScopedLock lock(per_process::cli_options_mutex);
860
4732
  Environment* env = Environment::GetCurrent(args);
861
4732
  if (!env->has_run_bootstrapping_code()) {
862
    // No code because this is an assertion.
863
    return env->ThrowError(
864
        "Should not query options before bootstrapping is done");
865
  }
866
4732
  env->set_has_serialized_options(true);
867
868
4732
  Isolate* isolate = env->isolate();
869
4732
  Local<Context> context = env->context();
870
871
  // Temporarily act as if the current Environment's/IsolateData's options were
872
  // the default options, i.e. like they are the ones we'd access for global
873
  // options parsing, so that all options are available from the main parser.
874
9464
  auto original_per_isolate = per_process::cli_options->per_isolate;
875
4732
  per_process::cli_options->per_isolate = env->isolate_data()->options();
876
9464
  auto original_per_env = per_process::cli_options->per_isolate->per_env;
877
4732
  per_process::cli_options->per_isolate->per_env = env->options();
878
4732
  auto on_scope_leave = OnScopeLeave([&]() {
879
4732
    per_process::cli_options->per_isolate->per_env = original_per_env;
880
4732
    per_process::cli_options->per_isolate = original_per_isolate;
881
14196
  });
882
883
4732
  Local<Map> options = Map::New(isolate);
884
548912
  for (const auto& item : _ppop_instance.options_) {
885
    Local<Value> value;
886
544180
    const auto& option_info = item.second;
887
1088360
    auto field = option_info.field;
888
544180
    PerProcessOptions* opts = per_process::cli_options.get();
889


544180
    switch (option_info.type) {
890
      case kNoOp:
891
      case kV8Option:
892
        // Special case for --abort-on-uncaught-exception which is also
893
        // respected by Node.js internals
894
80444
        if (item.first == "--abort-on-uncaught-exception") {
895
4732
          value = Boolean::New(
896
9464
            isolate, original_per_env->abort_on_uncaught_exception);
897
        } else {
898
75712
          value = Undefined(isolate);
899
        }
900
80444
        break;
901
      case kBoolean:
902
298116
        value = Boolean::New(isolate,
903
596232
                             *_ppop_instance.Lookup<bool>(field, opts));
904
298116
        break;
905
      case kInteger:
906
4732
        value = Number::New(isolate,
907
9464
                            *_ppop_instance.Lookup<int64_t>(field, opts));
908
4732
        break;
909
      case kUInteger:
910
14196
        value = Number::New(isolate,
911
28392
                            *_ppop_instance.Lookup<uint64_t>(field, opts));
912
14196
        break;
913
      case kString:
914
397488
        if (!ToV8Value(context,
915
264992
                       *_ppop_instance.Lookup<std::string>(field, opts))
916
132496
                 .ToLocal(&value)) {
917
          return;
918
        }
919
132496
        break;
920
      case kStringList:
921
28392
        if (!ToV8Value(context,
922
18928
                       *_ppop_instance.Lookup<StringVector>(field, opts))
923
9464
                 .ToLocal(&value)) {
924
          return;
925
        }
926
9464
        break;
927
      case kHostPort: {
928
        const HostPort& host_port =
929
4732
          *_ppop_instance.Lookup<HostPort>(field, opts);
930
4732
        Local<Object> obj = Object::New(isolate);
931
        Local<Value> host;
932

23660
        if (!ToV8Value(context, host_port.host()).ToLocal(&host) ||
933

23660
            obj->Set(context, env->host_string(), host).IsNothing() ||
934
9464
            obj->Set(context,
935
                     env->port_string(),
936
18928
                     Integer::New(isolate, host_port.port()))
937
4732
                .IsNothing()) {
938
          return;
939
        }
940
4732
        value = obj;
941
4732
        break;
942
      }
943
      default:
944
        UNREACHABLE();
945
    }
946
544180
    CHECK(!value.IsEmpty());
947
948
1088360
    Local<Value> name = ToV8Value(context, item.first).ToLocalChecked();
949
544180
    Local<Object> info = Object::New(isolate);
950
    Local<Value> help_text;
951

2720900
    if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) ||
952
2176720
        !info->Set(context, env->help_text_string(), help_text)
953
2176720
             .FromMaybe(false) ||
954
1632540
        !info->Set(context,
955
                   env->env_var_settings_string(),
956
                   Integer::New(isolate,
957
2176720
                                static_cast<int>(option_info.env_setting)))
958
2176720
             .FromMaybe(false) ||
959
1632540
        !info->Set(context,
960
                   env->type_string(),
961
2176720
                   Integer::New(isolate, static_cast<int>(option_info.type)))
962
2176720
             .FromMaybe(false) ||
963

3265080
        info->Set(context, env->value_string(), value).IsNothing() ||
964
1632540
        options->Set(context, name, info).IsEmpty()) {
965
      return;
966
    }
967
  }
968
969
  Local<Value> aliases;
970
9464
  if (!ToV8Value(context, _ppop_instance.aliases_).ToLocal(&aliases)) return;
971
972
4732
  Local<Object> ret = Object::New(isolate);
973

23660
  if (ret->Set(context, env->options_string(), options).IsNothing() ||
974
18928
      ret->Set(context, env->aliases_string(), aliases).IsNothing()) {
975
    return;
976
  }
977
978
9464
  args.GetReturnValue().Set(ret);
979
}
980
981
4732
void Initialize(Local<Object> target,
982
                Local<Value> unused,
983
                Local<Context> context,
984
                void* priv) {
985
4732
  Environment* env = Environment::GetCurrent(context);
986
4732
  Isolate* isolate = env->isolate();
987
4732
  env->SetMethodNoSideEffect(target, "getOptions", GetOptions);
988
989
4732
  Local<Object> env_settings = Object::New(isolate);
990
18928
  NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment);
991
18928
  NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvironment);
992
  target
993
9464
      ->Set(
994
14196
          context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings)
995
      .Check();
996
997
  target
998
9464
      ->Set(context,
999
            FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"),
1000
18928
            Boolean::New(isolate, env->should_not_register_esm_loader()))
1001
      .Check();
1002
1003
4732
  Local<Object> types = Object::New(isolate);
1004
18928
  NODE_DEFINE_CONSTANT(types, kNoOp);
1005
18928
  NODE_DEFINE_CONSTANT(types, kV8Option);
1006
18928
  NODE_DEFINE_CONSTANT(types, kBoolean);
1007
18928
  NODE_DEFINE_CONSTANT(types, kInteger);
1008
18928
  NODE_DEFINE_CONSTANT(types, kUInteger);
1009
18928
  NODE_DEFINE_CONSTANT(types, kString);
1010
18928
  NODE_DEFINE_CONSTANT(types, kHostPort);
1011
18928
  NODE_DEFINE_CONSTANT(types, kStringList);
1012
14196
  target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "types"), types)
1013
      .Check();
1014
4732
}
1015
1016
}  // namespace options_parser
1017
1018
4440
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options) {
1019
26640
  HandleEnvOptions(env_options, [](const char* name) {
1020
35520
    std::string text;
1021

35520
    return credentials::SafeGetenv(name, &text) ? text : "";
1022
4440
  });
1023
4440
}
1024
1025
4483
void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options,
1026
                      std::function<std::string(const char*)> opt_getter) {
1027
8966
  env_options->pending_deprecation =
1028
8966
      opt_getter("NODE_PENDING_DEPRECATION") == "1";
1029
1030
4483
  env_options->preserve_symlinks = opt_getter("NODE_PRESERVE_SYMLINKS") == "1";
1031
1032
8966
  env_options->preserve_symlinks_main =
1033
8966
      opt_getter("NODE_PRESERVE_SYMLINKS_MAIN") == "1";
1034
1035
4483
  if (env_options->redirect_warnings.empty())
1036
4483
    env_options->redirect_warnings = opt_getter("NODE_REDIRECT_WARNINGS");
1037
4483
}
1038
1039
4374
std::vector<std::string> ParseNodeOptionsEnvVar(
1040
    const std::string& node_options, std::vector<std::string>* errors) {
1041
4374
  std::vector<std::string> env_argv;
1042
1043
4374
  bool is_in_string = false;
1044
4374
  bool will_start_new_arg = true;
1045
7024
  for (std::string::size_type index = 0; index < node_options.size(); ++index) {
1046
2650
    char c = node_options.at(index);
1047
1048
    // Backslashes escape the following character
1049

2650
    if (c == '\\' && is_in_string) {
1050
      if (index + 1 == node_options.size()) {
1051
        errors->push_back("invalid value for NODE_OPTIONS "
1052
                          "(invalid escape)\n");
1053
        return env_argv;
1054
      } else {
1055
        c = node_options.at(++index);
1056
      }
1057

2650
    } else if (c == ' ' && !is_in_string) {
1058
32
      will_start_new_arg = true;
1059
32
      continue;
1060
2618
    } else if (c == '"') {
1061
4
      is_in_string = !is_in_string;
1062
4
      continue;
1063
    }
1064
1065
2614
    if (will_start_new_arg) {
1066
104
      env_argv.emplace_back(std::string(1, c));
1067
104
      will_start_new_arg = false;
1068
    } else {
1069
2510
      env_argv.back() += c;
1070
    }
1071
  }
1072
1073
4374
  if (is_in_string) {
1074
    errors->push_back("invalid value for NODE_OPTIONS "
1075
                      "(unterminated string)\n");
1076
  }
1077
4374
  return env_argv;
1078
}
1079
}  // namespace node
1080
1081

17763
NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize)