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-23 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
111879
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
16
    : handle_(env->isolate(), handle),
17
223758
      env_(env) {
18
111879
  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
111879
  if (handle->InternalFieldCount() > 0)
22
111879
    handle->SetAlignedPointerInInternalField(0, nullptr);
23
111879
}
24
25
26
287400
inline BaseObject::~BaseObject() {
27
191600
  CHECK(handle_.IsEmpty());
28
}
29
30
31
inline v8::Persistent<v8::Object>& BaseObject::persistent() {
32
  return handle_;
33
}
34
35
36
inline v8::Local<v8::Object> BaseObject::object() {
37
451174
  return PersistentToLocal(env_->isolate(), handle_);
38
}
39
40
41
inline Environment* BaseObject::env() const {
42
  return env_;
43
}
44
45
46
template <typename Type>
47
52848
inline void BaseObject::WeakCallback(
48
    const v8::WeakCallbackInfo<Type>& data) {
49
52848
  Type* self = data.GetParameter();
50
105696
  self->persistent().Reset();
51
52848
  delete self;
52
52848
}
53
54
55
template <typename Type>
56
66099
inline void BaseObject::MakeWeak(Type* ptr) {
57
132198
  v8::HandleScope scope(env_->isolate());
58
66099
  v8::Local<v8::Object> handle = object();
59
66099
  CHECK_GT(handle->InternalFieldCount(), 0);
60
66099
  Wrap(handle, ptr);
61
132198
  handle_.MarkIndependent();
62
132198
  handle_.SetWeak<Type>(ptr, WeakCallback<Type>,
63
                        v8::WeakCallbackType::kParameter);
64
66099
}
65
66
67
inline void BaseObject::ClearWeak() {
68
412
  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_