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: 521 551 94.6 %
Date: 2020-08-17 22:13:26 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
4460
Mutex cli_options_mutex;
28
4460
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
29
}  // namespace per_process
30
31
8876
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
8876
  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
17752
      SplitString(inspect_publish_uid_string, ',');
47
8876
  inspect_publish_uid.console = false;
48
8876
  inspect_publish_uid.http = false;
49
26626
  for (const std::string& destination : destinations) {
50
17750
    if (destination == "stderr") {
51
8875
      inspect_publish_uid.console = true;
52
8875
    } else if (destination == "http") {
53
8875
      inspect_publish_uid.http = true;
54
    } else {
55
      errors->push_back("--inspect-publish-uid destination can be "
56
                        "stderr or http");
57
    }
58
  }
59
8876
}
60
61
8793
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
62
#if HAVE_OPENSSL
63

8793
  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

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

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

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

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

20
    if (module_type != "commonjs" && module_type != "module") {
91
      errors->push_back("--input-type must be \"module\" or \"commonjs\"");
92
    }
93
  }
94
95
8876
  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
8870
  } 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

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

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

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

8876
  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
8876
  if (!cpu_prof) {
136
8865
    if (!cpu_prof_name.empty()) {
137
1
      errors->push_back("--cpu-prof-name must be used with --cpu-prof");
138
    }
139
8865
    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
8865
    if (cpu_prof_interval != kDefaultCpuProfInterval) {
145
1
      errors->push_back("--cpu-prof-interval must be used with --cpu-prof");
146
    }
147
  }
148
149


8876
  if (cpu_prof && cpu_prof_dir.empty() && !diagnostic_dir.empty()) {
150
1
      cpu_prof_dir = diagnostic_dir;
151
    }
152
153
8876
  if (!heap_prof) {
154
8865
    if (!heap_prof_name.empty()) {
155
1
      errors->push_back("--heap-prof-name must be used with --heap-prof");
156
    }
157
8865
    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
8865
    if (heap_prof_interval != kDefaultHeapProfInterval) {
163
1
      errors->push_back("--heap-prof-interval must be used with --heap-prof");
164
    }
165
  }
166
167


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


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

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

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

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


551000
    switch (option_info.type) {
895
      case kNoOp:
896
      case kV8Option:
897
        // Special case for --abort-on-uncaught-exception which is also
898
        // respected by Node.js internals
899
80750
        if (item.first == "--abort-on-uncaught-exception") {
900
4750
          value = Boolean::New(
901
9500
            isolate, original_per_env->abort_on_uncaught_exception);
902
        } else {
903
76000
          value = Undefined(isolate);
904
        }
905
80750
        break;
906
      case kBoolean:
907
299250
        value = Boolean::New(isolate,
908
598500
                             *_ppop_instance.Lookup<bool>(field, opts));
909
299250
        break;
910
      case kInteger:
911
4750
        value = Number::New(isolate,
912
9500
                            *_ppop_instance.Lookup<int64_t>(field, opts));
913
4750
        break;
914
      case kUInteger:
915
14250
        value = Number::New(isolate,
916
28500
                            *_ppop_instance.Lookup<uint64_t>(field, opts));
917
14250
        break;
918
      case kString:
919
399000
        if (!ToV8Value(context,
920
266000
                       *_ppop_instance.Lookup<std::string>(field, opts))
921
133000
                 .ToLocal(&value)) {
922
          return;
923
        }
924
133000
        break;
925
      case kStringList:
926
42750
        if (!ToV8Value(context,
927
28500
                       *_ppop_instance.Lookup<StringVector>(field, opts))
928
14250
                 .ToLocal(&value)) {
929
          return;
930
        }
931
14250
        break;
932
      case kHostPort: {
933
        const HostPort& host_port =
934
4750
          *_ppop_instance.Lookup<HostPort>(field, opts);
935
4750
        Local<Object> obj = Object::New(isolate);
936
        Local<Value> host;
937

23750
        if (!ToV8Value(context, host_port.host()).ToLocal(&host) ||
938

23750
            obj->Set(context, env->host_string(), host).IsNothing() ||
939
9500
            obj->Set(context,
940
                     env->port_string(),
941
19000
                     Integer::New(isolate, host_port.port()))
942
4750
                .IsNothing()) {
943
          return;
944
        }
945
4750
        value = obj;
946
4750
        break;
947
      }
948
      default:
949
        UNREACHABLE();
950
    }
951
551000
    CHECK(!value.IsEmpty());
952
953
1102000
    Local<Value> name = ToV8Value(context, item.first).ToLocalChecked();
954
551000
    Local<Object> info = Object::New(isolate);
955
    Local<Value> help_text;
956

2755000
    if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) ||
957
2204000
        !info->Set(context, env->help_text_string(), help_text)
958
2204000
             .FromMaybe(false) ||
959
1653000
        !info->Set(context,
960
                   env->env_var_settings_string(),
961
                   Integer::New(isolate,
962
2204000
                                static_cast<int>(option_info.env_setting)))
963
2204000
             .FromMaybe(false) ||
964
1653000
        !info->Set(context,
965
                   env->type_string(),
966
2204000
                   Integer::New(isolate, static_cast<int>(option_info.type)))
967
2204000
             .FromMaybe(false) ||
968

3306000
        info->Set(context, env->value_string(), value).IsNothing() ||
969
1653000
        options->Set(context, name, info).IsEmpty()) {
970
      return;
971
    }
972
  }
973
974
  Local<Value> aliases;
975
9500
  if (!ToV8Value(context, _ppop_instance.aliases_).ToLocal(&aliases)) return;
976
977
4750
  Local<Object> ret = Object::New(isolate);
978

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

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

2650
    if (c == '\\' && is_in_string) {
1055
      if (index + 1 == node_options.size()) {
1056
        errors->push_back("invalid value for NODE_OPTIONS "
1057
                          "(invalid escape)\n");
1058
        return env_argv;
1059
      } else {
1060
        c = node_options.at(++index);
1061
      }
1062

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

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