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

Line 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
223
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
21
  HandleWrap* wrap;
22
223
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
23
24
444
  if (IsAlive(wrap))
25
222
    uv_ref(wrap->GetHandle());
26
}
27
28
29
863
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
30
  HandleWrap* wrap;
31
863
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
32
33
1726
  if (IsAlive(wrap))
34
863
    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
8526
void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
46
8526
  Environment* env = Environment::GetCurrent(args);
47
48
  HandleWrap* wrap;
49
8526
  ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
50
51
  // Guard against uninitialized handle or double close.
52
17050
  if (!IsAlive(wrap))
53
    return;
54
55
8525
  if (wrap->state_ != kInitialized)
56
    return;
57
58
16694
  CHECK_EQ(false, wrap->persistent().IsEmpty());
59
8347
  uv_close(wrap->handle__, OnClose);
60
8347
  wrap->state_ = kClosing;
61
62
8347
  if (args[0]->IsFunction()) {
63
24584
    wrap->object()->Set(env->onclose_string(), args[0]);
64
6146
    wrap->state_ = kClosingWithCallback;
65
  }
66
}
67
68
69
9452
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
18904
      handle__(handle) {
77
9452
  handle__->data = this;
78
18904
  HandleScope scope(env->isolate());
79
9452
  Wrap(object, this);
80
18904
  env->handle_wrap_queue()->PushBack(this);
81
9452
}
82
83
84
24795
HandleWrap::~HandleWrap() {
85
16530
  CHECK(persistent().IsEmpty());
86
8265
}
87
88
89
8267
void HandleWrap::OnClose(uv_handle_t* handle) {
90
8267
  HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
91
8267
  Environment* env = wrap->env();
92
16532
  HandleScope scope(env->isolate());
93
24799
  Context::Scope context_scope(env->context());
94
95
  // The wrap object should still be there.
96
16534
  CHECK_EQ(wrap->persistent().IsEmpty(), false);
97
8267
  CHECK(wrap->state_ >= kClosing && wrap->state_ <= kClosingWithCallback);
98
99
8267
  const bool have_close_callback = (wrap->state_ == kClosingWithCallback);
100
8267
  wrap->state_ = kClosed;
101
102
8267
  if (have_close_callback)
103
6117
    wrap->MakeCallback(env->onclose_string(), 0, nullptr);
104
105
16530
  ClearWrap(wrap->object());
106
16530
  wrap->persistent().Reset();
107
8265
  delete wrap;
108
8265
}
109
110
111
}  // namespace node