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-10-21 Branches: 22 44 50.0 %

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
496464
inline BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> handle)
37
    : persistent_handle_(env->isolate(), handle),
38
992928
      env_(env) {
39
496464
  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
496464
  if (handle->InternalFieldCount() > 0)
43
496464
    handle->SetAlignedPointerInInternalField(0, nullptr);
44
496464
}
45
46
47
906088
inline BaseObject::~BaseObject() {
48
906088
  CHECK(persistent_handle_.IsEmpty());
49
453044
}
50
51
52
1202719
inline v8::Persistent<v8::Object>& BaseObject::persistent() {
53
1202719
  return persistent_handle_;
54
}
55
56
57
1685018
inline v8::Local<v8::Object> BaseObject::object() {
58
1685018
  return PersistentToLocal(env_->isolate(), persistent_handle_);
59
}
60
61
62
2604972
inline Environment* BaseObject::env() const {
63
2604972
  return env_;
64
}
65
66
67
template <typename Type>
68
224607
inline void BaseObject::WeakCallback(
69
    const v8::WeakCallbackInfo<Type>& data) {
70
224607
  Type* self = data.GetParameter();
71
224607
  self->persistent().Reset();
72




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




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