GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/handle_wrap.cc Lines: 47 47 100.0 %
Date: 2016-12-18 Branches: 20 30 66.7 %

Line Branch Exec Source
1
#include "handle_wrap.h"
2
#include "async-wrap.h"
3
#include "async-wrap-inl.h"
4
#include "env.h"
5
#include "env-inl.h"
6
#include "util.h"
7
#include "util-inl.h"
8
#include "node.h"
9
10
namespace node {
11
12
using v8::Context;
13
using v8::FunctionCallbackInfo;
14
using v8::HandleScope;
15
using v8::Local;
16
using v8::Object;
17
using v8::Value;
18
19
20
229
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
21
  HandleWrap* wrap;
22
229
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
23
24
456
  if (IsAlive(wrap))
25
228
    uv_ref(wrap->GetHandle());
26
}
27
28
29
1459
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
30
  HandleWrap* wrap;
31
1459
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
32
33
2918
  if (IsAlive(wrap))
34
1459
    uv_unref(wrap->GetHandle());
35
}
36
37
38
26
void HandleWrap::HasRef(const FunctionCallbackInfo<Value>& args) {
39
  HandleWrap* wrap;
40
26
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
41
78
  args.GetReturnValue().Set(HasRef(wrap));
42
}
43
44
45
8820
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
46
8820
  Environment* env = Environment::GetCurrent(args);
47
48
  HandleWrap* wrap;
49
8820
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
50
51
  // Guard against uninitialized handle or double close.
52
17638
  if (!IsAlive(wrap))
53
    return;
54
55
8819
  if (wrap->state_ != kInitialized)
56
    return;
57
58
17100
  CHECK_EQ(false, wrap->persistent().IsEmpty());
59
8550
  uv_close(wrap->handle_, OnClose);
60
8550
  wrap->state_ = kClosing;
61
62
8550
  if (args[0]->IsFunction()) {
63
24504
    wrap->object()->Set(env->onclose_string(), args[0]);
64
6126
    wrap->state_ = kClosingWithCallback;
65
  }
66
}
67
68
69
10283
HandleWrap::HandleWrap(Environment* env,
70
                       Local<Object> object,
71
                       uv_handle_t* handle,
72
                       AsyncWrap::ProviderType provider,
73
                       AsyncWrap* parent)
74
    : AsyncWrap(env, object, provider, parent),
75
      state_(kInitialized),
76
20566
      handle_(handle) {
77
10283
  handle_->data = this;
78
20566
  HandleScope scope(env->isolate());
79
10283
  Wrap(object, this);
80
20566
  env->handle_wrap_queue()->PushBack(this);
81
10283
}
82
83
84
25392
HandleWrap::~HandleWrap() {
85
16928
  CHECK(persistent().IsEmpty());
86
8464
}
87
88
89
8466
void HandleWrap::OnClose(uv_handle_t* handle) {
90
8466
  HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
91
8466
  Environment* env = wrap->env();
92
16930
  HandleScope scope(env->isolate());
93
25396
  Context::Scope context_scope(env->context());
94
95
  // The wrap object should still be there.
96
16932
  CHECK_EQ(wrap->persistent().IsEmpty(), false);
97
8466
  CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
98
99
8466
  const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
100
8466
  wrap->state_ = kClosed;
101
102
8466
  if (have_close_callback)
103
6092
    wrap->MakeCallback(env->onclose_string(), 0, nullptr);
104
105
16928
  ClearWrap(wrap->object());
106
16928
  wrap->persistent().Reset();
107
8464
  delete wrap;
108
8464
}
109
110
111
}  // namespace node