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: 2017-01-02 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
228
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
21
  HandleWrap* wrap;
22
228
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
23
24
454
  if (IsAlive(wrap))
25
227
    uv_ref(wrap->GetHandle());
26
}
27
28
29
1355
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
30
  HandleWrap* wrap;
31
1355
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
32
33
2710
  if (IsAlive(wrap))
34
1355
    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
8833
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
46
8833
  Environment* env = Environment::GetCurrent(args);
47
48
  HandleWrap* wrap;
49
8833
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
50
51
  // Guard against uninitialized handle or double close.
52
17664
  if (!IsAlive(wrap))
53
    return;
54
55
8832
  if (wrap->state_ != kInitialized)
56
    return;
57
58
17126
  CHECK_EQ(false, wrap->persistent().IsEmpty());
59
8563
  uv_close(wrap->handle_, OnClose);
60
8563
  wrap->state_ = kClosing;
61
62
8563
  if (args[0]->IsFunction()) {
63
24616
    wrap->object()->Set(env->onclose_string(), args[0]);
64
6154
    wrap->state_ = kClosingWithCallback;
65
  }
66
}
67
68
69
10188
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
20376
      handle_(handle) {
77
10188
  handle_->data = this;
78
20376
  HandleScope scope(env->isolate());
79
10188
  Wrap(object, this);
80
20376
  env->handle_wrap_queue()->PushBack(this);
81
10188
}
82
83
84
25434
HandleWrap::~HandleWrap() {
85
16956
  CHECK(persistent().IsEmpty());
86
8478
}
87
88
89
8479
void HandleWrap::OnClose(uv_handle_t* handle) {
90
8479
  HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
91
8479
  Environment* env = wrap->env();
92
16957
  HandleScope scope(env->isolate());
93
25436
  Context::Scope context_scope(env->context());
94
95
  // The wrap object should still be there.
96
16958
  CHECK_EQ(wrap->persistent().IsEmpty(), false);
97
8479
  CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
98
99
8479
  const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
100
8479
  wrap->state_ = kClosed;
101
102
8479
  if (have_close_callback)
103
6119
    wrap->MakeCallback(env->onclose_string(), 0, nullptr);
104
105
16956
  ClearWrap(wrap->object());
106
16956
  wrap->persistent().Reset();
107
8478
  delete wrap;
108
8478
}
109
110
111
}  // namespace node