GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/node_config.cc Lines: 31 31 100.0 %
Date: 2017-12-18 Branches: 12 12 100.0 %

Line Branch Exec Source
1
#include "node.h"
2
#include "node_i18n.h"
3
#include "env-inl.h"
4
#include "util-inl.h"
5
#include "node_debug_options.h"
6
7
namespace node {
8
9
using v8::Boolean;
10
using v8::Context;
11
using v8::Integer;
12
using v8::Isolate;
13
using v8::Local;
14
using v8::Number;
15
using v8::Object;
16
using v8::ReadOnly;
17
using v8::String;
18
using v8::Value;
19
20
// The config binding is used to provide an internal view of compile or runtime
21
// config options that are required internally by lib/*.js code. This is an
22
// alternative to dropping additional properties onto the process object as
23
// has been the practice previously in node.cc.
24
25
#define READONLY_BOOLEAN_PROPERTY(str)                                        \
26
  do {                                                                        \
27
    target->DefineOwnProperty(context,                                        \
28
                              FIXED_ONE_BYTE_STRING(isolate, str),            \
29
                              True(isolate), ReadOnly).FromJust();            \
30
  } while (0)
31
32
#define READONLY_PROPERTY(obj, name, value)                                   \
33
  do {                                                                        \
34
    obj->DefineOwnProperty(env->context(),                                    \
35
                           FIXED_ONE_BYTE_STRING(isolate, name),              \
36
                           value, ReadOnly).FromJust();                       \
37
  } while (0)
38
39
3348
static void InitConfig(Local<Object> target,
40
                       Local<Value> unused,
41
                       Local<Context> context) {
42
3348
  Environment* env = Environment::GetCurrent(context);
43
3348
  Isolate* isolate = env->isolate();
44
45
#ifdef NODE_FIPS_MODE
46
  READONLY_BOOLEAN_PROPERTY("fipsMode");
47
  if (force_fips_crypto)
48
    READONLY_BOOLEAN_PROPERTY("fipsForced");
49
#endif
50
51
#ifdef NODE_HAVE_I18N_SUPPORT
52
53
10044
  READONLY_BOOLEAN_PROPERTY("hasIntl");
54
55
#ifdef NODE_HAVE_SMALL_ICU
56
10044
  READONLY_BOOLEAN_PROPERTY("hasSmallICU");
57
#endif  // NODE_HAVE_SMALL_ICU
58
59
  target->DefineOwnProperty(
60
      context,
61
      FIXED_ONE_BYTE_STRING(isolate, "icuDataDir"),
62
      String::NewFromUtf8(isolate,
63
                          icu_data_dir.data(),
64
3348
                          v8::NewStringType::kNormal).ToLocalChecked(),
65
13392
      ReadOnly).FromJust();
66
67
#endif  // NODE_HAVE_I18N_SUPPORT
68
69
3348
  if (config_preserve_symlinks)
70
24
    READONLY_BOOLEAN_PROPERTY("preserveSymlinks");
71
72
3348
  if (config_experimental_modules) {
73
96
    READONLY_BOOLEAN_PROPERTY("experimentalModules");
74
32
    if (!config_userland_loader.empty()) {
75
      target->DefineOwnProperty(
76
          context,
77
          FIXED_ONE_BYTE_STRING(isolate, "userLoader"),
78
          String::NewFromUtf8(isolate,
79
                              config_userland_loader.data(),
80
7
                              v8::NewStringType::kNormal).ToLocalChecked(),
81
28
          ReadOnly).FromJust();
82
    }
83
  }
84
85
3348
  if (config_pending_deprecation)
86
12
    READONLY_BOOLEAN_PROPERTY("pendingDeprecation");
87
88
3348
  if (config_expose_internals)
89
291
    READONLY_BOOLEAN_PROPERTY("exposeInternals");
90
91
16740
  READONLY_PROPERTY(target,
92
                    "bits",
93
                    Number::New(env->isolate(), 8 * sizeof(intptr_t)));
94
95
3348
  if (!config_warning_file.empty()) {
96
    target->DefineOwnProperty(
97
        context,
98
        FIXED_ONE_BYTE_STRING(isolate, "warningFile"),
99
        String::NewFromUtf8(isolate,
100
                            config_warning_file.data(),
101
3
                            v8::NewStringType::kNormal).ToLocalChecked(),
102
12
        ReadOnly).FromJust();
103
  }
104
105
3348
  Local<Object> debugOptions = Object::New(isolate);
106
107
  target->DefineOwnProperty(
108
      context,
109
      FIXED_ONE_BYTE_STRING(isolate, "debugOptions"),
110
10044
      debugOptions, ReadOnly).FromJust();
111
112
  debugOptions->DefineOwnProperty(
113
      context,
114
      FIXED_ONE_BYTE_STRING(isolate, "host"),
115
      String::NewFromUtf8(isolate,
116
                          debug_options.host_name().c_str(),
117
6696
                          v8::NewStringType::kNormal).ToLocalChecked(),
118
13392
      ReadOnly).FromJust();
119
120
  debugOptions->DefineOwnProperty(
121
      context,
122
      env->port_string(),
123
      Integer::New(isolate, debug_options.port()),
124
13392
      ReadOnly).FromJust();
125
126
  debugOptions->DefineOwnProperty(
127
      context,
128
      FIXED_ONE_BYTE_STRING(isolate, "inspectorEnabled"),
129
13392
      Boolean::New(isolate, debug_options.inspector_enabled()), ReadOnly)
130
6696
          .FromJust();
131
3348
}  // InitConfig
132
133
}  // namespace node
134
135
3391
NODE_BUILTIN_MODULE_CONTEXT_AWARE(config, node::InitConfig)