5#ifndef INCLUDE_V8_PERSISTENT_HANDLE_H_
6#define INCLUDE_V8_PERSISTENT_HANDLE_H_
16template <
class K,
class V,
class T>
18template <
class V,
class T>
24template <
class K,
class V,
class T>
28namespace api_internal {
58 return Local<T>(internal::ValueHelper::SlotAsValue<T>(val_));
65 static_assert(std::is_base_of<T, S>::value,
"type check");
66 val_ =
reinterpret_cast<T*
>(
78namespace api_internal {
159 template <
typename P>
171 template <
typename P>
207 template <
class F1,
class F2>
215 template <
class F1,
class F2,
class F3>
217 template <
class F1,
class F2>
223 V8_INLINE T* operator*()
const {
return this->val_; }
245 template <
class S,
class M>
248 static_assert(
sizeof(S) < 0,
249 "NonCopyablePersistentTraits::Copy is not instantiable");
258struct V8_DEPRECATED(
"Use v8::Global instead") CopyablePersistentTraits {
259 using CopyablePersistent = Persistent<T, CopyablePersistentTraits<T>>;
260 static const bool kResetInDestructor =
true;
261 template <
class S,
class M>
262 static V8_INLINE void Copy(
const Persistent<S, M>& source,
263 CopyablePersistent* dest) {
276template <
class T,
class M>
292 static_assert(std::is_base_of<T, S>::value,
"type check");
300 template <
class S,
class M2>
303 static_assert(std::is_base_of<T, S>::value,
"type check");
314 template <
class S,
class M2>
322 template <
class S,
class M2>
333 if (M::kResetInDestructor) this->
Reset();
339#ifdef V8_ENABLE_CHECKS
342 if (!that.
IsEmpty()) T::Cast(*that);
358 template <
class F1,
class F2>
364 template <
class S,
class M2>
389 static_assert(std::is_base_of<T, S>::value,
"type check");
400 static_assert(std::is_base_of<T, S>::value,
"type check");
445 uint16_t class_id) {}
449T* PersistentBase<T>::New(Isolate* isolate, Local<T> that) {
450 return PersistentBase<T>::New(isolate,
455T* PersistentBase<T>::New(Isolate* isolate, T* that) {
456 if (that ==
nullptr)
return nullptr;
459 reinterpret_cast<internal::Isolate*
>(isolate), p));
462template <
class T,
class M>
463template <
class S,
class M2>
465 static_assert(std::is_base_of<T, S>::value,
"type check");
476 if (this->IsEmpty())
return false;
478 I::kNodeStateIsWeakValue;
483 if (this->IsEmpty())
return;
495 static_assert(std::is_base_of<T, S>::value,
"type check");
509 static_assert(std::is_base_of<T, S>::value,
"type check");
512 this->val_ = New(isolate, other.val_);
521#if (__GNUC__ >= 8) && !defined(__clang__)
522#pragma GCC diagnostic push
523#pragma GCC diagnostic ignored "-Wcast-function-type"
526 parameter,
reinterpret_cast<Callback
>(callback), type);
527#if (__GNUC__ >= 8) && !defined(__clang__)
528#pragma GCC diagnostic pop
553 if (this->IsEmpty())
return;
555 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
556 *
reinterpret_cast<uint16_t*
>(addr) = class_id;
562 if (this->IsEmpty())
return 0;
564 uint8_t* addr =
reinterpret_cast<uint8_t*
>(obj) + I::kNodeClassIdOffset;
565 return *
reinterpret_cast<uint16_t*
>(addr);
570 if (other.val_ !=
nullptr) {
574 other.val_ =
nullptr;
581 static_assert(std::is_base_of<T, S>::value,
"type check");
584 if (rhs.val_ !=
nullptr) {
585 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 Global(Global &&other)
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
static V8_INLINE bool EqualHandles(const T1 &lhs, const T2 &rhs)
static V8_INLINE T * ValueAsSlot(T *const &value)
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)
#define V8_DEPRECATED(message)