5#ifndef INCLUDE_V8_LOCAL_HANDLE_H_
6#define INCLUDE_V8_LOCAL_HANDLE_H_
33class NonCopyablePersistentTraits;
36template <
class T,
class M = NonCopyablePersistentTraits<T>>
39class TracedReferenceBase;
41class BasicTracedReference;
47class EscapableHandleScope;
52template <
class F1,
class F2,
class F3>
67class ConsoleCallArguments;
78namespace api_internal {
106 static int NumberOfHandles(
Isolate* isolate);
109 return reinterpret_cast<Isolate*
>(i_isolate_);
116 internal::Address value);
121 void Initialize(
Isolate* isolate);
124 internal::Address value);
129 void*
operator new(
size_t size);
130 void*
operator new[](
size_t size);
131 void operator delete(
void*, size_t);
132 void operator delete[](
void*, size_t);
137#ifdef V8_ENABLE_CHECKS
138 int scope_level_ = 0;
142 template <
typename T>
157#ifdef V8_ENABLE_DIRECT_HANDLE
160class LocalBase :
public api_internal::DirectHandleBase {
169 template <
typename S>
205 template <
typename S>
262#ifdef V8_ENABLE_LOCAL_OFF_STACK_CHECK
280 requires std::is_base_of_v<T, S>
300 return internal::HandleHelper::EqualHandles(*
this, that);
305 return internal::HandleHelper::EqualHandles(*
this, that);
310 return !operator==(that);
315 return !operator==(that);
325#ifdef V8_ENABLE_CHECKS
328 if (that.IsEmpty())
return Local<T>();
329 T::Cast(that.template value<S>());
350 return New(isolate, that.template value<T, true>());
355 return New(isolate, that.template value<T, true>());
360 return New(isolate, that.template value<T, true>());
374 template <
class F,
class M>
394 template <
class F1,
class F2,
class F3>
405 explicit Local(no_checking_tag do_not_check)
406 :
LocalBase<T>(), StackAllocated(do_not_check) {}
408 :
LocalBase<T>(other), StackAllocated(do_not_check) {}
421#ifdef V8_ENABLE_DIRECT_HANDLE
452#if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
458 LocalUnchecked& operator=(
const LocalUnchecked&)
noexcept =
default;
466#ifdef V8_ENABLE_DIRECT_HANDLE
471class StrongRootAllocator<LocalUnchecked<T>> :
public StrongRootAllocatorBase {
473 using value_type = LocalUnchecked<T>;
474 static_assert(std::is_standard_layout_v<value_type>);
475 static_assert(
sizeof(value_type) ==
sizeof(Address));
477 template <
typename HeapOrIsolateT>
478 explicit StrongRootAllocator(HeapOrIsolateT* heap_or_isolate)
479 : StrongRootAllocatorBase(heap_or_isolate) {}
480 template <
typename U>
481 StrongRootAllocator(
const StrongRootAllocator<U>& other) noexcept
482 : StrongRootAllocatorBase(other) {}
484 value_type* allocate(
size_t n) {
485 return reinterpret_cast<value_type*
>(allocate_impl(n));
487 void deallocate(value_type* p,
size_t n)
noexcept {
488 return deallocate_impl(
reinterpret_cast<Address*
>(p), n);
499#ifdef V8_ENABLE_DIRECT_HANDLE
532 if (init.size() == 0)
return;
567 template <
typename InputIt>
586 template <
typename... Args>
596 return x.backing_ ==
y.backing_;
599 return x.backing_ !=
y.backing_;
602 return x.backing_ <
y.backing_;
605 return x.backing_ >
y.backing_;
608 return x.backing_ <=
y.backing_;
611 return x.backing_ >=
y.backing_;
618#if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
645 requires std::is_base_of_v<T, S>
651 requires std::is_base_of_v<T, S>
707 template <
typename S>
722 void*
operator new(
size_t size) =
delete;
723 void*
operator new[](
size_t size) =
delete;
724 void operator delete(
void*, size_t) =
delete;
725 void operator delete[](
void*, size_t) =
delete;
732 internal::Address* EscapeSlot(internal::Address* escape_value);
746#ifdef V8_ENABLE_DIRECT_HANDLE
749 if (value.IsEmpty())
return value;
756 return Escape(value.FromMaybe(
Local<T>()));
772 void*
operator new(
size_t size) =
delete;
773 void*
operator new[](
size_t size) =
delete;
774 void operator delete(
void*, size_t) =
delete;
775 void operator delete[](
void*, size_t) =
delete;
V8_INLINE ~EscapableHandleScopeBase()=default
internal::Address * escape_slot_
EscapableHandleScopeBase(const EscapableHandleScopeBase &)=delete
void operator=(const EscapableHandleScopeBase &)=delete
V8_INLINE ~EscapableHandleScope()=default
V8_INLINE MaybeLocal< T > EscapeMaybe(MaybeLocal< T > value)
V8_INLINE Local< T > Escape(Local< T > value)
EscapableHandleScope(Isolate *isolate)
V8_INLINE Isolate * GetIsolate() const
internal::Address * prev_next_
void operator=(const HandleScope &)=delete
HandleScope(const HandleScope &)=delete
internal::Isolate * i_isolate_
V8_INLINE HandleScope()=default
internal::Address * prev_limit_
static internal::Address * CreateHandleForCurrentIsolate(internal::Address value)
static internal::Address * CreateHandle(internal::Isolate *i_isolate, internal::Address value)
static V8_INLINE LocalBase< T > New(Isolate *isolate, T *that)
V8_INLINE LocalBase(internal::Address *location)
V8_INLINE LocalBase()=default
static V8_INLINE LocalBase< T > New(Isolate *isolate, internal::Address value)
static V8_INLINE LocalBase< T > FromSlot(internal::Address *slot)
static V8_INLINE LocalBase< T > FromRepr(internal::ValueHelper::InternalRepresentationType repr)
V8_INLINE LocalBase(const LocalBase< S > &other)
LocalVector< T > & operator=(std::initializer_list< Local< T > > init)
const Local< T > & front() const
friend bool operator>=(const LocalVector< T > &x, const LocalVector< T > &y)
std::vector< element_type, allocator_type > vector_type
bool empty() const noexcept
const Local< T > * data() const noexcept
const_iterator end() const noexcept
const Local< T > & operator[](size_t n) const
friend bool operator<(const LocalVector< T > &x, const LocalVector< T > &y)
const Local< T > & back() const
Local< T > * data() noexcept
friend bool operator<=(const LocalVector< T > &x, const LocalVector< T > &y)
friend bool operator!=(const LocalVector< T > &x, const LocalVector< T > &y)
Local< T > & operator[](size_t n)
void emplace_back(Args &&... args)
const_iterator begin() const noexcept
static allocator_type make_allocator(Isolate *isolate) noexcept
iterator insert(const_iterator pos, std::initializer_list< Local< T > > init)
Local< T > & at(size_t n)
ptrdiff_t difference_type
iterator insert(const_iterator pos, const Local< T > &value)
LocalVector(Isolate *isolate, std::initializer_list< Local< T > > init)
std::allocator< element_type > allocator_type
const Local< T > & at(size_t n) const
internal::WrappedIterator< typename vector_type::const_iterator, const Local< T > > const_iterator
void swap(LocalVector< T > &other)
iterator insert(const_iterator pos, InputIt first, InputIt last)
friend bool operator==(const LocalVector< T > &x, const LocalVector< T > &y)
LocalVector(Isolate *isolate)
size_t size() const noexcept
LocalVector(Isolate *isolate, size_t n)
void push_back(const Local< T > &x)
internal::WrappedIterator< typename vector_type::iterator, Local< T > > iterator
iterator begin() noexcept
friend bool operator>(const LocalVector< T > &x, const LocalVector< T > &y)
friend class TracedReferenceBase
friend class PersistentValueMapBase
V8_INLINE bool operator==(const Local< S > &that) const
V8_INLINE Local(const LocalBase< T > &other)
V8_INLINE Local< S > As() const
V8_INLINE T * operator->() const
V8_INLINE bool operator!=(const Local< S > &that) const
static V8_INLINE Local< T > New(Isolate *isolate, const PersistentBase< T > &that)
Local(no_checking_tag do_not_check)
Local(const Local< T > &other, no_checking_tag do_not_check)
static V8_INLINE Local< T > Cast(Local< S > that)
friend class PropertyCallbackInfo
V8_INLINE T * operator*() const
friend class FunctionCallbackInfo
static V8_INLINE Local< T > New(Isolate *isolate, T *that)
V8_INLINE bool operator!=(const Persistent< S > &that) const
V8_INLINE Local(Local< S > that)
static V8_INLINE Local< T > New(Isolate *isolate, internal::Address value)
V8_INLINE Local()=default
static V8_INLINE Local< T > New(Isolate *isolate, const BasicTracedReference< T > &that)
V8_INLINE bool operator==(const PersistentBase< S > &that) const
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
friend class EscapableHandleScope
V8_INLINE Local< S > UnsafeAs() const
static V8_INLINE Local< T > FromRepr(internal::ValueHelper::InternalRepresentationType repr)
friend class InternalEscapableScope
static V8_INLINE Local< T > FromSlot(internal::Address *slot)
V8_INLINE MaybeLocal< S > As() const
V8_INLINE MaybeLocal(MaybeLocal< S > that)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
V8_INLINE Local< T > ToLocalChecked()
V8_INLINE bool IsEmpty() const
static V8_INLINE MaybeLocal< T > Cast(MaybeLocal< S > that)
V8_INLINE MaybeLocal(Local< S > that)
V8_INLINE MaybeLocal()=default
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
SealHandleScope(const SealHandleScope &)=delete
void operator=(const SealHandleScope &)=delete
internal::Isolate *const i_isolate_
internal::Address * prev_limit_
V8_INLINE internal::Address ptr() const
V8_INLINE internal::ValueHelper::InternalRepresentationType repr() const
V8_INLINE IndirectHandleBase()=default
V8_INLINE internal::Address *const & slot() const
LocalUnchecked(const Local< T > &other) noexcept
static V8_INLINE Address ValueAsAddress(const T *value)
internal::Address * InternalRepresentationType
static V8_INLINE bool IsEmpty(T *value)
base::Vector< const DirectHandle< Object > > args
internal::BasicPersistent< T, internal::StrongPersistentPolicy > Persistent
#define V8_WARN_UNUSED_RESULT
#define V8_UNLIKELY(condition)
std::unique_ptr< ValueMirror > value