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