5#ifndef INCLUDE_V8_PERSISTENT_HANDLE_H_
6#define INCLUDE_V8_PERSISTENT_HANDLE_H_
16template <
class K,
class V,
class T>
17class PersistentValueMapBase;
18template <
class V,
class T>
19class PersistentValueVector;
24template <
class K,
class V,
class T>
25class PersistentValueMap;
28namespace api_internal {
65 static_assert(std::is_base_of<T, S>::value,
"type check");
66 val_ =
reinterpret_cast<T*
>(
74namespace api_internal {
127 if (a ==
nullptr)
return b ==
nullptr;
128 if (b ==
nullptr)
return false;
136 if (a ==
nullptr)
return b ==
nullptr;
137 if (b ==
nullptr)
return false;
163 template <
typename P>
177 template <
typename P>
213 template <
class F1,
class F2>
221 template <
class F1,
class F2,
class F3>
223 template <
class F1,
class F2>
244 template <
class S,
class M>
247 static_assert(
sizeof(S) < 0,
248 "NonCopyablePersistentTraits::Copy is not instantiable");
260 template <
class S,
class M>
275template <
class T,
class M>
290 static_assert(std::is_base_of<T, S>::value,
"type check");
297 template <
class S,
class M2>
300 static_assert(std::is_base_of<T, S>::value,
"type check");
311 template <
class S,
class M2>
319 template <
class S,
class M2>
330 if (M::kResetInDestructor) this->
Reset();
336#ifdef V8_ENABLE_CHECKS
339 if (!that.
IsEmpty()) T::Cast(*that);
355 template <
class F1,
class F2>
361 V8_INLINE T* operator*()
const {
return this->val_; }
362 template <
class S,
class M2>
363 V8_INLINE void Copy(
const Persistent<S, M2>& that);
387 static_assert(std::is_base_of<T, S>::value,
"type check");
398 static_assert(std::is_base_of<T, S>::value,
"type check");
430 V8_INLINE T* operator*()
const {
return this->val_; }
444 uint16_t class_id) {}
448T* PersistentBase<T>::New(Isolate* isolate, T* that) {
449 if (that ==
nullptr)
return nullptr;
452 reinterpret_cast<internal::Isolate*
>(isolate), p));
455template <
class T,
class M>
456template <
class S,
class M2>
458 static_assert(std::is_base_of<T, S>::value,
"type check");
469 if (this->IsEmpty())
return false;
471 I::kNodeStateIsWeakValue;
476 if (this->IsEmpty())
return;
488 static_assert(std::is_base_of<T, S>::value,
"type check");
491 this->val_ = New(isolate, other.val_);
502 static_assert(std::is_base_of<T, S>::value,
"type check");
505 this->val_ = New(isolate, other.val_);
514#if (__GNUC__ >= 8) && !defined(__clang__)
515#pragma GCC diagnostic push
516#pragma GCC diagnostic ignored "-Wcast-function-type"
519 parameter,
reinterpret_cast<Callback
>(callback), type);
520#if (__GNUC__ >= 8) && !defined(__clang__)
521#pragma GCC diagnostic pop
546 if (this->IsEmpty())
return;
548 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
549 *
reinterpret_cast<uint16_t*
>(addr) = class_id;
555 if (this->IsEmpty())
return 0;
557 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
558 return *
reinterpret_cast<uint16_t*
>(addr);
563 if (other.val_ !=
nullptr) {
567 other.val_ =
nullptr;
574 static_assert(std::is_base_of<T, S>::value,
"type check");
577 if (rhs.val_ !=
nullptr) {
578 this->val_ = rhs.val_;
V8_INLINE Eternal(Isolate *isolate, Local< S > handle)
V8_INLINE bool IsEmpty() const
void Set(Isolate *isolate, Local< S > handle)
V8_INLINE Local< T > Get(Isolate *isolate) const
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
V8_INLINE Global(Isolate *isolate, Local< S > that)
V8_INLINE Global & operator=(Global< S > &&rhs)
Global(const Global &)=delete
void operator=(const Global &)=delete
void MoveOnlyTypeForCPP03
V8_INLINE bool IsEmpty() const
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
static V8_INLINE void Copy(const Persistent< S, M > &source, NonCopyablePersistent *dest)
static const bool kResetInDestructor
V8_INLINE void Reset(Isolate *isolate, const Local< S > &other)
void operator=(const PersistentBase &)=delete
V8_INLINE uint16_t WrapperClassId() const
V8_INLINE bool IsWeak() const
V8_INLINE bool operator!=(const Local< S > &that) const
V8_INLINE bool IsEmpty() const
V8_INLINE bool operator==(const Local< S > &that) const
V8_INLINE P * ClearWeak()
V8_INLINE bool operator!=(const PersistentBase< S > &that) const
PersistentBase(const PersistentBase &other)=delete
V8_INLINE void AnnotateStrongRetainer(const char *label)
V8_INLINE bool operator==(const PersistentBase< S > &that) const
V8_INLINE void Reset(Isolate *isolate, const PersistentBase< S > &other)
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackInfo< P >::Callback callback, WeakCallbackType type)
V8_INLINE void ClearWeak()
V8_INLINE Local< T > Get(Isolate *isolate) const
friend class PersistentBase
V8_INLINE void SetWrapperClassId(uint16_t class_id)
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
virtual ~PersistentHandleVisitor()=default
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
V8_INLINE Persistent< S > & As() const
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
V8_INLINE Persistent(const Persistent< S, M2 > &that)
V8_INLINE Persistent(const Persistent &that)
V8_INLINE Persistent & operator=(const Persistent &that)
V8_INLINE Persistent & operator=(const Persistent< S, M2 > &that)
static V8_INLINE Persistent< T > & Cast(const Persistent< S > &that)
void(*)(const WeakCallbackInfo< T > &data) Callback
V8_EXPORT void MakeWeak(internal::Address **location_addr)
V8_EXPORT void DisposeGlobal(internal::Address *global_handle)
V8_EXPORT void * ClearWeak(internal::Address *location)
V8_EXPORT internal::Address * CopyGlobalReference(internal::Address *from)
V8_EXPORT internal::Address * GlobalizeReference(internal::Isolate *isolate, internal::Address *handle)
V8_EXPORT Value * Eternalize(v8::Isolate *isolate, Value *handle)
V8_EXPORT void MoveGlobalReference(internal::Address **from, internal::Address **to)
V8_EXPORT void AnnotateStrongRetainer(internal::Address *location, const char *label)
static V8_INLINE void Copy(const Persistent< S, M > &source, CopyablePersistent *dest)
static const bool kResetInDestructor