GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/src/base-object-inl.h Lines: 23 24 95.8 %
Date: 2016-07-26 Branches: 26 70 37.1 %

Line Exec Source
1
#ifndef SRC_BASE_OBJECT_INL_H_
2
#define SRC_BASE_OBJECT_INL_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "base-object.h"
7
#include "env.h"
8
#include "env-inl.h"
9
#include "util.h"
10
#include "util-inl.h"
11
#include "v8.h"
12
13
namespace node {
14
15
111818
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
16
    : persistent_handle_(env->isolate(), handle),
17
223636
      env_(env) {
18
111818
  CHECK_EQ(false, handle.IsEmpty());
19
  // The zero field holds a pointer to the handle. Immediately set it to
20
  // nullptr in case it's accessed by the user before construction is complete.
21
111818
  if (handle->InternalFieldCount() > 0)
22
111818
    handle->SetAlignedPointerInInternalField(0, nullptr);
23
111818
}
24
25
26
287088
inline BaseObject::~BaseObject() {
27
191392
  CHECK(persistent_handle_.IsEmpty());
28
}
29
30
31
inline v8::Persistent<v8::Object>& BaseObject::persistent() {
32
  return persistent_handle_;
33
}
34
35
36
inline v8::Local<v8::Object> BaseObject::object() {
37
448355
  return PersistentToLocal(env_->isolate(), persistent_handle_);
38
}
39
40
41
inline Environment* BaseObject::env() const {
42
  return env_;
43
}
44
45
46
template <typename Type>
47
52724
inline void BaseObject::WeakCallback(
48
    const v8::WeakCallbackInfo<Type>& data) {
49
52724
  Type* self = data.GetParameter();
50
105448
  self->persistent().Reset();
51
52724
  delete self;
52
52724
}
53
54
55
template <typename Type>
56
66023
inline void BaseObject::MakeWeak(Type* ptr) {
57
132046
  v8::HandleScope scope(env_->isolate());
58
66023
  v8::Local<v8::Object> handle = object();
59
66023
  CHECK_GT(handle->InternalFieldCount(), 0);
60
66023
  Wrap(handle, ptr);
61
132046
  persistent_handle_.MarkIndependent();
62
132046
  persistent_handle_.SetWeak<Type>(ptr, WeakCallback<Type>,
63
                                   v8::WeakCallbackType::kParameter);
64
66023
}
65
66
67
inline void BaseObject::ClearWeak() {
68
412
  persistent_handle_.ClearWeak();
69
}
70
71
}  // namespace node
72
73
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
74
75
#endif  // SRC_BASE_OBJECT_INL_H_