5#ifndef INCLUDE_V8_LOCAL_HANDLE_H_
6#define INCLUDE_V8_LOCAL_HANDLE_H_
36template <
class T,
class M = NonCopyablePersistentTraits<T>>
52template <
class F1,
class F2,
class F3>
67class ConsoleCallArguments;
75class SamplingHeapProfiler;
109 return reinterpret_cast<Isolate*
>(i_isolate_);
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);
134 internal::Isolate* i_isolate_;
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>
210 reinterpret_cast<internal::Isolate*
>(isolate),
value));
262#ifdef V8_ENABLE_LOCAL_OFF_STACK_CHECK
280 requires std::is_base_of_v<T, S>
325#ifdef V8_ENABLE_CHECKS
374 template <
class F,
class M>
394 template <
class F1,
class F2,
class F3>
400 friend class internal::SamplingHeapProfiler;
402 friend class debug::ConsoleCallArguments;
407 explicit Local(
const Local<T>& other, no_checking_tag do_not_check)
408 :
LocalBase<T>(other), StackAllocated(do_not_check) {}
410 V8_INLINE explicit Local(
const LocalBase<T>& other) : LocalBase<T>(other) {}
413 internal::ValueHelper::InternalRepresentationType repr) {
414 return Local<T>(LocalBase<T>::FromRepr(repr));
417 V8_INLINE static Local<T> FromSlot(internal::Address* slot) {
418 return Local<T>(LocalBase<T>::FromSlot(slot));
421#ifdef V8_ENABLE_DIRECT_HANDLE
422 friend class TypecheckWitness;
424 V8_INLINE static Local<T> FromAddress(internal::Address ptr) {
425 return Local<T>(LocalBase<T>(ptr));
429 V8_INLINE static Local<T> New(Isolate* isolate, internal::Address value) {
430 return Local<T>(LocalBase<T>::New(isolate, value));
433 V8_INLINE static Local<T> New(Isolate* isolate, T* that) {
434 return Local<T>(LocalBase<T>::New(isolate, that));
440 return Local<S>(LocalBase<S>(*
this));
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
502 static allocator_type make_allocator(
Isolate* isolate)
noexcept {
503 return allocator_type(isolate);
506 using allocator_type = std::allocator<element_type>;
508 static allocator_type make_allocator(
Isolate* isolate)
noexcept {
509 return allocator_type();
513 using vector_type = std::vector<element_type, allocator_type>;
529 : backing_(n, make_allocator(isolate)) {}
531 : backing_(make_allocator(isolate)) {
532 if (init.size() == 0)
return;
533 backing_.reserve(init.size());
534 backing_.insert(backing_.end(), init.begin(), init.end());
544 size_t size() const noexcept {
return backing_.size(); }
545 bool empty() const noexcept {
return backing_.empty(); }
546 void reserve(
size_t n) { backing_.reserve(n); }
553 const Local<T>&
at(
size_t n)
const {
return backing_.at(n); }
567 template <
typename InputIt>
569 return iterator(backing_.insert(pos.
base(), first, last));
573 return iterator(backing_.insert(pos.
base(), init.begin(), init.end()));
578 backing_.reserve(init.size());
579 backing_.insert(backing_.end(), init.begin(), init.end());
586 template <
typename... Args>
588 backing_.push_back(
value_type{std::forward<Args>(args)...});
591 void clear() noexcept { backing_.clear(); }
592 void resize(
size_t n) { backing_.resize(n); }
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_;
615 vector_type 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;
746#ifdef V8_ENABLE_DIRECT_HANDLE
749 if (value.
IsEmpty())
return value;
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;
778 internal::Isolate*
const i_isolate_;
780 int prev_sealed_level_;
EscapableHandleScopeBase(const EscapableHandleScopeBase &)=delete
internal::Address * EscapeSlot(internal::Address *escape_value)
EscapableHandleScopeBase(Isolate *isolate)
void operator=(const EscapableHandleScopeBase &)=delete
V8_INLINE ~EscapableHandleScopeBase()=default
V8_INLINE Local< T > Escape(Local< T > value)
EscapableHandleScope(Isolate *isolate)
V8_INLINE MaybeLocal< T > EscapeMaybe(MaybeLocal< T > value)
V8_INLINE ~EscapableHandleScope()=default
void Initialize(Isolate *isolate)
V8_INLINE HandleScope()=default
static int NumberOfHandles(Isolate *isolate)
V8_INLINE Isolate * GetIsolate() const
HandleScope(const HandleScope &)=delete
static internal::Address * CreateHandleForCurrentIsolate(internal::Address value)
HandleScope(Isolate *isolate)
void operator=(const HandleScope &)=delete
static internal::Address * CreateHandle(internal::Isolate *i_isolate, internal::Address value)
V8_INLINE LocalBase(internal::Address *location)
V8_INLINE LocalBase(const LocalBase< S > &other)
V8_INLINE LocalBase()=default
static V8_INLINE LocalBase< T > FromRepr(internal::ValueHelper::InternalRepresentationType repr)
static V8_INLINE LocalBase< T > New(Isolate *isolate, T *that)
static V8_INLINE LocalBase< T > New(Isolate *isolate, internal::Address value)
static V8_INLINE LocalBase< T > FromSlot(internal::Address *slot)
friend Local< Primitive > Null(Isolate *isolate)
friend class TracedReferenceBase
friend class PersistentValueMapBase
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)
static V8_INLINE Local< T > Cast(Local< S > that)
V8_INLINE bool operator==(const Local< S > &that) const
friend class PropertyCallbackInfo
friend Local< Boolean > False(Isolate *isolate)
friend Local< Primitive > Undefined(Isolate *isolate)
static V8_INLINE Local< T > New(Isolate *isolate, const BasicTracedReference< T > &that)
friend class FunctionCallbackInfo
V8_INLINE Local< S > As() const
V8_INLINE bool operator==(const PersistentBase< S > &that) const
V8_INLINE Local(Local< S > that)
friend Local< Boolean > True(Isolate *isolate)
static V8_INLINE Local< T > New(Isolate *isolate, Local< T > that)
V8_INLINE T * operator*() const
V8_INLINE bool operator!=(const Persistent< S > &that) const
V8_INLINE Local()=default
friend class EscapableHandleScope
friend class InternalEscapableScope
friend bool operator>=(const LocalVector< T > &x, const LocalVector< T > &y)
internal::WrappedIterator< typename vector_type::iterator, Local< T > > iterator
const_iterator begin() const noexcept
friend bool operator<(const LocalVector< T > &x, const LocalVector< T > &y)
size_t size() const noexcept
friend bool operator<=(const LocalVector< T > &x, const LocalVector< T > &y)
bool empty() const noexcept
LocalVector(Isolate *isolate, std::initializer_list< Local< T > > init)
const Local< T > * data() const noexcept
internal::WrappedIterator< typename vector_type::const_iterator, const Local< T > > const_iterator
friend bool operator!=(const LocalVector< T > &x, const LocalVector< T > &y)
iterator insert(const_iterator pos, std::initializer_list< Local< T > > init)
const_iterator end() const noexcept
LocalVector(Isolate *isolate, size_t n)
const Local< T > & back() const
Local< T > * data() noexcept
void swap(LocalVector< T > &other)
LocalVector(Isolate *isolate)
iterator begin() noexcept
iterator insert(const_iterator pos, const Local< T > &value)
LocalVector< T > & operator=(std::initializer_list< Local< T > > init)
Local< T > & operator[](size_t n)
const value_type & const_reference
const Local< T > & operator[](size_t n) const
iterator insert(const_iterator pos, InputIt first, InputIt last)
void emplace_back(Args &&... args)
friend bool operator==(const LocalVector< T > &x, const LocalVector< T > &y)
const Local< T > & front() const
void push_back(const Local< T > &x)
const Local< T > & at(size_t n) const
Local< T > & at(size_t n)
ptrdiff_t difference_type
friend bool operator>(const LocalVector< T > &x, const LocalVector< T > &y)
V8_INLINE Local< T > ToLocalChecked()
V8_INLINE MaybeLocal()=default
V8_INLINE bool IsEmpty() const
V8_INLINE MaybeLocal(MaybeLocal< S > that)
V8_INLINE MaybeLocal(Local< S > that)
static V8_INLINE MaybeLocal< T > Cast(MaybeLocal< S > that)
V8_INLINE MaybeLocal< S > As() const
V8_INLINE Local< S > FromMaybe(Local< S > default_value) const
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
void operator=(const SealHandleScope &)=delete
SealHandleScope(Isolate *isolate)
SealHandleScope(const SealHandleScope &)=delete
V8_INLINE internal::Address ptr() const
V8_INLINE internal::ValueHelper::InternalRepresentationType repr() const
V8_INLINE T * value() const
V8_INLINE bool IsEmpty() const
V8_INLINE IndirectHandleBase()=default
V8_INLINE internal::Address *const & slot() const
static constexpr no_checking_tag do_not_check
V8_INLINE StackAllocated()=default
static V8_INLINE bool EqualHandles(const T1 &lhs, const T2 &rhs)
LocalUnchecked(const Local< T > &other) noexcept
static V8_INLINE Address ValueAsAddress(const T *value)
static V8_INLINE bool IsEmpty(T *value)
internal::Address * InternalRepresentationType
constexpr const Iterator & base() const noexcept
V8_EXPORT void ToLocalEmpty()
#define V8_WARN_UNUSED_RESULT
#define V8_UNLIKELY(condition)