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-11-30 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
227
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
21
  HandleWrap* wrap;
22
227
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
23
24
452
  if (IsAlive(wrap))
25
226
    uv_ref(wrap->GetHandle());
26
}
27
28
29
1445
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
30
  HandleWrap* wrap;
31
1445
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
32
33
2890
  if (IsAlive(wrap))
34
1445
    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
8771
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
46
8771
  Environment* env = Environment::GetCurrent(args);
47
48
  HandleWrap* wrap;
49
8771
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
50
51
  // Guard against uninitialized handle or double close.
52
17540
  if (!IsAlive(wrap))
53
    return;
54
55
8770
  if (wrap->state_ != kInitialized)
56
    return;
57
58
17002
  CHECK_EQ(false, wrap->persistent().IsEmpty());
59
8501
  uv_close(wrap->handle_, OnClose);
60
8501
  wrap->state_ = kClosing;
61
62
8501
  if (args[0]->IsFunction()) {
63
24368
    wrap->object()->Set(env->onclose_string(), args[0]);
64
6092
    wrap->state_ = kClosingWithCallback;
65
  }
66
}
67
68
69
10215
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
20430
      handle_(handle) {
77
10215
  handle_->data = this;
78
20430
  HandleScope scope(env->isolate());
79
10215
  Wrap(object, this);
80
20430
  env->handle_wrap_queue()->PushBack(this);
81
10215
}
82
83
84
25236
HandleWrap::~HandleWrap() {
85
16824
  CHECK(persistent().IsEmpty());
86
8412
}
87
88
89
8414
void HandleWrap::OnClose(uv_handle_t* handle) {
90
8414
  HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
91
8414
  Environment* env = wrap->env();
92
16826
  HandleScope scope(env->isolate());
93
25240
  Context::Scope context_scope(env->context());
94
95
  // The wrap object should still be there.
96
16828
  CHECK_EQ(wrap->persistent().IsEmpty(), false);
97
8414
  CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
98
99
8414
  const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
100
8414
  wrap->state_ = kClosed;
101
102
8414
  if (have_close_callback)
103
6055
    wrap->MakeCallback(env->onclose_string(), 0, nullptr);
104
105
16824
  ClearWrap(wrap->object());
106
16824
  wrap->persistent().Reset();
107
8412
  delete wrap;
108
8412
}
109
110
111
}  // namespace node