5#ifndef INCLUDE_V8_PERSISTENT_HANDLE_H_
6#define INCLUDE_V8_PERSISTENT_HANDLE_H_
16template <
class K,
class V,
class T>
17class PersistentValueMapBase;
22template <
class K,
class V,
class T>
23class PersistentValueMap;
26namespace api_internal {
53 requires(std::is_base_of_v<T, S>)
66 requires(std::is_base_of_v<T, S>)
73namespace api_internal {
151 template <
typename P>
163 template <
typename P>
199 template <
class F1,
class F2>
207 template <
class F1,
class F2,
class F3>
231 template <
class S,
class M>
234 static_assert(
sizeof(S) < 0,
235 "NonCopyablePersistentTraits::Copy is not instantiable");
249template <
class T,
class M>
263 requires(std::is_base_of_v<T, S>)
273 template <
class S,
class M2>
274 requires(std::is_base_of_v<T, S>)
288 template <
class S,
class M2>
296 template <
class S,
class M2>
308 if (M::kResetInDestructor) this->
Reset();
312 template <
class S,
class M2>
314#ifdef V8_ENABLE_CHECKS
317 if (!that.IsEmpty()) T::Cast(that.template value<S>());
324 template <
class S,
class M2>
334 template <
class F1,
class F2>
339 template <
class S,
class M2>
362 requires(std::is_base_of_v<T, S>)
373 requires(std::is_base_of_v<T, S>)
420 uint16_t class_id) {}
431template <
class T,
class M>
432template <
class S,
class M2>
434 static_assert(std::is_base_of<T, S>::value,
"type check");
436 if (that.IsEmpty())
return;
444 if (this->IsEmpty())
return false;
445 return I::GetNodeState(this->slot()) == I::kNodeStateIsWeakValue;
450 if (this->IsEmpty())
return;
462 static_assert(std::is_base_of<T, S>::value,
"type check");
464 if (other.IsEmpty())
return;
465 this->slot() = New(isolate, *other);
476 static_assert(std::is_base_of<T, S>::value,
"type check");
478 if (other.IsEmpty())
return;
479 this->slot() = New(isolate, other.template value<S>());
488#if (__GNUC__ >= 8) && !defined(__clang__)
489#pragma GCC diagnostic push
490#pragma GCC diagnostic ignored "-Wcast-function-type"
493 reinterpret_cast<Callback
>(
callback), type);
494#if (__GNUC__ >= 8) && !defined(__clang__)
495#pragma GCC diagnostic pop
518 if (this->IsEmpty())
return;
519 uint8_t* addr =
reinterpret_cast<uint8_t*
>(slot()) + I::kNodeClassIdOffset;
520 *
reinterpret_cast<uint16_t*
>(addr) = class_id;
526 if (this->IsEmpty())
return 0;
527 uint8_t* addr =
reinterpret_cast<uint8_t*
>(slot()) + I::kNodeClassIdOffset;
528 return *
reinterpret_cast<uint16_t*
>(addr);
533 if (!other.IsEmpty()) {
534 api_internal::MoveGlobalReference(&other.slot(), &this->slot());
542 static_assert(std::is_base_of<T, S>::value,
"type check");
545 if (!rhs.IsEmpty()) {
546 this->slot() = rhs.slot();
V8_INLINE Eternal(Isolate *isolate, Local< S > handle)
V8_INLINE Local< T > Get(Isolate *isolate) const
V8_INLINE Eternal()=default
void Set(Isolate *isolate, Local< S > handle)
V8_INLINE Global()=default
void MoveOnlyTypeForCPP03
V8_INLINE Global(Isolate *isolate, Local< S > that)
void operator=(const Global &)=delete
V8_INLINE Global(Isolate *isolate, const PersistentBase< S > &that)
V8_INLINE Global(Global &&other)
V8_INLINE Global & operator=(Global< S > &&rhs)
Global(const Global &)=delete
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
static V8_INLINE Local< T > FromSlot(internal::Address *slot)
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)
V8_INLINE void ClearWeak()
V8_INLINE void AnnotateStrongRetainer(const char *label)
V8_INLINE bool operator!=(const PersistentBase< S > &that) const
V8_INLINE bool operator==(const PersistentBase< S > &that) const
V8_INLINE Local< T > Get(Isolate *isolate) const
V8_INLINE bool IsWeak() const
V8_INLINE bool operator==(const Local< S > &that) const
V8_INLINE bool operator!=(const Local< S > &that) const
static V8_INLINE internal::Address * New(Isolate *isolate, T *that)
V8_INLINE PersistentBase()=default
V8_INLINE P * ClearWeak()
PersistentBase(const PersistentBase &other)=delete
friend class PersistentBase
V8_INLINE void SetWrapperClassId(uint16_t class_id)
V8_INLINE uint16_t WrapperClassId() const
void operator=(const PersistentBase &)=delete
V8_INLINE PersistentBase(internal::Address *location)
V8_INLINE void SetWeak(P *parameter, typename WeakCallbackInfo< P >::Callback callback, WeakCallbackType type)
V8_INLINE void Reset(Isolate *isolate, const PersistentBase< S > &other)
virtual void VisitPersistentHandle(Persistent< Value > *value, uint16_t class_id)
virtual ~PersistentHandleVisitor()=default
V8_INLINE Persistent(const Persistent &that)
V8_INLINE void Copy(const Persistent< S, M2 > &that)
static V8_INLINE Persistent< T, M > & Cast(const Persistent< S, M2 > &that)
V8_INLINE Persistent(Isolate *isolate, const Persistent< S, M2 > &that)
V8_INLINE Persistent & operator=(const Persistent &that)
V8_INLINE Persistent< S, M2 > & As() const
V8_INLINE Persistent(Isolate *isolate, Local< S > that)
V8_INLINE Persistent & operator=(const Persistent< S, M2 > &that)
V8_INLINE Persistent()=default
V8_INLINE Persistent(const Persistent< S, M2 > &that)
void(*)(const WeakCallbackInfo< T > &data) Callback
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)
void * ClearWeak(i::Address *location)
void AnnotateStrongRetainer(i::Address *location, const char *label)
void MoveGlobalReference(internal::Address **from, internal::Address **to)
i::Address * GlobalizeReference(i::Isolate *i_isolate, i::Address value)
void MakeWeak(i::Address *location, void *parameter, WeakCallbackInfo< void >::Callback weak_callback, WeakCallbackType type)
i::Address * Eternalize(Isolate *v8_isolate, Value *value)
i::Address * CopyGlobalReference(i::Address *from)
void DisposeGlobal(i::Address *location)
#define P(name, number_of_args, result_size)
#define I(name, number_of_args, result_size)