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: 240 257 93.4 %
Date: 2019-02-23 22:23:05 Branches: 132 204 64.7 %

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
4288
Mutex cli_options_mutex;
23
4288
std::shared_ptr<PerProcessOptions> cli_options{new PerProcessOptions()};
24
}  // namespace per_process
25
26
8422
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

8422
  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

8422
  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
8422
}
45
46
8415
void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
47
#if HAVE_OPENSSL
48

8415
  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
8415
  per_isolate->CheckOptions(errors);
54
8415
}
55
56
8422
void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
57
8422
  per_env->CheckOptions(errors);
58
#ifdef NODE_REPORT
59
8422
  if (per_env->experimental_report)
60
8430
    return;
61
62
8414
  if (!report_directory.empty()) {
63
    errors->push_back("--diagnostic-report-directory option is valid only when "
64
                      "--experimental-report is set");
65
  }
66
67
8414
  if (!report_filename.empty()) {
68
    errors->push_back("--diagnostic-report-filename option is valid only when "
69
                      "--experimental-report is set");
70
  }
71
72
8414
  if (!report_signal.empty()) {
73
    errors->push_back("--diagnostic-report-signal option is valid only when "
74
                      "--experimental-report is set");
75
  }
76
77
8414
  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
8414
  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
8414
  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
#endif  // NODE_REPORT
94
}
95
96
8422
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
97

8422
  if (!userland_loader.empty() && !experimental_modules) {
98
    errors->push_back("--loader requires --experimental-modules be enabled");
99
  }
100
101

8422
  if (syntax_check_only && has_eval_string) {
102
4
    errors->push_back("either --check or --eval can be used, not both");
103
  }
104
105

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


107
  if (!host.empty() && host.front() == '[' && host.back() == ']')
469
4
    return host.substr(1, host.size() - 2);
470
  else
471
103
    return host;
472
}
473
474
95
inline int ParseAndValidatePort(const std::string& port,
475
                                std::vector<std::string>* errors) {
476
  char* endptr;
477
95
  errno = 0;
478
95
  const long result = strtol(port.c_str(), &endptr, 10);  // NOLINT(runtime/int)
479

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

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

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


294800
    switch (option_info.type) {
539
      case kNoOp:
540
      case kV8Option:
541
        // Special case for --abort-on-uncaught-exception which is also
542
        // respected by Node.js internals
543
39600
        if (item.first == "--abort-on-uncaught-exception") {
544
          value = Boolean::New(
545
8800
            isolate, original_per_env->abort_on_uncaught_exception);
546
        } else {
547
35200
          value = Undefined(isolate);
548
        }
549
39600
        break;
550
      case kBoolean:
551
343200
        value = Boolean::New(isolate, *parser.Lookup<bool>(field, opts));
552
171600
        break;
553
      case kInteger:
554
8800
        value = Number::New(isolate, *parser.Lookup<int64_t>(field, opts));
555
4400
        break;
556
      case kUInteger:
557
8800
        value = Number::New(isolate, *parser.Lookup<uint64_t>(field, opts));
558
4400
        break;
559
      case kString:
560
184800
        if (!ToV8Value(context, *parser.Lookup<std::string>(field, opts))
561
184800
                 .ToLocal(&value)) {
562
          return;
563
        }
564
61600
        break;
565
      case kStringList:
566
17600
        if (!ToV8Value(context,
567
17600
                       *parser.Lookup<std::vector<std::string>>(field, opts))
568
26400
                 .ToLocal(&value)) {
569
          return;
570
        }
571
8800
        break;
572
      case kHostPort: {
573
4400
        const HostPort& host_port = *parser.Lookup<HostPort>(field, opts);
574
4400
        Local<Object> obj = Object::New(isolate);
575
        Local<Value> host;
576

26400
        if (!ToV8Value(context, host_port.host()).ToLocal(&host) ||
577


39600
            obj->Set(context, env->host_string(), host).IsNothing() ||
578
            obj->Set(context,
579
                     env->port_string(),
580

17600
                     Integer::New(isolate, host_port.port()))
581
22000
                .IsNothing()) {
582
          return;
583
        }
584
4400
        value = obj;
585
4400
        break;
586
      }
587
      default:
588
        UNREACHABLE();
589
    }
590
294800
    CHECK(!value.IsEmpty());
591
592
589600
    Local<Value> name = ToV8Value(context, item.first).ToLocalChecked();
593
294800
    Local<Object> info = Object::New(isolate);
594
    Local<Value> help_text;
595

2063600
    if (!ToV8Value(context, option_info.help_text).ToLocal(&help_text) ||
596
884400
        !info->Set(context, env->help_text_string(), help_text)
597

2653200
             .FromMaybe(false) ||
598
        !info->Set(context,
599
                   env->env_var_settings_string(),
600
                   Integer::New(isolate,
601

1179200
                                static_cast<int>(option_info.env_setting)))
602

2948000
             .FromMaybe(false) ||
603
        !info->Set(context,
604
                   env->type_string(),
605

1179200
                   Integer::New(isolate, static_cast<int>(option_info.type)))
606

2653200
             .FromMaybe(false) ||
607


2948000
        info->Set(context, env->value_string(), value).IsNothing() ||
608

1179200
        options->Set(context, name, info).IsEmpty()) {
609
      return;
610
    }
611
294800
  }
612
613
  Local<Value> aliases;
614
8800
  if (!ToV8Value(context, parser.aliases_).ToLocal(&aliases)) return;
615
616
4400
  Local<Object> ret = Object::New(isolate);
617



35200
  if (ret->Set(context, env->options_string(), options).IsNothing() ||
618

22000
      ret->Set(context, env->aliases_string(), aliases).IsNothing()) {
619
    return;
620
  }
621
622
13200
  args.GetReturnValue().Set(ret);
623
}
624
625
4400
void Initialize(Local<Object> target,
626
                Local<Value> unused,
627
                Local<Context> context,
628
                void* priv) {
629
4400
  Environment* env = Environment::GetCurrent(context);
630
4400
  Isolate* isolate = env->isolate();
631
4400
  env->SetMethodNoSideEffect(target, "getOptions", GetOptions);
632
633
4400
  Local<Object> env_settings = Object::New(isolate);
634
17600
  NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment);
635
17600
  NODE_DEFINE_CONSTANT(env_settings, kDisallowedInEnvironment);
636
  target
637
      ->Set(
638
13200
          context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings)
639
8800
      .FromJust();
640
641
4400
  Local<Object> types = Object::New(isolate);
642
17600
  NODE_DEFINE_CONSTANT(types, kNoOp);
643
17600
  NODE_DEFINE_CONSTANT(types, kV8Option);
644
17600
  NODE_DEFINE_CONSTANT(types, kBoolean);
645
17600
  NODE_DEFINE_CONSTANT(types, kInteger);
646
17600
  NODE_DEFINE_CONSTANT(types, kUInteger);
647
17600
  NODE_DEFINE_CONSTANT(types, kString);
648
17600
  NODE_DEFINE_CONSTANT(types, kHostPort);
649
17600
  NODE_DEFINE_CONSTANT(types, kStringList);
650
13200
  target->Set(context, FIXED_ONE_BYTE_STRING(isolate, "types"), types)
651
8800
      .FromJust();
652
4400
}
653
654
}  // namespace options_parser
655
}  // namespace node
656
657

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