GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/node_util.cc Lines: 56 58 96.6 %
Date: 2016-09-05 Branches: 23 36 63.9 %

Line Branch Exec Source
1
#include "node.h"
2
#include "node_watchdog.h"
3
#include "v8.h"
4
#include "env.h"
5
#include "env-inl.h"
6
7
namespace node {
8
namespace util {
9
10
using v8::Array;
11
using v8::Context;
12
using v8::FunctionCallbackInfo;
13
using v8::Integer;
14
using v8::Local;
15
using v8::Object;
16
using v8::Private;
17
using v8::Proxy;
18
using v8::Value;
19
20
21
#define VALUE_METHOD_MAP(V)                                                   \
22
  V(isArrayBuffer, IsArrayBuffer)                                             \
23
  V(isDataView, IsDataView)                                                   \
24
  V(isDate, IsDate)                                                           \
25
  V(isMap, IsMap)                                                             \
26
  V(isMapIterator, IsMapIterator)                                             \
27
  V(isPromise, IsPromise)                                                     \
28
  V(isRegExp, IsRegExp)                                                       \
29
  V(isSet, IsSet)                                                             \
30
  V(isSetIterator, IsSetIterator)                                             \
31
  V(isTypedArray, IsTypedArray)
32
33
34
#define V(_, ucname) \
35
  static void ucname(const FunctionCallbackInfo<Value>& args) {               \
36
    CHECK_EQ(1, args.Length());                                               \
37
    args.GetReturnValue().Set(args[0]->ucname());                             \
38
  }
39
40





124940
  VALUE_METHOD_MAP(V)
41
#undef V
42
43
53
static void GetProxyDetails(const FunctionCallbackInfo<Value>& args) {
44
  // Return undefined if it's not a proxy.
45
53
  if (!args[0]->IsProxy())
46
    return;
47
48
52
  Local<Proxy> proxy = args[0].As<Proxy>();
49
50
26
  Local<Array> ret = Array::New(args.GetIsolate(), 2);
51
52
  ret->Set(0, proxy->GetTarget());
52
26
  ret->Set(1, proxy->GetHandler());
53
54
26
  args.GetReturnValue().Set(ret);
55
}
56
57
53
inline Local<Private> IndexToPrivateSymbol(Environment* env, uint32_t index) {
58
#define V(name, _) &Environment::name,
59
  static Local<Private> (Environment::*const methods[])() const = {
60
    PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
61
  };
62
#undef V
63
53
  CHECK_LT(index, arraysize(methods));
64
53
  return (env->*methods[index])();
65
}
66
67
60
static void GetHiddenValue(const FunctionCallbackInfo<Value>& args) {
68
60
  Environment* env = Environment::GetCurrent(args);
69
70
60
  if (!args[0]->IsObject())
71
8
    return env->ThrowTypeError("obj must be an object");
72
73
55
  if (!args[1]->IsUint32())
74
    return env->ThrowTypeError("index must be an uint32");
75
76
104
  Local<Object> obj = args[0].As<Object>();
77
156
  auto index = args[1]->Uint32Value(env->context()).FromJust();
78
52
  auto private_symbol = IndexToPrivateSymbol(env, index);
79
52
  auto maybe_value = obj->GetPrivate(env->context(), private_symbol);
80
81
156
  args.GetReturnValue().Set(maybe_value.ToLocalChecked());
82
}
83
84
9
static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) {
85
9
  Environment* env = Environment::GetCurrent(args);
86
87
9
  if (!args[0]->IsObject())
88
8
    return env->ThrowTypeError("obj must be an object");
89
90
4
  if (!args[1]->IsUint32())
91
    return env->ThrowTypeError("index must be an uint32");
92
93
2
  Local<Object> obj = args[0].As<Object>();
94
3
  auto index = args[1]->Uint32Value(env->context()).FromJust();
95
1
  auto private_symbol = IndexToPrivateSymbol(env, index);
96
2
  auto maybe_value = obj->SetPrivate(env->context(), private_symbol, args[2]);
97
98
3
  args.GetReturnValue().Set(maybe_value.FromJust());
99
}
100
101
102
33
void StartSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
103
33
  int ret = SigintWatchdogHelper::GetInstance()->Start();
104
33
  if (ret != 0) {
105
    Environment* env = Environment::GetCurrent(args);
106
    env->ThrowErrnoException(ret, "StartSigintWatchdog");
107
  }
108
33
}
109
110
111
31
void StopSigintWatchdog(const FunctionCallbackInfo<Value>& args) {
112
31
  bool had_pending_signals = SigintWatchdogHelper::GetInstance()->Stop();
113
93
  args.GetReturnValue().Set(had_pending_signals);
114
31
}
115
116
117
6
void WatchdogHasPendingSigint(const FunctionCallbackInfo<Value>& args) {
118
6
  bool ret = SigintWatchdogHelper::GetInstance()->HasPendingSignal();
119
18
  args.GetReturnValue().Set(ret);
120
6
}
121
122
123
1626
void Initialize(Local<Object> target,
124
                Local<Value> unused,
125
                Local<Context> context) {
126
1626
  Environment* env = Environment::GetCurrent(context);
127
128
#define V(lcname, ucname) env->SetMethod(target, #lcname, ucname);
129
1626
  VALUE_METHOD_MAP(V)
130
#undef V
131
132
#define V(name, _)                                                            \
133
  target->Set(context,                                                        \
134
              FIXED_ONE_BYTE_STRING(env->isolate(), #name),                   \
135
              Integer::NewFromUnsigned(env->isolate(), index++));
136
  {
137
1626
    uint32_t index = 0;
138
27642
    PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V)
139
  }
140
#undef V
141
142
1626
  env->SetMethod(target, "getHiddenValue", GetHiddenValue);
143
1626
  env->SetMethod(target, "setHiddenValue", SetHiddenValue);
144
1626
  env->SetMethod(target, "getProxyDetails", GetProxyDetails);
145
146
1626
  env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog);
147
1626
  env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog);
148
1626
  env->SetMethod(target, "watchdogHasPendingSigint", WatchdogHasPendingSigint);
149
1626
}
150
151
}  // namespace util
152
}  // namespace node
153
154
1631
NODE_MODULE_CONTEXT_AWARE_BUILTIN(util, node::util::Initialize)