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: 242 260 93.1 %
Date: 2019-02-13 22:28:58 Branches: 133 206 64.6 %

Line Branch Exec Source
1
#include <errno.h>
2
#include "env-inl.h"
3
#include "node_binding.h"
4
#include "node_options-inl.h"
5
6
using v8::Boolean;
7
using v8::Context;
8
using v8::FunctionCallbackInfo;
9
using v8::Integer;
10
using v8::Isolate;
11
using v8::Local;
12
using v8::Map;
13
using v8::Number;
14
using v8::Object;
15
using v8::String;
16
using v8::Undefined;
17
using v8::Value;
18
19
namespace node {
20
21
namespace per_process {
22
4314
Mutex cli_options_mutex;
23
4314
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
24
}  // namespace per_process
25
26
8474
void DebugOptions::CheckOptions(std::vector<std::string>* errors) {
27
#if !NODE_USE_V8_PLATFORM
28
  if (inspector_enabled) {
29
    errors->push_back("Inspector is not available when Node is compiled "
30
                      "--without-v8-platform");
31
  }
32
#endif
33
34

8474
  if (deprecated_debug && !inspector_enabled) {
35
    errors->push_back("[DEP0062]: `node --debug` and `node --debug-brk` "
36
                      "are invalid. Please use `node --inspect` or "
37
2
                      "`node --inspect-brk` instead.");
38
  }
39
40

8474
  if (deprecated_debug && inspector_enabled && break_first_line) {
41
    errors->push_back("[DEP0062]: `node --inspect --debug-brk` is deprecated. "
42
3
                      "Please use `node --inspect-brk` instead.");
43
  }
44
8474
}
45
46
8468
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
47
#if HAVE_OPENSSL
48

8468
  if (use_openssl_ca && use_bundled_ca) {
49
    errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
50
1
                      "used, not both");
51
  }
52
#endif
53
8468
  per_isolate->CheckOptions(errors);
54
8468
}
55
56
8474
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
57
8474
  per_env->CheckOptions(errors);
58
#ifdef NODE_REPORT
59
8474
  if (per_env->experimental_report)
60
8480
    return;
61
62
8468
  if (!report_directory.empty()) {
63
    errors->push_back("--diagnostic-report-directory option is valid only when "
64
                      "--experimental-report is set");
65
  }
66
67
8468
  if (!report_filename.empty()) {
68
    errors->push_back("--diagnostic-report-filename option is valid only when "
69
                      "--experimental-report is set");
70
  }
71
72
8468
  if (!report_signal.empty()) {
73
    errors->push_back("--diagnostic-report-signal option is valid only when "
74
                      "--experimental-report is set");
75
  }
76
77
8468
  if (report_on_fatalerror) {
78
    errors->push_back(
79
        "--diagnostic-report-on-fatalerror option is valid only when "
80
        "--experimental-report is set");
81
  }
82
83
8468
  if (report_on_signal) {
84
    errors->push_back("--diagnostic-report-on-signal option is valid only when "
85
                      "--experimental-report is set");
86
  }
87
88
8468
  if (report_uncaught_exception) {
89
    errors->push_back(
90
        "--diagnostic-report-uncaught-exception option is valid only when "
91
        "--experimental-report is set");
92
  }
93
94
8468
  if (report_verbose) {
95
    errors->push_back("--diagnostic-report-verbose option is valid only when "
96
                      "--experimental-report is set");
97
  }
98
#endif  // NODE_REPORT
99
}
100
101
8474
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
102

8474
  if (!userland_loader.empty() && !experimental_modules) {
103
    errors->push_back("--loader requires --experimental-modules be enabled");
104
  }
105
106

8474
  if (syntax_check_only && has_eval_string) {
107
4
    errors->push_back("either --check or --eval can be used, not both");
108
  }
109
110

8474
  if (http_parser != "legacy" && http_parser != "llhttp") {
111
    errors->push_back("invalid value for --http-parser");
112
  }
113
114
#if HAVE_INSPECTOR
115
8474
  debug_options_.CheckOptions(errors);
116
#endif  // HAVE_INSPECTOR
117
8474
}
118
119
namespace options_parser {
120
121
// Explicitly access the singelton instances in their dependancy order.
122
// This was moved here to workaround a compiler bug.
123
// Refs: https://github.com/nodejs/node/issues/25593
124
125
#if HAVE_INSPECTOR
126
4314
const DebugOptionsParser DebugOptionsParser::instance;
127
#endif  // HAVE_INSPECTOR
128
129
4314
const EnvironmentOptionsParser EnvironmentOptionsParser::instance;
130
131
4314
const PerIsolateOptionsParser PerIsolateOptionsParser::instance;
132
133
4314
const PerProcessOptionsParser PerProcessOptionsParser::instance;
134
135
// XXX: If you add an option here, please also add it to doc/node.1 and
136
// doc/api/cli.md
137
// TODO(addaleax): Make that unnecessary.
138
139
4314
DebugOptionsParser::DebugOptionsParser() {
140
  AddOption("--inspect-port",
141
            "set host:port for inspector",
142
            &DebugOptions::host_port,
143
4314
            kAllowedInEnvironment);
144
4314
  AddAlias("--debug-port", "--inspect-port");
145
146
  AddOption("--inspect",
147
            "activate inspector on host:port (default: 127.0.0.1:9229)",
148
            &DebugOptions::inspector_enabled,
149
4314
            kAllowedInEnvironment);
150
4314
  AddAlias("--inspect=", { "--inspect-port", "--inspect" });
151
152
4314
  AddOption("--debug", "", &DebugOptions::deprecated_debug);
153
4314
  AddAlias("--debug=", { "--inspect-port", "--debug" });
154
155
  AddOption("--inspect-brk",
156
            "activate inspector on host:port and break at start of user script",
157
            &DebugOptions::break_first_line,
158
4314
            kAllowedInEnvironment);
159
4314
  Implies("--inspect-brk", "--inspect");
160
4314
  AddAlias("--inspect-brk=", { "--inspect-port", "--inspect-brk" });
161
162
4314
  AddOption("--inspect-brk-node", "", &DebugOptions::break_node_first_line);
163
4314
  Implies("--inspect-brk-node", "--inspect");
164
4314
  AddAlias("--inspect-brk-node=", { "--inspect-port", "--inspect-brk-node" });
165
166
4314
  AddOption("--debug-brk", "", &DebugOptions::break_first_line);
167
4314
  Implies("--debug-brk", "--debug");
168
4314
  AddAlias("--debug-brk=", { "--inspect-port", "--debug-brk" });
169
4314
}
170
171
4314
EnvironmentOptionsParser::EnvironmentOptionsParser() {
172
  AddOption("--experimental-modules",
173
            "experimental ES Module support and caching modules",
174
            &EnvironmentOptions::experimental_modules,
175
4314
            kAllowedInEnvironment);
176
  AddOption("--experimental-policy",
177
            "use the specified file as a "
178
            "security policy",
179
            &EnvironmentOptions::experimental_policy,
180
4314
            kAllowedInEnvironment);
181
  AddOption("--experimental-repl-await",
182
            "experimental await keyword support in REPL",
183
            &EnvironmentOptions::experimental_repl_await,
184
4314
            kAllowedInEnvironment);
185
  AddOption("--experimental-vm-modules",
186
            "experimental ES Module support in vm module",
187
            &EnvironmentOptions::experimental_vm_modules,
188
4314
            kAllowedInEnvironment);
189
4314
  AddOption("--experimental-worker", "", NoOp{}, kAllowedInEnvironment);
190
#ifdef NODE_REPORT
191
  AddOption("--experimental-report",
192
            "enable report generation",
193
            &EnvironmentOptions::experimental_report,
194
4314
            kAllowedInEnvironment);
195
#endif  // NODE_REPORT
196
4314
  AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
197
  AddOption("--http-parser",
198
            "Select which HTTP parser to use; either 'legacy' or 'llhttp' "
199
            "(default: llhttp).",
200
            &EnvironmentOptions::http_parser,
201
4314
            kAllowedInEnvironment);
202
  AddOption("--loader",
203
            "(with --experimental-modules) use the specified file as a "
204
            "custom loader",
205
            &EnvironmentOptions::userland_loader,
206
4314
            kAllowedInEnvironment);
207
  AddOption("--no-deprecation",
208
            "silence deprecation warnings",
209
            &EnvironmentOptions::no_deprecation,
210
4314
            kAllowedInEnvironment);
211
  AddOption("--no-force-async-hooks-checks",
212
            "disable checks for async_hooks",
213
            &EnvironmentOptions::no_force_async_hooks_checks,
214
4314
            kAllowedInEnvironment);
215
  AddOption("--no-warnings",
216
            "silence all process warnings",
217
            &EnvironmentOptions::no_warnings,
218
4314
            kAllowedInEnvironment);
219
  AddOption("--pending-deprecation",
220
            "emit pending deprecation warnings",
221
            &EnvironmentOptions::pending_deprecation,
222
4314
            kAllowedInEnvironment);
223
  AddOption("--preserve-symlinks",
224
            "preserve symbolic links when resolving",
225
4314
            &EnvironmentOptions::preserve_symlinks);
226
  AddOption("--preserve-symlinks-main",
227
            "preserve symbolic links when resolving the main module",
228
4314
            &EnvironmentOptions::preserve_symlinks_main);
229
  AddOption("--prof-process",
230
            "process V8 profiler output generated using --prof",
231
4314
            &EnvironmentOptions::prof_process);
232
  // Options after --prof-process are passed through to the prof processor.
233
4314
  AddAlias("--prof-process", { "--prof-process", "--" });
234
  AddOption("--redirect-warnings",
235
            "write warnings to file instead of stderr",
236
            &EnvironmentOptions::redirect_warnings,
237
4314
            kAllowedInEnvironment);
238
  AddOption("--throw-deprecation",
239
            "throw an exception on deprecations",
240
            &EnvironmentOptions::throw_deprecation,
241
4314
            kAllowedInEnvironment);
242
  AddOption("--trace-deprecation",
243
            "show stack traces on deprecations",
244
            &EnvironmentOptions::trace_deprecation,
245
4314
            kAllowedInEnvironment);
246
  AddOption("--trace-sync-io",
247
            "show stack trace when use of sync IO is detected after the "
248
            "first tick",
249
            &EnvironmentOptions::trace_sync_io,
250
4314
            kAllowedInEnvironment);
251
  AddOption("--trace-warnings",
252
            "show stack traces on process warnings",
253
            &EnvironmentOptions::trace_warnings,
254
4314
            kAllowedInEnvironment);
255
256
  AddOption("--check",
257
            "syntax check script without executing",
258
4314
            &EnvironmentOptions::syntax_check_only);
259
4314
  AddAlias("-c", "--check");
260
  // This option is only so that we can tell --eval with an empty string from
261
  // no eval at all. Having it not start with a dash makes it inaccessible
262
  // from the parser itself, but available for using Implies().
263
  // TODO(addaleax): When moving --help over to something generated from the
264
  // programmatic descriptions, this will need some special care.
265
  // (See also [ssl_openssl_cert_store] below.)
266
4314
  AddOption("[has_eval_string]", "", &EnvironmentOptions::has_eval_string);
267
4314
  AddOption("--eval", "evaluate script", &EnvironmentOptions::eval_string);
268
4314
  Implies("--eval", "[has_eval_string]");
269
  AddOption("--print",
270
            "evaluate script and print result",
271
4314
            &EnvironmentOptions::print_eval);
272
4314
  AddAlias("-e", "--eval");
273
4314
  AddAlias("--print <arg>", "-pe");
274
4314
  AddAlias("-pe", { "--print", "--eval" });
275
4314
  AddAlias("-p", "--print");
276
  AddOption("--require",
277
            "module to preload (option can be repeated)",
278
            &EnvironmentOptions::preload_modules,
279
4314
            kAllowedInEnvironment);
280
4314
  AddAlias("-r", "--require");
281
  AddOption("--interactive",
282
            "always enter the REPL even if stdin does not appear "
283
            "to be a terminal",
284
4314
            &EnvironmentOptions::force_repl);
285
4314
  AddAlias("-i", "--interactive");
286
287
4314
  AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvironment);
288
289
#if HAVE_OPENSSL
290
  AddOption("--tls-v1.0",
291
            "enable TLSv1.0 and greater by default",
292
            &EnvironmentOptions::tls_v1_0,
293
4314
            kAllowedInEnvironment);
294
  AddOption("--tls-v1.1",
295
            "enable TLSv1.1 and greater by default",
296
            &EnvironmentOptions::tls_v1_1,
297
4314
            kAllowedInEnvironment);
298
#endif
299
300
#if HAVE_INSPECTOR
301
  Insert(&DebugOptionsParser::instance,
302
4314
         &EnvironmentOptions::get_debug_options);
303
#endif  // HAVE_INSPECTOR
304
4314
}
305
306
4314
PerIsolateOptionsParser::PerIsolateOptionsParser() {
307
  AddOption("--track-heap-objects",
308
            "track heap object allocations for heap snapshots",
309
            &PerIsolateOptions::track_heap_objects,
310
4314
            kAllowedInEnvironment);
311
312
  // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
313
  AddOption("--abort-on-uncaught-exception",
314
            "aborting instead of exiting causes a core file to be generated "
315
            "for analysis",
316
            V8Option{},
317
4314
            kAllowedInEnvironment);
318
4314
  AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvironment);
319
4314
  AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvironment);
320
  AddOption("--perf-basic-prof-only-functions",
321
            "",
322
            V8Option{},
323
4314
            kAllowedInEnvironment);
324
4314
  AddOption("--perf-prof", "", V8Option{}, kAllowedInEnvironment);
325
  AddOption("--perf-prof-unwinding-info",
326
            "",
327
            V8Option{},
328
4314
            kAllowedInEnvironment);
329
4314
  AddOption("--stack-trace-limit", "", V8Option{}, kAllowedInEnvironment);
330
331
#ifdef NODE_REPORT
332
  AddOption("--diagnostic-report-uncaught-exception",
333
            "generate diagnostic report on uncaught exceptions",
334
            &PerIsolateOptions::report_uncaught_exception,
335
4314
            kAllowedInEnvironment);
336
  AddOption("--diagnostic-report-on-signal",
337
            "generate diagnostic report upon receiving signals",
338
            &PerIsolateOptions::report_on_signal,
339
4314
            kAllowedInEnvironment);
340
  AddOption("--diagnostic-report-on-fatalerror",
341
            "generate diagnostic report on fatal (internal) errors",
342
            &PerIsolateOptions::report_on_fatalerror,
343
4314
            kAllowedInEnvironment);
344
  AddOption("--diagnostic-report-signal",
345
            "causes diagnostic report to be produced on provided signal,"
346
            " unsupported in Windows. (default: SIGUSR2)",
347
            &PerIsolateOptions::report_signal,
348
4314
            kAllowedInEnvironment);
349
4314
  Implies("--diagnostic-report-signal", "--diagnostic-report-on-signal");
350
  AddOption("--diagnostic-report-filename",
351
            "define custom report file name."
352
            " (default: YYYYMMDD.HHMMSS.PID.SEQUENCE#.txt)",
353
            &PerIsolateOptions::report_filename,
354
4314
            kAllowedInEnvironment);
355
  AddOption("--diagnostic-report-directory",
356
            "define custom report pathname."
357
            " (default: current working directory of Node.js process)",
358
            &PerIsolateOptions::report_directory,
359
4314
            kAllowedInEnvironment);
360
  AddOption("--diagnostic-report-verbose",
361
            "verbose option for report generation(true|false)."
362
            " (default: false)",
363
            &PerIsolateOptions::report_verbose,
364
4314
            kAllowedInEnvironment);
365
#endif  // NODE_REPORT
366
367
  Insert(&EnvironmentOptionsParser::instance,
368
4314
         &PerIsolateOptions::get_per_env_options);
369
4314
}
370
371
4314
PerProcessOptionsParser::PerProcessOptionsParser() {
372
  AddOption("--title",
373
            "the process title to use on startup",
374
            &PerProcessOptions::title,
375
4314
            kAllowedInEnvironment);
376
  AddOption("--trace-event-categories",
377
            "comma separated list of trace event categories to record",
378
            &PerProcessOptions::trace_event_categories,
379
4314
            kAllowedInEnvironment);
380
  AddOption("--trace-event-file-pattern",
381
            "Template string specifying the filepath for the trace-events "
382
            "data, it supports ${rotation} and ${pid}.",
383
            &PerProcessOptions::trace_event_file_pattern,
384
4314
            kAllowedInEnvironment);
385
  AddAlias("--trace-events-enabled", {
386
4314
    "--trace-event-categories", "v8,node,node.async_hooks" });
387
  AddOption("--max-http-header-size",
388
            "set the maximum size of HTTP headers (default: 8KB)",
389
            &PerProcessOptions::max_http_header_size,
390
4314
            kAllowedInEnvironment);
391
  AddOption("--v8-pool-size",
392
            "set V8's thread pool size",
393
            &PerProcessOptions::v8_thread_pool_size,
394
4314
            kAllowedInEnvironment);
395
  AddOption("--zero-fill-buffers",
396
            "automatically zero-fill all newly allocated Buffer and "
397
            "SlowBuffer instances",
398
            &PerProcessOptions::zero_fill_all_buffers,
399
4314
            kAllowedInEnvironment);
400
401
4314
  AddOption("--security-reverts", "", &PerProcessOptions::security_reverts);
402
  AddOption("--completion-bash",
403
            "print source-able bash completion script",
404
4314
            &PerProcessOptions::print_bash_completion);
405
  AddOption("--help",
406
            "print node command line options",
407
4314
            &PerProcessOptions::print_help);
408
4314
  AddAlias("-h", "--help");
409
  AddOption(
410
4314
      "--version", "print Node.js version", &PerProcessOptions::print_version);
411
4314
  AddAlias("-v", "--version");
412
  AddOption("--v8-options",
413
            "print V8 command line options",
414
4314
            &PerProcessOptions::print_v8_help);
415
416
#ifdef NODE_HAVE_I18N_SUPPORT
417
  AddOption("--icu-data-dir",
418
            "set ICU data load path to dir (overrides NODE_ICU_DATA)"
419
#ifndef NODE_HAVE_SMALL_ICU
420
            " (note: linked-in ICU data is present)\n"
421
#endif
422
            ,
423
            &PerProcessOptions::icu_data_dir,
424
4314
            kAllowedInEnvironment);
425
#endif
426
427
#if HAVE_OPENSSL
428
  AddOption("--openssl-config",
429
            "load OpenSSL configuration from the specified file "
430
            "(overrides OPENSSL_CONF)",
431
            &PerProcessOptions::openssl_config,
432
4314
            kAllowedInEnvironment);
433
  AddOption("--tls-cipher-list",
434
            "use an alternative default TLS cipher list",
435
            &PerProcessOptions::tls_cipher_list,
436
4314
            kAllowedInEnvironment);
437
  AddOption("--use-openssl-ca",
438
            "use OpenSSL's default CA store"
439
#if defined(NODE_OPENSSL_CERT_STORE)
440
            " (default)"
441
#endif
442
            ,
443
            &PerProcessOptions::use_openssl_ca,
444
4314
            kAllowedInEnvironment);
445
  AddOption("--use-bundled-ca",
446
            "use bundled CA store"
447
#if !defined(NODE_OPENSSL_CERT_STORE)
448
            " (default)"
449
#endif
450
            ,
451
            &PerProcessOptions::use_bundled_ca,
452
4314
            kAllowedInEnvironment);
453
  // Similar to [has_eval_string] above, except that the separation between
454
  // this and use_openssl_ca only exists for option validation after parsing.
455
  // This is not ideal.
456
  AddOption("[ssl_openssl_cert_store]",
457
            "",
458
4314
            &PerProcessOptions::ssl_openssl_cert_store);
459
4314
  Implies("--use-openssl-ca", "[ssl_openssl_cert_store]");
460
4314
  ImpliesNot("--use-bundled-ca", "[ssl_openssl_cert_store]");
461
#if NODE_FIPS_MODE
462
  AddOption("--enable-fips",
463
            "enable FIPS crypto at startup",
464
            &PerProcessOptions::enable_fips_crypto,
465
            kAllowedInEnvironment);
466
  AddOption("--force-fips",
467
            "force FIPS crypto (cannot be disabled)",
468
            &PerProcessOptions::force_fips_crypto,
469
            kAllowedInEnvironment);
470
#endif
471
#endif
472
473
  Insert(&PerIsolateOptionsParser::instance,
474
4314
         &PerProcessOptions::get_per_isolate_options);
475
4314
}
476
477
107
inline std::string RemoveBrackets(const std::string& host) {
478


107
  if (!host.empty() && host.front() == '[' && host.back() == ']')
479
4
    return host.substr(1, host.size() - 2);
480
  else
481
103
    return host;
482
}
483
484
95
inline int ParseAndValidatePort(const std::string& port,
485
                                std::vector<std::string>* errors) {
486
  char* endptr;
487
95
  errno = 0;
488
95
  const long result = strtol(port.c_str(), &endptr, 10);  // NOLINT(runtime/int)
489

95
  if (errno != 0 || *endptr != '\0'||
490

64
      (result != 0 && result < 1024) || result > 65535) {
491
    errors->push_back(" must be 0 or in range 1024 to 65535.");
492
  }
493
95
  return static_cast<int>(result);
494
}
495
496
95
HostPort SplitHostPort(const std::string& arg,
497
                      std::vector<std::string>* errors) {
498
  // remove_brackets only works if no port is specified
499
  // so if it has an effect only an IPv6 address was specified.
500
95
  std::string host = RemoveBrackets(arg);
501
95
  if (host.length() < arg.length())
502
    return HostPort{host, DebugOptions::kDefaultInspectorPort};
503
504
95
  size_t colon = arg.rfind(':');
505
95
  if (colon == std::string::npos) {
506
    // Either a port number or a host name.  Assume that
507
    // if it's not all decimal digits, it's a host name.
508
383
    for (char c : arg) {
509

300
      if (c < '0' || c > '9') {
510
        return HostPort{arg, DebugOptions::kDefaultInspectorPort};
511
      }
512
    }
513
83
    return HostPort { "", ParseAndValidatePort(arg, errors) };
514
  }
515
  // Host and port found:
516
  return HostPort { RemoveBrackets(arg.substr(0, colon)),
517
12
                    ParseAndValidatePort(arg.substr(colon + 1), errors) };
518
}
519
520
// Return a map containing all the options and their metadata as well
521
// as the aliases
522
4416
void GetOptions(const FunctionCallbackInfo<Value>& args) {
523
4416
  Mutex::ScopedLock lock(per_process::cli_options_mutex);
524
4416
  Environment* env = Environment::GetCurrent(args);
525
4416
  Isolate* isolate = env->isolate();
526
4416
  Local<Context> context = env->context();
527
528
  // Temporarily act as if the current Environment's/IsolateData's options were
529
  // the default options, i.e. like they are the ones we'd access for global
530
  // options parsing, so that all options are available from the main parser.
531
8832
  auto original_per_isolate = per_process::cli_options->per_isolate;
532
4416
  per_process::cli_options->per_isolate = env->isolate_data()->options();
533
8832
  auto original_per_env = per_process::cli_options->per_isolate->per_env;
534
4416
  per_process::cli_options->per_isolate->per_env = env->options();
535
4416
  OnScopeLeave on_scope_leave([&]() {
536
4416
    per_process::cli_options->per_isolate->per_env = original_per_env;
537
4416
    per_process::cli_options->per_isolate = original_per_isolate;
538
13248
  });
539
540
4416
  const auto& parser = PerProcessOptionsParser::instance;
541
542
4416
  Local<Map> options = Map::New(isolate);
543
304704
  for (const auto& item : parser.options_) {
544
    Local<Value> value;
545
300288
    const auto& option_info = item.second;
546
300288
    auto field = option_info.field;
547
300288
    PerProcessOptions* opts = per_process::cli_options.get();
548


300288
    switch (option_info.type) {
549
      case kNoOp:
550
      case kV8Option:
551
        // Special case for --abort-on-uncaught-exception which is also
552
        // respected by Node.js internals
553
39744
        if (item.first == "--abort-on-uncaught-exception") {
554
          value = Boolean::New(
555
8832
            isolate, original_per_env->abort_on_uncaught_exception);
556
        } else {
557
35328
          value = Undefined(isolate);
558
        }
559
39744
        break;
560
      case kBoolean:
561
353280
        value = Boolean::New(isolate, *parser.Lookup<bool>(field, opts));
562
176640
        break;
563
      case kInteger:
564
8832
        value = Number::New(isolate, *parser.Lookup<int64_t>(field, opts));
565
4416
        break;
566
      case kUInteger:
567
8832
        value = Number::New(isolate, *parser.Lookup<uint64_t>(field, opts));
568
4416
        break;
569
      case kString:
570
185472
        if (!ToV8Value(context, *parser.Lookup<std::string>(field, opts))
571
185472
                 .ToLocal(&value)) {
572
          return;
573
        }
574
61824
        break;
575
      case kStringList:
576
17664
        if (!ToV8Value(context,
577
17664
                       *parser.Lookup<std::vector<std::string>>(field, opts))
578
26496
                 .ToLocal(&value)) {
579
          return;
580
        }
581
8832
        break;
582
      case kHostPort: {
583
4416
        const HostPort& host_port = *parser.Lookup<HostPort>(field, opts);
584
4416
        Local<Object> obj = Object::New(isolate);
585
        Local<Value> host;
586

26496
        if (!ToV8Value(context, host_port.host()).ToLocal(&host) ||
587


39744
            obj->Set(context, env->host_string(), host).IsNothing() ||
588
            obj->Set(context,
589
                     env->port_string(),
590

17664
                     Integer::New(isolate, host_port.port()))
591
22080
                .IsNothing()) {
592
          return;
593
        }
594
4416
        value = obj;
595
4416
        break;
596
      }
597
      default:
598
        UNREACHABLE();
599
    }
600
300288
    CHECK(!value.IsEmpty());
601
602
600576
    Local<Value> name = ToV8Value(context, item.first).ToLocalChecked();
603
300288
    Local<Object> info = Object::New(isolate);
604
    Local<Value> help_text;
605

2102016
    if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) ||
606
900864
        !info->Set(context, env->help_text_string(), help_text)
607

2702592
             .FromMaybe(false) ||
608
        !info->Set(context,
609
                   env->env_var_settings_string(),
610
                   Integer::New(isolate,
611

1201152
                                static_cast<int>(option_info.env_setting)))
612

3002880
             .FromMaybe(false) ||
613
        !info->Set(context,
614
                   env->type_string(),
615

1201152
                   Integer::New(isolate, static_cast<int>(option_info.type)))
616

2702592
             .FromMaybe(false) ||
617


3002880
        info->Set(context, env->value_string(), value).IsNothing() ||
618

1201152
        options->Set(context, name, info).IsEmpty()) {
619
      return;
620
    }
621
300288
  }
622
623
  Local<Value> aliases;
624
8832
  if (!ToV8Value(context, parser.aliases_).ToLocal(&aliases)) return;
625
626
4416
  Local<Object> ret = Object::New(isolate);
627



35328
  if (ret->Set(context, env->options_string(), options).IsNothing() ||
628

22080
      ret->Set(context, env->aliases_string(), aliases).IsNothing()) {
629
    return;
630
  }
631
632
13248
  args.GetReturnValue().Set(ret);
633
}
634
635
4416
void Initialize(Local<Object> target,
636
                Local<Value> unused,
637
                Local<Context> context,
638
                void* priv) {
639
4416
  Environment* env = Environment::GetCurrent(context);
640
4416
  Isolate* isolate = env->isolate();
641
4416
  env->SetMethodNoSideEffect(target, "getOptions", GetOptions);
642
643
4416
  Local<Object> env_settings = Object::New(isolate);
644
17664
  NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment);
645
17664
  NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvironment);
646
  target
647
      ->Set(
648
13248
          context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings)
649
8832
      .FromJust();
650
651
4416
  Local<Object> types = Object::New(isolate);
652
17664
  NODE_DEFINE_CONSTANT(types, kNoOp);
653
17664
  NODE_DEFINE_CONSTANT(types, kV8Option);
654
17664
  NODE_DEFINE_CONSTANT(types, kBoolean);
655
17664
  NODE_DEFINE_CONSTANT(types, kInteger);
656
17664
  NODE_DEFINE_CONSTANT(types, kUInteger);
657
17664
  NODE_DEFINE_CONSTANT(types, kString);
658
17664
  NODE_DEFINE_CONSTANT(types, kHostPort);
659
17664
  NODE_DEFINE_CONSTANT(types, kStringList);
660
13248
  target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "types"), types)
661
8832
      .FromJust();
662
4416
}
663
664
}  // namespace options_parser
665
}  // namespace node
666
667

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