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-10-21 Branches: 12 12 100.0 %

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