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: 520 550 94.5 %
Date: 2020-09-06 22:14:11 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
4473
Mutex cli_options_mutex;
28
4473
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
29
}  // namespace per_process
30
31
9014
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
9014
  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
18028
      SplitString(inspect_publish_uid_string, ',');
47
9014
  inspect_publish_uid.console = false;
48
9014
  inspect_publish_uid.http = false;
49
27040
  for (const std::string& destination : destinations) {
50
18026
    if (destination == "stderr") {
51
9013
      inspect_publish_uid.console = true;
52
9013
    } else if (destination == "http") {
53
9013
      inspect_publish_uid.http = true;
54
    } else {
55
      errors->push_back("--inspect-publish-uid destination can be "
56
                        "stderr or http");
57
    }
58
  }
59
9014
}
60
61
8819
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
62
#if HAVE_OPENSSL
63

8819
  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

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

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

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

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

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

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

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

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


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


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


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

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

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

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


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

24135
        if (!ToV8Value(context, host_port.host()).ToLocal(&host) ||
937

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

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

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

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

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

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

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

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