GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/base-object-inl.h Lines: 32 32 100.0 %
Date: 2017-06-14 Branches: 18 44 40.9 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#ifndef SRC_BASE_OBJECT_INL_H_
23
#define SRC_BASE_OBJECT_INL_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "base-object.h"
28
#include "env.h"
29
#include "env-inl.h"
30
#include "util.h"
31
#include "util-inl.h"
32
#include "v8.h"
33
34
namespace node {
35
36
187944
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
37
    : persistent_handle_(env->isolate(), handle),
38
375888
      env_(env) {
39
187944
  CHECK_EQ(false, handle.IsEmpty());
40
  // The zero field holds a pointer to the handle. Immediately set it to
41
  // nullptr in case it's accessed by the user before construction is complete.
42
187944
  if (handle->InternalFieldCount() > 0)
43
187944
    handle->SetAlignedPointerInInternalField(0, nullptr);
44
187944
}
45
46
47
318836
inline BaseObject::~BaseObject() {
48
318836
  CHECK(persistent_handle_.IsEmpty());
49
159418
}
50
51
52
348833
inline v8::Persistent<v8::Object>& BaseObject::persistent() {
53
348833
  return persistent_handle_;
54
}
55
56
57
626600
inline v8::Local<v8::Object> BaseObject::object() {
58
626600
  return PersistentToLocal(env_->isolate(), persistent_handle_);
59
}
60
61
62
2972803
inline Environment* BaseObject::env() const {
63
2972803
  return env_;
64
}
65
66
67
template <typename Type>
68
115577
inline void BaseObject::WeakCallback(
69
    const v8::WeakCallbackInfo<Type>& data) {
70
115577
  Type* self = data.GetParameter();
71
115577
  self->persistent().Reset();
72




115577
  delete self;
73
115577
}
74
75
76
template <typename Type>
77
139932
inline void BaseObject::MakeWeak(Type* ptr) {
78
139932
  v8::HandleScope scope(env_->isolate());
79
139932
  v8::Local<v8::Object> handle = object();
80




139932
  CHECK_GT(handle->InternalFieldCount(), 0);
81
139932
  Wrap(handle, ptr);
82
139932
  persistent_handle_.MarkIndependent();
83
139932
  persistent_handle_.SetWeak<Type>(ptr, WeakCallback<Type>,
84
139932
                                   v8::WeakCallbackType::kParameter);
85
139932
}
86
87
88
806
inline void BaseObject::ClearWeak() {
89
806
  persistent_handle_.ClearWeak();
90
806
}
91
92
}  // namespace node
93
94
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
95
96
#endif  // SRC_BASE_OBJECT_INL_H_