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-22 22:13:06 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
4465
Mutex cli_options_mutex;
28
4465
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
29
}  // namespace per_process
30
31
8998
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
8998
  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
17996
      SplitString(inspect_publish_uid_string, ',');
47
8998
  inspect_publish_uid.console = false;
48
8998
  inspect_publish_uid.http = false;
49
26992
  for (const std::string& destination : destinations) {
50
17994
    if (destination == "stderr") {
51
8997
      inspect_publish_uid.console = true;
52
8997
    } else if (destination == "http") {
53
8997
      inspect_publish_uid.http = true;
54
    } else {
55
      errors->push_back("--inspect-publish-uid destination can be "
56
                        "stderr or http");
57
    }
58
  }
59
8998
}
60
61
8803
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
62
#if HAVE_OPENSSL
63

8803
  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

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

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

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

8998
  if (has_policy_integrity_string && experimental_policy_integrity.empty()) {
86
1
    errors->push_back("--policy-integrity cannot be empty");
87
  }
88
89
8998
  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
8998
  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
8992
  } 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

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

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

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

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


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


8998
  if (heap_prof && heap_prof_dir.empty() && !diagnostic_dir.empty()) {
168
1
    heap_prof_dir = diagnostic_dir;
169
  }
170
171
8998
  debug_options_.CheckOptions(errors);
172
#endif  // HAVE_INSPECTOR
173
8998
}
174
175
namespace options_parser {
176
177
4465
class DebugOptionsParser : public OptionsParser<DebugOptions> {
178
 public:
179
  DebugOptionsParser();
180
};
181
182
4465
class EnvironmentOptionsParser : public OptionsParser<EnvironmentOptions> {
183
 public:
184
  EnvironmentOptionsParser();
185
4465
  explicit EnvironmentOptionsParser(const DebugOptionsParser& dop)
186
4465
    : EnvironmentOptionsParser() {
187
4465
    Insert(dop, &EnvironmentOptions::get_debug_options);
188
4465
  }
189
};
190
191
4465
class PerIsolateOptionsParser : public OptionsParser<PerIsolateOptions> {
192
 public:
193
  PerIsolateOptionsParser() = delete;
194
  explicit PerIsolateOptionsParser(const EnvironmentOptionsParser& eop);
195
};
196
197
4465
class PerProcessOptionsParser : public OptionsParser<PerProcessOptions> {
198
 public:
199
  PerProcessOptionsParser() = delete;
200
  explicit PerProcessOptionsParser(const PerIsolateOptionsParser& iop);
201
};
202
203
#if HAVE_INSPECTOR
204
4465
const DebugOptionsParser _dop_instance{};
205
4465
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
4465
const PerIsolateOptionsParser _piop_instance{_eop_instance};
221
4465
const PerProcessOptionsParser _ppop_instance{_piop_instance};
222
223
template <>
224
195
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
195
    args, exec_args, v8_args, options, required_env_settings, errors);
231
195
}
232
233
template <>
234
8803
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
8803
    args, exec_args, v8_args, options, required_env_settings, errors);
241
8803
}
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
4465
DebugOptionsParser::DebugOptionsParser() {
248
4465
  AddOption("--inspect-port",
249
            "set host:port for inspector",
250
            &DebugOptions::host_port,
251
4465
            kAllowedInEnvironment);
252
4465
  AddAlias("--debug-port", "--inspect-port");
253
254
4465
  AddOption("--inspect",
255
            "activate inspector on host:port (default: 127.0.0.1:9229)",
256
            &DebugOptions::inspector_enabled,
257
4465
            kAllowedInEnvironment);
258
4465
  AddAlias("--inspect=", { "--inspect-port", "--inspect" });
259
260
4465
  AddOption("--debug", "", &DebugOptions::deprecated_debug);
261
4465
  AddAlias("--debug=", "--debug");
262
4465
  AddOption("--debug-brk", "", &DebugOptions::deprecated_debug);
263
4465
  AddAlias("--debug-brk=", "--debug-brk");
264
265
4465
  AddOption("--inspect-brk",
266
            "activate inspector on host:port and break at start of user script",
267
            &DebugOptions::break_first_line,
268
4465
            kAllowedInEnvironment);
269
4465
  Implies("--inspect-brk", "--inspect");
270
4465
  AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" });
271
272
4465
  AddOption("--inspect-brk-node", "", &DebugOptions::break_node_first_line);
273
4465
  Implies("--inspect-brk-node", "--inspect");
274
4465
  AddAlias("--inspect-brk-node=", { "--inspect-port", "--inspect-brk-node" });
275
276
4465
  AddOption("--inspect-publish-uid",
277
            "comma separated list of destinations for inspector uid"
278
            "(default: stderr,http)",
279
            &DebugOptions::inspect_publish_uid_string,
280
4465
            kAllowedInEnvironment);
281
4465
}
282
283
4465
EnvironmentOptionsParser::EnvironmentOptionsParser() {
284
4465
  AddOption("--conditions",
285
            "additional user conditions for conditional exports and imports",
286
            &EnvironmentOptions::conditions,
287
4465
            kAllowedInEnvironment);
288
4465
  AddAlias("-u", "--conditions");
289
4465
  AddOption("--diagnostic-dir",
290
            "set dir for all output files"
291
            " (default: current working directory)",
292
            &EnvironmentOptions::diagnostic_dir,
293
4465
            kAllowedInEnvironment);
294
4465
  AddOption("--enable-source-maps",
295
            "experimental Source Map V3 support",
296
            &EnvironmentOptions::enable_source_maps,
297
4465
            kAllowedInEnvironment);
298
4465
  AddOption("--experimental-abortcontroller", "",
299
4465
            NoOp{}, kAllowedInEnvironment);
300
4465
  AddOption("--experimental-json-modules",
301
            "experimental JSON interop support for the ES Module loader",
302
            &EnvironmentOptions::experimental_json_modules,
303
4465
            kAllowedInEnvironment);
304
4465
  AddOption("--experimental-loader",
305
            "use the specified module as a custom loader",
306
            &EnvironmentOptions::userland_loader,
307
4465
            kAllowedInEnvironment);
308
4465
  AddAlias("--loader", "--experimental-loader");
309
4465
  AddOption("--experimental-modules",
310
            "",
311
            &EnvironmentOptions::experimental_modules,
312
4465
            kAllowedInEnvironment);
313
4465
  AddOption("--experimental-wasm-modules",
314
            "experimental ES Module support for webassembly modules",
315
            &EnvironmentOptions::experimental_wasm_modules,
316
4465
            kAllowedInEnvironment);
317
4465
  AddOption("--experimental-import-meta-resolve",
318
            "experimental ES Module import.meta.resolve() support",
319
            &EnvironmentOptions::experimental_import_meta_resolve,
320
4465
            kAllowedInEnvironment);
321
4465
  AddOption("--experimental-policy",
322
            "use the specified file as a "
323
            "security policy",
324
            &EnvironmentOptions::experimental_policy,
325
4465
            kAllowedInEnvironment);
326
4465
  AddOption("[has_policy_integrity_string]",
327
            "",
328
4465
            &EnvironmentOptions::has_policy_integrity_string);
329
4465
  AddOption("--policy-integrity",
330
            "ensure the security policy contents match "
331
            "the specified integrity",
332
            &EnvironmentOptions::experimental_policy_integrity,
333
4465
            kAllowedInEnvironment);
334
4465
  Implies("--policy-integrity", "[has_policy_integrity_string]");
335
4465
  AddOption("--experimental-repl-await",
336
            "experimental await keyword support in REPL",
337
            &EnvironmentOptions::experimental_repl_await,
338
4465
            kAllowedInEnvironment);
339
4465
  AddOption("--experimental-vm-modules",
340
            "experimental ES Module support in vm module",
341
            &EnvironmentOptions::experimental_vm_modules,
342
4465
            kAllowedInEnvironment);
343
4465
  AddOption("--experimental-worker", "", NoOp{}, kAllowedInEnvironment);
344
4465
  AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvironment);
345
4465
  AddOption("--experimental-wasi-unstable-preview1",
346
            "experimental WASI support",
347
            &EnvironmentOptions::experimental_wasi,
348
4465
            kAllowedInEnvironment);
349
4465
  AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
350
4465
  AddOption("--frozen-intrinsics",
351
            "experimental frozen intrinsics support",
352
            &EnvironmentOptions::frozen_intrinsics,
353
4465
            kAllowedInEnvironment);
354
4465
  AddOption("--heapsnapshot-signal",
355
            "Generate heap snapshot on specified signal",
356
            &EnvironmentOptions::heap_snapshot_signal,
357
4465
            kAllowedInEnvironment);
358
4465
  AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment);
359
4465
  AddOption("--insecure-http-parser",
360
            "use an insecure HTTP parser that accepts invalid HTTP headers",
361
            &EnvironmentOptions::insecure_http_parser,
362
4465
            kAllowedInEnvironment);
363
4465
  AddOption("--input-type",
364
            "set module type for string input",
365
            &EnvironmentOptions::module_type,
366
4465
            kAllowedInEnvironment);
367
4465
  AddOption("--experimental-specifier-resolution",
368
            "Select extension resolution algorithm for es modules; "
369
            "either 'explicit' (default) or 'node'",
370
            &EnvironmentOptions::experimental_specifier_resolution,
371
4465
            kAllowedInEnvironment);
372
4465
  AddOption("--es-module-specifier-resolution",
373
            "",
374
            &EnvironmentOptions::es_module_specifier_resolution,
375
4465
            kAllowedInEnvironment);
376
4465
  AddOption("--no-deprecation",
377
            "silence deprecation warnings",
378
            &EnvironmentOptions::no_deprecation,
379
4465
            kAllowedInEnvironment);
380
4465
  AddOption("--no-force-async-hooks-checks",
381
            "disable checks for async_hooks",
382
            &EnvironmentOptions::no_force_async_hooks_checks,
383
4465
            kAllowedInEnvironment);
384
4465
  AddOption("--no-warnings",
385
            "silence all process warnings",
386
            &EnvironmentOptions::no_warnings,
387
4465
            kAllowedInEnvironment);
388
4465
  AddOption("--force-context-aware",
389
            "disable loading non-context-aware addons",
390
            &EnvironmentOptions::force_context_aware,
391
4465
            kAllowedInEnvironment);
392
4465
  AddOption("--pending-deprecation",
393
            "emit pending deprecation warnings",
394
            &EnvironmentOptions::pending_deprecation,
395
4465
            kAllowedInEnvironment);
396
4465
  AddOption("--preserve-symlinks",
397
            "preserve symbolic links when resolving",
398
            &EnvironmentOptions::preserve_symlinks,
399
4465
            kAllowedInEnvironment);
400
4465
  AddOption("--preserve-symlinks-main",
401
            "preserve symbolic links when resolving the main module",
402
            &EnvironmentOptions::preserve_symlinks_main,
403
4465
            kAllowedInEnvironment);
404
4465
  AddOption("--prof-process",
405
            "process V8 profiler output generated using --prof",
406
4465
            &EnvironmentOptions::prof_process);
407
  // Options after --prof-process are passed through to the prof processor.
408
4465
  AddAlias("--prof-process", { "--prof-process", "--" });
409
#if HAVE_INSPECTOR
410
4465
  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
4465
            &EnvironmentOptions::cpu_prof);
415
4465
  AddOption("--cpu-prof-name",
416
            "specified file name of the V8 CPU profile generated with "
417
            "--cpu-prof",
418
4465
            &EnvironmentOptions::cpu_prof_name);
419
4465
  AddOption("--cpu-prof-interval",
420
            "specified sampling interval in microseconds for the V8 CPU "
421
            "profile generated with --cpu-prof. (default: 1000)",
422
4465
            &EnvironmentOptions::cpu_prof_interval);
423
4465
  AddOption("--cpu-prof-dir",
424
            "Directory where the V8 profiles generated by --cpu-prof will be "
425
            "placed. Does not affect --prof.",
426
4465
            &EnvironmentOptions::cpu_prof_dir);
427
4465
  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
4465
      &EnvironmentOptions::heap_prof);
433
4465
  AddOption("--heap-prof-name",
434
            "specified file name of the V8 heap profile generated with "
435
            "--heap-prof",
436
4465
            &EnvironmentOptions::heap_prof_name);
437
4465
  AddOption("--heap-prof-dir",
438
            "Directory where the V8 heap profiles generated by --heap-prof "
439
            "will be placed.",
440
4465
            &EnvironmentOptions::heap_prof_dir);
441
4465
  AddOption("--heap-prof-interval",
442
            "specified sampling interval in bytes for the V8 heap "
443
            "profile generated with --heap-prof. (default: 512 * 1024)",
444
4465
            &EnvironmentOptions::heap_prof_interval);
445
#endif  // HAVE_INSPECTOR
446
4465
  AddOption("--max-http-header-size",
447
            "set the maximum size of HTTP headers (default: 16384 (16KB))",
448
            &EnvironmentOptions::max_http_header_size,
449
4465
            kAllowedInEnvironment);
450
4465
  AddOption("--redirect-warnings",
451
            "write warnings to file instead of stderr",
452
            &EnvironmentOptions::redirect_warnings,
453
4465
            kAllowedInEnvironment);
454
4465
  AddOption("--test-udp-no-try-send", "",  // For testing only.
455
4465
            &EnvironmentOptions::test_udp_no_try_send);
456
4465
  AddOption("--throw-deprecation",
457
            "throw an exception on deprecations",
458
            &EnvironmentOptions::throw_deprecation,
459
4465
            kAllowedInEnvironment);
460
4465
  AddOption("--trace-atomics-wait",
461
            "trace Atomics.wait() operations",
462
            &EnvironmentOptions::trace_atomics_wait,
463
4465
            kAllowedInEnvironment);
464
4465
  AddOption("--trace-deprecation",
465
            "show stack traces on deprecations",
466
            &EnvironmentOptions::trace_deprecation,
467
4465
            kAllowedInEnvironment);
468
4465
  AddOption("--trace-exit",
469
            "show stack trace when an environment exits",
470
            &EnvironmentOptions::trace_exit,
471
4465
            kAllowedInEnvironment);
472
4465
  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
4465
            kAllowedInEnvironment);
477
4465
  AddOption("--trace-tls",
478
            "prints TLS packet trace information to stderr",
479
            &EnvironmentOptions::trace_tls,
480
4465
            kAllowedInEnvironment);
481
4465
  AddOption("--trace-uncaught",
482
            "show stack traces for the `throw` behind uncaught exceptions",
483
            &EnvironmentOptions::trace_uncaught,
484
4465
            kAllowedInEnvironment);
485
4465
  AddOption("--trace-warnings",
486
            "show stack traces on process warnings",
487
            &EnvironmentOptions::trace_warnings,
488
4465
            kAllowedInEnvironment);
489
4465
  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
4465
            kAllowedInEnvironment);
494
495
4465
  AddOption("--check",
496
            "syntax check script without executing",
497
4465
            &EnvironmentOptions::syntax_check_only);
498
4465
  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
4465
  AddOption("[has_eval_string]", "", &EnvironmentOptions::has_eval_string);
506
4465
  AddOption("--eval", "evaluate script", &EnvironmentOptions::eval_string);
507
4465
  Implies("--eval", "[has_eval_string]");
508
4465
  AddOption("--print",
509
            "evaluate script and print result",
510
4465
            &EnvironmentOptions::print_eval);
511
4465
  AddAlias("-e", "--eval");
512
4465
  AddAlias("--print <arg>", "-pe");
513
4465
  AddAlias("-pe", { "--print", "--eval" });
514
4465
  AddAlias("-p", "--print");
515
4465
  AddOption("--require",
516
            "module to preload (option can be repeated)",
517
            &EnvironmentOptions::preload_modules,
518
4465
            kAllowedInEnvironment);
519
4465
  AddAlias("-r", "--require");
520
4465
  AddOption("--interactive",
521
            "always enter the REPL even if stdin does not appear "
522
            "to be a terminal",
523
4465
            &EnvironmentOptions::force_repl);
524
4465
  AddAlias("-i", "--interactive");
525
526
4465
  AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment);
527
528
4465
  AddOption("--tls-keylog",
529
            "log TLS decryption keys to named file for traffic analysis",
530
4465
            &EnvironmentOptions::tls_keylog, kAllowedInEnvironment);
531
532
4465
  AddOption("--tls-min-v1.0",
533
            "set default TLS minimum to TLSv1.0 (default: TLSv1.2)",
534
            &EnvironmentOptions::tls_min_v1_0,
535
4465
            kAllowedInEnvironment);
536
4465
  AddOption("--tls-min-v1.1",
537
            "set default TLS minimum to TLSv1.1 (default: TLSv1.2)",
538
            &EnvironmentOptions::tls_min_v1_1,
539
4465
            kAllowedInEnvironment);
540
4465
  AddOption("--tls-min-v1.2",
541
            "set default TLS minimum to TLSv1.2 (default: TLSv1.2)",
542
            &EnvironmentOptions::tls_min_v1_2,
543
4465
            kAllowedInEnvironment);
544
4465
  AddOption("--tls-min-v1.3",
545
            "set default TLS minimum to TLSv1.3 (default: TLSv1.2)",
546
            &EnvironmentOptions::tls_min_v1_3,
547
4465
            kAllowedInEnvironment);
548
4465
  AddOption("--tls-max-v1.2",
549
            "set default TLS maximum to TLSv1.2 (default: TLSv1.3)",
550
            &EnvironmentOptions::tls_max_v1_2,
551
4465
            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
4465
  AddOption("--tls-max-v1.3",
557
            "set default TLS maximum to TLSv1.3 (default: TLSv1.3)",
558
            &EnvironmentOptions::tls_max_v1_3,
559
4465
            kAllowedInEnvironment);
560
4465
}
561
562
4465
PerIsolateOptionsParser::PerIsolateOptionsParser(
563
4465
  const EnvironmentOptionsParser& eop) {
564
4465
  AddOption("--track-heap-objects",
565
            "track heap object allocations for heap snapshots",
566
            &PerIsolateOptions::track_heap_objects,
567
4465
            kAllowedInEnvironment);
568
4465
  AddOption("--no-node-snapshot",
569
            "",  // It's a debug-only option.
570
            &PerIsolateOptions::no_node_snapshot,
571
4465
            kAllowedInEnvironment);
572
573
  // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
574
4465
  AddOption("--abort-on-uncaught-exception",
575
            "aborting instead of exiting causes a core file to be generated "
576
            "for analysis",
577
4465
            V8Option{},
578
4465
            kAllowedInEnvironment);
579
4465
  AddOption("--interpreted-frames-native-stack",
580
            "help system profilers to translate JavaScript interpreted frames",
581
4465
            V8Option{}, kAllowedInEnvironment);
582
4465
  AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvironment);
583
4465
  AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvironment);
584
4465
  AddOption("--perf-basic-prof-only-functions",
585
            "",
586
4465
            V8Option{},
587
4465
            kAllowedInEnvironment);
588
4465
  AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvironment);
589
4465
  AddOption("--perf-prof-unwinding-info",
590
            "",
591
4465
            V8Option{},
592
4465
            kAllowedInEnvironment);
593
4465
  AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment);
594
4465
  AddOption("--disallow-code-generation-from-strings",
595
            "disallow eval and friends",
596
4465
            V8Option{},
597
4465
            kAllowedInEnvironment);
598
4465
  AddOption("--huge-max-old-generation-size",
599
             "increase default maximum heap size on machines with 16GB memory "
600
             "or more",
601
4465
             V8Option{},
602
4465
             kAllowedInEnvironment);
603
4465
  AddOption("--jitless",
604
             "disable runtime allocation of executable memory",
605
4465
             V8Option{},
606
4465
             kAllowedInEnvironment);
607
4465
  AddOption("--report-uncaught-exception",
608
            "generate diagnostic report on uncaught exceptions",
609
            &PerIsolateOptions::report_uncaught_exception,
610
4465
            kAllowedInEnvironment);
611
4465
  AddOption("--report-on-signal",
612
            "generate diagnostic report upon receiving signals",
613
            &PerIsolateOptions::report_on_signal,
614
4465
            kAllowedInEnvironment);
615
4465
  AddOption("--report-signal",
616
            "causes diagnostic report to be produced on provided signal,"
617
            " unsupported in Windows. (default: SIGUSR2)",
618
            &PerIsolateOptions::report_signal,
619
4465
            kAllowedInEnvironment);
620
4465
  Implies("--report-signal", "--report-on-signal");
621
622
4465
  AddOption("--experimental-top-level-await",
623
            "",
624
            &PerIsolateOptions::experimental_top_level_await,
625
4465
            kAllowedInEnvironment);
626
4465
  AddOption("--harmony-top-level-await", "", V8Option{});
627
4465
  Implies("--experimental-top-level-await", "--harmony-top-level-await");
628
4465
  Implies("--harmony-top-level-await", "--experimental-top-level-await");
629
4465
  ImpliesNot("--no-harmony-top-level-await", "--experimental-top-level-await");
630
631
4465
  Insert(eop, &PerIsolateOptions::get_per_env_options);
632
4465
}
633
634
4465
PerProcessOptionsParser::PerProcessOptionsParser(
635
4465
  const PerIsolateOptionsParser& iop) {
636
4465
  AddOption("--title",
637
            "the process title to use on startup",
638
            &PerProcessOptions::title,
639
4465
            kAllowedInEnvironment);
640
4465
  AddOption("--trace-event-categories",
641
            "comma separated list of trace event categories to record",
642
            &PerProcessOptions::trace_event_categories,
643
4465
            kAllowedInEnvironment);
644
4465
  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
4465
            kAllowedInEnvironment);
649
17860
  AddAlias("--trace-events-enabled", {
650
13395
    "--trace-event-categories", "v8,node,node.async_hooks" });
651
4465
  AddOption("--v8-pool-size",
652
            "set V8's thread pool size",
653
            &PerProcessOptions::v8_thread_pool_size,
654
4465
            kAllowedInEnvironment);
655
4465
  AddOption("--zero-fill-buffers",
656
            "automatically zero-fill all newly allocated Buffer and "
657
            "SlowBuffer instances",
658
            &PerProcessOptions::zero_fill_all_buffers,
659
4465
            kAllowedInEnvironment);
660
4465
  AddOption("--debug-arraybuffer-allocations",
661
            "", /* undocumented, only for debugging */
662
            &PerProcessOptions::debug_arraybuffer_allocations,
663
4465
            kAllowedInEnvironment);
664
4465
  AddOption("--disable-proto",
665
            "disable Object.prototype.__proto__",
666
            &PerProcessOptions::disable_proto,
667
4465
            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
4465
  AddOption("--security-revert", "", &PerProcessOptions::security_reverts);
673
4465
  AddAlias("--security-reverts", "--security-revert");
674
4465
  AddOption("--completion-bash",
675
            "print source-able bash completion script",
676
4465
            &PerProcessOptions::print_bash_completion);
677
4465
  AddOption("--help",
678
            "print node command line options",
679
4465
            &PerProcessOptions::print_help);
680
4465
  AddAlias("-h", "--help");
681
4465
  AddOption(
682
4465
      "--version", "print Node.js version", &PerProcessOptions::print_version);
683
4465
  AddAlias("-v", "--version");
684
4465
  AddOption("--v8-options",
685
            "print V8 command line options",
686
4465
            &PerProcessOptions::print_v8_help);
687
4465
  AddOption("--report-compact",
688
            "output compact single-line JSON",
689
            &PerProcessOptions::report_compact,
690
4465
            kAllowedInEnvironment);
691
4465
  AddOption("--report-dir",
692
            "define custom report pathname."
693
            " (default: current working directory)",
694
            &PerProcessOptions::report_directory,
695
4465
            kAllowedInEnvironment);
696
4465
  AddAlias("--report-directory", "--report-dir");
697
4465
  AddOption("--report-filename",
698
            "define custom report file name."
699
            " (default: YYYYMMDD.HHMMSS.PID.SEQUENCE#.txt)",
700
            &PerProcessOptions::report_filename,
701
4465
            kAllowedInEnvironment);
702
4465
  AddOption("--report-on-fatalerror",
703
              "generate diagnostic report on fatal (internal) errors",
704
              &PerProcessOptions::report_on_fatalerror,
705
4465
              kAllowedInEnvironment);
706
707
#ifdef NODE_HAVE_I18N_SUPPORT
708
4465
  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
4465
            kAllowedInEnvironment);
716
#endif
717
718
#if HAVE_OPENSSL
719
4465
  AddOption("--openssl-config",
720
            "load OpenSSL configuration from the specified file "
721
            "(overrides OPENSSL_CONF)",
722
            &PerProcessOptions::openssl_config,
723
4465
            kAllowedInEnvironment);
724
4465
  AddOption("--tls-cipher-list",
725
            "use an alternative default TLS cipher list",
726
            &PerProcessOptions::tls_cipher_list,
727
4465
            kAllowedInEnvironment);
728
4465
  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
4465
            kAllowedInEnvironment);
736
4465
  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
4465
            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
4465
  AddOption("[ssl_openssl_cert_store]",
748
            "",
749
4465
            &PerProcessOptions::ssl_openssl_cert_store);
750
4465
  Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
751
4465
  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
4465
  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
4465
            kAllowedInEnvironment);
770
771
4465
  AddOption("--trace-sigint",
772
            "enable printing JavaScript stacktrace on SIGINT",
773
            &PerProcessOptions::trace_sigint,
774
4465
            kAllowedInEnvironment);
775
776
4465
  Insert(iop, &PerProcessOptions::get_per_isolate_options);
777
4465
}
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
4819
void GetOptions(const FunctionCallbackInfo<Value>& args) {
864
9638
  Mutex::ScopedLock lock(per_process::cli_options_mutex);
865
4819
  Environment* env = Environment::GetCurrent(args);
866
4819
  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
4819
  env->set_has_serialized_options(true);
872
873
4819
  Isolate* isolate = env->isolate();
874
4819
  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
9638
  auto original_per_isolate = per_process::cli_options->per_isolate;
880
4819
  per_process::cli_options->per_isolate = env->isolate_data()->options();
881
9638
  auto original_per_env = per_process::cli_options->per_isolate->per_env;
882
4819
  per_process::cli_options->per_isolate->per_env = env->options();
883
4819
  auto on_scope_leave = OnScopeLeave([&]() {
884
4819
    per_process::cli_options->per_isolate->per_env = original_per_env;
885
4819
    per_process::cli_options->per_isolate = original_per_isolate;
886
14457
  });
887
888
4819
  Local<Map> options = Map::New(isolate);
889
563823
  for (const auto& item : _ppop_instance.options_) {
890
    Local<Value> value;
891
559004
    const auto& option_info = item.second;
892
1118008
    auto field = option_info.field;
893
559004
    PerProcessOptions* opts = per_process::cli_options.get();
894


559004
    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
81923
        if (item.first == "--abort-on-uncaught-exception") {
900
4819
          value = Boolean::New(
901
9638
            isolate, original_per_env->abort_on_uncaught_exception);
902
        } else {
903
77104
          value = Undefined(isolate);
904
        }
905
81923
        break;
906
      case kBoolean:
907
303597
        value = Boolean::New(isolate,
908
607194
                             *_ppop_instance.Lookup<bool>(field, opts));
909
303597
        break;
910
      case kInteger:
911
4819
        value = Number::New(isolate,
912
9638
                            *_ppop_instance.Lookup<int64_t>(field, opts));
913
4819
        break;
914
      case kUInteger:
915
14457
        value = Number::New(isolate,
916
28914
                            *_ppop_instance.Lookup<uint64_t>(field, opts));
917
14457
        break;
918
      case kString:
919
404796
        if (!ToV8Value(context,
920
269864
                       *_ppop_instance.Lookup<std::string>(field, opts))
921
134932
                 .ToLocal(&value)) {
922
          return;
923
        }
924
134932
        break;
925
      case kStringList:
926
43371
        if (!ToV8Value(context,
927
28914
                       *_ppop_instance.Lookup<StringVector>(field, opts))
928
14457
                 .ToLocal(&value)) {
929
          return;
930
        }
931
14457
        break;
932
      case kHostPort: {
933
        const HostPort& host_port =
934
4819
          *_ppop_instance.Lookup<HostPort>(field, opts);
935
4819
        Local<Object> obj = Object::New(isolate);
936
        Local<Value> host;
937

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

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

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

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

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

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

2674
    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

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

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