GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_persistent.h Lines: 8 8 100.0 %
Date: 2019-02-13 22:28:58 Branches: 2 6 33.3 %

Line Branch Exec Source
1
#ifndef SRC_NODE_PERSISTENT_H_
2
#define SRC_NODE_PERSISTENT_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "v8.h"
7
8
namespace node {
9
10
template <typename T>
11
struct ResetInDestructorPersistentTraits {
12
  static const bool kResetInDestructor = true;
13
  template <typename S, typename M>
14
  // Disallow copy semantics by leaving this unimplemented.
15
  inline static void Copy(
16
      const v8::Persistent<S, M>&,
17
      v8::Persistent<T, ResetInDestructorPersistentTraits<T>>*);
18
};
19
20
// v8::Persistent does not reset the object slot in its destructor.  That is
21
// acknowledged as a flaw in the V8 API and expected to change in the future
22
// but for now node::Persistent is the easier and safer alternative.
23
template <typename T>
24
using Persistent = v8::Persistent<T, ResetInDestructorPersistentTraits<T>>;
25
26
class PersistentToLocal {
27
 public:
28
  // If persistent.IsWeak() == false, then do not call persistent.Reset()
29
  // while the returned Local<T> is still in scope, it will destroy the
30
  // reference to the object.
31
  template <class TypeName>
32
39181587
  static inline v8::Local<TypeName> Default(
33
      v8::Isolate* isolate,
34
      const Persistent<TypeName>& persistent) {
35

78363174
    if (persistent.IsWeak()) {
36
35714848
      return PersistentToLocal::Weak(isolate, persistent);
37
    } else {
38
3466739
      return PersistentToLocal::Strong(persistent);
39
    }
40
  }
41
42
  // Unchecked conversion from a non-weak Persistent<T> to Local<T>,
43
  // use with care!
44
  //
45
  // Do not call persistent.Reset() while the returned Local<T> is still in
46
  // scope, it will destroy the reference to the object.
47
  template <class TypeName>
48
30933662
  static inline v8::Local<TypeName> Strong(
49
      const Persistent<TypeName>& persistent) {
50
    return *reinterpret_cast<v8::Local<TypeName>*>(
51
30933662
        const_cast<Persistent<TypeName>*>(&persistent));
52
  }
53
54
  template <class TypeName>
55
35714848
  static inline v8::Local<TypeName> Weak(
56
      v8::Isolate* isolate,
57
      const Persistent<TypeName>& persistent) {
58
71429696
    return v8::Local<TypeName>::New(isolate, persistent);
59
  }
60
};
61
62
}  // namespace node
63
64
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
65
66
#endif  // SRC_NODE_PERSISTENT_H_