nan_persistent_12_inl.h 3.8 KB

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