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 {
65 static_assert(std::is_base_of<T, S>::value,
"type check");
71namespace api_internal {
149 template <
typename P>
161 template <
typename P>
197 template <
class F1,
class F2>
205 template <
class F1,
class F2,
class F3>
207 template <
class F1,
class F2>
231 template <
class S,
class M>
234 static_assert(
sizeof(S) < 0,
235 "NonCopyablePersistentTraits::Copy is not instantiable");
244struct V8_DEPRECATED(
"Use v8::Global instead") CopyablePersistentTraits {
245 using CopyablePersistent = Persistent<T, CopyablePersistentTraits<T>>;
246 static const bool kResetInDestructor =
true;
247 template <
class S,
class M>
248 static V8_INLINE void Copy(
const Persistent<S, M>& source,
249 CopyablePersistent* dest) {
264template <
class T,
class M>
281 static_assert(std::is_base_of<T, S>::value,
"type check");
289 template <
class S,
class M2>
293 static_assert(std::is_base_of<T, S>::value,
"type check");
305 template <
class S,
class M2>
313 template <
class S,
class M2>
325 if (M::kResetInDestructor) this->
Reset();
329 template <
class S,
class M2>
331#ifdef V8_ENABLE_CHECKS
334 if (!that.
IsEmpty()) T::Cast(that.template value<S>());
341 template <
class S,
class M2>
351 template <
class F1,
class F2>
356 template <
class S,
class M2>
382 static_assert(std::is_base_of<T, S>::value,
"type check");
394 static_assert(std::is_base_of<T, S>::value,
"type check");
439 uint16_t class_id) {}
446 reinterpret_cast<internal::Isolate*
>(isolate),
450template <
class T,
class M>
451template <
class S,
class M2>
453 static_assert(std::is_base_of<T, S>::value,
"type check");
463 if (this->IsEmpty())
return false;
464 return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
469 if (this->IsEmpty())
return;
481 static_assert(std::is_base_of<T, S>::value,
"type check");
484 this->slot() = New(isolate, *other);
495 static_assert(std::is_base_of<T, S>::value,
"type check");
498 this->slot() = New(isolate, other.template value<S>());
507#if (__GNUC__ >= 8) && !defined(__clang__)
508#pragma GCC diagnostic push
509#pragma GCC diagnostic ignored "-Wcast-function-type"
512 reinterpret_cast<Callback
>(callback), type);
513#if (__GNUC__ >= 8) && !defined(__clang__)
514#pragma GCC diagnostic pop
537 if (this->IsEmpty())
return;
538 uint8_t* addr =
reinterpret_cast<uint8_t*
>(slot()) + I::kNodeClassIdOffset;
539 *
reinterpret_cast<uint16_t*
>(addr) = class_id;
545 if (this->IsEmpty())
return 0;
546 uint8_t* addr =
reinterpret_cast<uint8_t*
>(slot()) + I::kNodeClassIdOffset;
547 return *
reinterpret_cast<uint16_t*
>(addr);
552 if (!other.IsEmpty()) {
561 static_assert(std::is_base_of<T, S>::value,
"type check");
564 if (!rhs.IsEmpty()) {
565 this->slot() = rhs.slot();
V8_INLINE Eternal()=default
V8_INLINE Eternal(Isolate *isolate, Local< S > handle)
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()=default
V8_INLINE Global & operator=(Global< S > &&rhs)
Global(const Global &)=delete
void operator=(const Global &)=delete
void MoveOnlyTypeForCPP03
V8_INLINE Global(Global &&other)
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 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()=default
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
static V8_INLINE Persistent< T, M > & Cast(const Persistent< S, M2 > &that)
V8_INLINE Persistent(const Persistent< S, M2 > &that)
V8_INLINE Persistent< S, M2 > & As() const
V8_INLINE Persistent(const Persistent &that)
V8_INLINE Persistent & operator=(const Persistent &that)
V8_INLINE Persistent & operator=(const Persistent< S, M2 > &that)
void(*)(const WeakCallbackInfo< T > &data) Callback
V8_INLINE T * value() const
V8_INLINE bool IsEmpty() const
V8_INLINE IndirectHandleBase()=default
V8_INLINE internal::Address *const & slot() const
static V8_INLINE bool EqualHandles(const T1 &lhs, const T2 &rhs)
static V8_INLINE Address ValueAsAddress(const T *value)
static V8_INLINE bool IsEmpty(T *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 void MoveGlobalReference(internal::Address **from, internal::Address **to)
V8_EXPORT internal::Address * Eternalize(v8::Isolate *isolate, Value *handle)
V8_EXPORT internal::Address * GlobalizeReference(internal::Isolate *isolate, internal::Address value)
V8_EXPORT void AnnotateStrongRetainer(internal::Address *location, const char *label)
#define V8_DEPRECATED(message)