UNPKG

3.87 kBtext/x-cView Raw
1/*********************************************************************
2 * NAN - Native Abstractions for Node.js
3 *
4 * Copyright (c) 2018 NAN contributors
5 *
6 * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
7 ********************************************************************/
8
9#ifndef NAN_PERSISTENT_12_INL_H_
10#define NAN_PERSISTENT_12_INL_H_
11
12template<typename T, typename M> class Persistent :
13 public v8::Persistent<T, M> {
14 public:
15 inline Persistent() : v8::Persistent<T, M>() {}
16
17 template<typename S> inline Persistent(v8::Local<S> that) :
18 v8::Persistent<T, M>(v8::Isolate::GetCurrent(), that) {}
19
20 template<typename S, typename M2>
21 inline
22 Persistent(const v8::Persistent<S, M2> &that) : // NOLINT(runtime/explicit)
23 v8::Persistent<T, M2>(v8::Isolate::GetCurrent(), that) {}
24
25 inline void Reset() { v8::PersistentBase<T>::Reset(); }
26
27 template <typename S>
28 inline void Reset(const v8::Local<S> &other) {
29 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
30 }
31
32 template <typename S>
33 inline void Reset(const v8::PersistentBase<S> &other) {
34 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
35 }
36
37 template<typename P>
38 inline void SetWeak(
39 P *parameter
40 , typename WeakCallbackInfo<P>::Callback callback
41 , WeakCallbackType type);
42
43 private:
44 inline T *operator*() const { return *PersistentBase<T>::persistent; }
45
46 template<typename S, typename M2>
47 inline void Copy(const Persistent<S, M2> &that) {
48 TYPE_CHECK(T, S);
49
50 this->Reset();
51
52 if (!that.IsEmpty()) {
53 this->Reset(that);
54 M::Copy(that, this);
55 }
56 }
57};
58
59#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
60 (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
61template<typename T>
62class Global : public v8::Global<T> {
63 public:
64 inline Global() : v8::Global<T>() {}
65
66 template<typename S> inline Global(v8::Local<S> that) :
67 v8::Global<T>(v8::Isolate::GetCurrent(), that) {}
68
69 template<typename S>
70 inline
71 Global(const v8::PersistentBase<S> &that) : // NOLINT(runtime/explicit)
72 v8::Global<S>(v8::Isolate::GetCurrent(), that) {}
73
74 inline void Reset() { v8::PersistentBase<T>::Reset(); }
75
76 template <typename S>
77 inline void Reset(const v8::Local<S> &other) {
78 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
79 }
80
81 template <typename S>
82 inline void Reset(const v8::PersistentBase<S> &other) {
83 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
84 }
85
86 template<typename P>
87 inline void SetWeak(
88 P *parameter
89 , typename WeakCallbackInfo<P>::Callback callback
90 , WeakCallbackType type) {
91 reinterpret_cast<Persistent<T>*>(this)->SetWeak(
92 parameter, callback, type);
93 }
94};
95#else
96template<typename T>
97class Global : public v8::UniquePersistent<T> {
98 public:
99 inline Global() : v8::UniquePersistent<T>() {}
100
101 template<typename S> inline Global(v8::Local<S> that) :
102 v8::UniquePersistent<T>(v8::Isolate::GetCurrent(), that) {}
103
104 template<typename S>
105 inline
106 Global(const v8::PersistentBase<S> &that) : // NOLINT(runtime/explicit)
107 v8::UniquePersistent<S>(v8::Isolate::GetCurrent(), that) {}
108
109 inline void Reset() { v8::PersistentBase<T>::Reset(); }
110
111 template <typename S>
112 inline void Reset(const v8::Local<S> &other) {
113 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
114 }
115
116 template <typename S>
117 inline void Reset(const v8::PersistentBase<S> &other) {
118 v8::PersistentBase<T>::Reset(v8::Isolate::GetCurrent(), other);
119 }
120
121 template<typename P>
122 inline void SetWeak(
123 P *parameter
124 , typename WeakCallbackInfo<P>::Callback callback
125 , WeakCallbackType type) {
126 reinterpret_cast<Persistent<T>*>(this)->SetWeak(
127 parameter, callback, type);
128 }
129};
130#endif
131
132#endif // NAN_PERSISTENT_12_INL_H_