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;
49class FunctionCallbackInfo;
52template <
class F1,
class F2,
class F3>
53class PersistentValueMapBase;
57class PropertyCallbackInfo;
67class ConsoleCallArguments;
75class SamplingHeapProfiler;
78namespace api_internal {
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>
173 return LocalBase<T>(
value);
176 V8_INLINE static LocalBase<T>
New(Isolate* isolate, T* that) {
182 return LocalBase<T>(*
slot);
187 return LocalBase<T>(
repr);
204 template <
typename S>
209 reinterpret_cast<internal::Isolate*
>(isolate),
value));
261#ifdef V8_ENABLE_LOCAL_OFF_STACK_CHECK
277 static_assert(std::is_base_of<T, S>::value,
"type check");
297 return internal::HandleHelper::EqualHandles(*
this, that);
302 return internal::HandleHelper::EqualHandles(*
this, that);
307 return !operator==(that);
312 return !operator==(that);
322#ifdef V8_ENABLE_CHECKS
326 T::Cast(that.template value<S>());
347 return New(isolate, that.template value<T, true>());
352 return New(isolate, that.template value<T, true>());
357 return New(isolate, that.template value<T, true>());
371 template <
class F,
class M>
391 template <
class F1,
class F2,
class F3>
397 friend class internal::SamplingHeapProfiler;
399 friend class debug::ConsoleCallArguments;
402 explicit Local(no_checking_tag do_not_check)
403 :
LocalBase<T>(), StackAllocated(do_not_check) {}
404 explicit Local(
const Local<T>& other, no_checking_tag do_not_check)
405 :
LocalBase<T>(other), StackAllocated(do_not_check) {}
407 V8_INLINE explicit Local(
const LocalBase<T>& other) : LocalBase<T>(other) {}
410 internal::ValueHelper::InternalRepresentationType repr) {
411 return Local<T>(LocalBase<T>::FromRepr(repr));
414 V8_INLINE static Local<T> FromSlot(internal::Address* slot) {
415 return Local<T>(LocalBase<T>::FromSlot(slot));
418#ifdef V8_ENABLE_DIRECT_HANDLE
419 friend class TypecheckWitness;
421 V8_INLINE static Local<T> FromAddress(internal::Address ptr) {
422 return Local<T>(LocalBase<T>(ptr));
426 V8_INLINE static Local<T> New(Isolate* isolate, internal::Address value) {
427 return Local<T>(LocalBase<T>::New(isolate, value));
430 V8_INLINE static Local<T> New(Isolate* isolate, T* that) {
431 return Local<T>(LocalBase<T>::New(isolate, that));
437 return Local<S>(LocalBase<S>(*
this));
449#if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
455 LocalUnchecked& operator=(
const LocalUnchecked&)
noexcept =
default;
463#ifdef V8_ENABLE_DIRECT_HANDLE
468class StrongRootAllocator<LocalUnchecked<T>> :
public StrongRootAllocatorBase {
470 using value_type = LocalUnchecked<T>;
471 static_assert(std::is_standard_layout_v<value_type>);
472 static_assert(
sizeof(value_type) ==
sizeof(Address));
474 template <
typename HeapOrIsolateT>
475 explicit StrongRootAllocator(HeapOrIsolateT* heap_or_isolate)
476 : StrongRootAllocatorBase(heap_or_isolate) {}
477 template <
typename U>
478 StrongRootAllocator(
const StrongRootAllocator<U>& other) noexcept
479 : StrongRootAllocatorBase(other) {}
481 value_type* allocate(
size_t n) {
482 return reinterpret_cast<value_type*
>(allocate_impl(n));
484 void deallocate(value_type* p,
size_t n)
noexcept {
485 return deallocate_impl(
reinterpret_cast<Address*
>(p), n);
496#ifdef V8_ENABLE_DIRECT_HANDLE
499 static allocator_type make_allocator(
Isolate* isolate)
noexcept {
500 return allocator_type(isolate);
503 using allocator_type = std::allocator<element_type>;
505 static allocator_type make_allocator(
Isolate* isolate)
noexcept {
506 return allocator_type();
510 using vector_type = std::vector<element_type, allocator_type>;
526 : backing_(n, make_allocator(isolate)) {}
528 : backing_(make_allocator(isolate)) {
529 if (init.size() == 0)
return;
530 backing_.reserve(init.size());
531 backing_.insert(backing_.end(), init.begin(), init.end());
541 size_t size() const noexcept {
return backing_.size(); }
542 bool empty() const noexcept {
return backing_.empty(); }
543 void reserve(
size_t n) { backing_.reserve(n); }
550 const Local<T>&
at(
size_t n)
const {
return backing_.at(n); }
564 template <
typename InputIt>
566 return iterator(backing_.insert(pos.
base(), first, last));
570 return iterator(backing_.insert(pos.
base(), init.begin(), init.end()));
575 backing_.reserve(init.size());
576 backing_.insert(backing_.end(), init.begin(), init.end());
583 template <
typename... Args>
585 backing_.push_back(
value_type{std::forward<Args>(args)...});
588 void clear() noexcept { backing_.clear(); }
589 void resize(
size_t n) { backing_.resize(n); }
593 return x.backing_ == y.backing_;
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_;
612 vector_type backing_;
615#if !defined(V8_IMMINENT_DEPRECATION_WARNINGS)
675#ifdef V8_ENABLE_CHECKS
679 T::Cast(that.local_.template value<S>());
697 template <
typename S>
712 void*
operator new(
size_t size) =
delete;
713 void*
operator new[](
size_t size) =
delete;
714 void operator delete(
void*, size_t) =
delete;
715 void operator delete[](
void*, size_t) =
delete;
736#ifdef V8_ENABLE_DIRECT_HANDLE
739 if (value.
IsEmpty())
return value;
762 void*
operator new(
size_t size) =
delete;
763 void*
operator new[](
size_t size) =
delete;
764 void operator delete(
void*, size_t) =
delete;
765 void operator delete[](
void*, size_t) =
delete;
768 internal::Isolate*
const i_isolate_;
770 int prev_sealed_level_;
Definition: v8-traced-handle.h:124
Definition: v8-context.h:48
Definition: v8-local-handle.h:705
EscapableHandleScopeBase(Isolate *isolate)
internal::Address * EscapeSlot(internal::Address *escape_value)
EscapableHandleScopeBase(const EscapableHandleScopeBase &)=delete
void operator=(const EscapableHandleScopeBase &)=delete
~EscapableHandleScopeBase()=default
Definition: v8-local-handle.h:729
~EscapableHandleScope()=default
Local< T > Escape(Local< T > value)
Definition: v8-local-handle.h:735
MaybeLocal< T > EscapeMaybe(MaybeLocal< T > value)
Definition: v8-local-handle.h:745
EscapableHandleScope(Isolate *isolate)
Definition: v8-local-handle.h:731
Definition: v8-local-handle.h:97
void operator=(const HandleScope &)=delete
void Initialize(Isolate *isolate)
HandleScope(const HandleScope &)=delete
Isolate * GetIsolate() const
Definition: v8-local-handle.h:108
static int NumberOfHandles(Isolate *isolate)
static internal::Address * CreateHandleForCurrentIsolate(internal::Address value)
static internal::Address * CreateHandle(internal::Isolate *i_isolate, internal::Address value)
HandleScope(Isolate *isolate)
Definition: v8-isolate.h:212
Definition: v8-local-handle.h:194
static LocalBase< T > New(Isolate *isolate, T *that)
Definition: v8-local-handle.h:212
static LocalBase< T > FromSlot(internal::Address *slot)
Definition: v8-local-handle.h:218
LocalBase(const LocalBase< S > &other)
Definition: v8-local-handle.h:205
static LocalBase< T > FromRepr(internal::ValueHelper::InternalRepresentationType repr)
Definition: v8-local-handle.h:222
LocalBase(internal::Address *location)
Definition: v8-local-handle.h:201
static LocalBase< T > New(Isolate *isolate, internal::Address value)
Definition: v8-local-handle.h:207
Definition: v8-local-handle.h:492
LocalVector< T > & operator=(std::initializer_list< Local< T > > init)
Definition: v8-local-handle.h:573
const Local< T > & front() const
Definition: v8-local-handle.h:553
friend bool operator>=(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:607
bool empty() const noexcept
Definition: v8-local-handle.h:542
const Local< T > * data() const noexcept
Definition: v8-local-handle.h:558
const_iterator end() const noexcept
Definition: v8-local-handle.h:539
const Local< T > & operator[](size_t n) const
Definition: v8-local-handle.h:547
friend bool operator<(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:598
const Local< T > & back() const
Definition: v8-local-handle.h:555
void shrink_to_fit()
Definition: v8-local-handle.h:544
Local< T > * data() noexcept
Definition: v8-local-handle.h:557
void reserve(size_t n)
Definition: v8-local-handle.h:543
Local< T > & front()
Definition: v8-local-handle.h:552
internal::WrappedIterator< typename vector_type::iterator, Local< T > > iterator
Definition: v8-local-handle.h:519
friend bool operator<=(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:604
friend bool operator!=(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:595
Local< T > & operator[](size_t n)
Definition: v8-local-handle.h:546
size_t size_type
Definition: v8-local-handle.h:516
void emplace_back(Args &&... args)
Definition: v8-local-handle.h:584
const_iterator begin() const noexcept
Definition: v8-local-handle.h:535
iterator insert(const_iterator pos, std::initializer_list< Local< T > > init)
Definition: v8-local-handle.h:569
Local< T > & at(size_t n)
Definition: v8-local-handle.h:549
ptrdiff_t difference_type
Definition: v8-local-handle.h:517
iterator insert(const_iterator pos, const Local< T > &value)
Definition: v8-local-handle.h:560
internal::WrappedIterator< typename vector_type::const_iterator, const Local< T > > const_iterator
Definition: v8-local-handle.h:522
void pop_back()
Definition: v8-local-handle.h:581
LocalVector(Isolate *isolate, std::initializer_list< Local< T > > init)
Definition: v8-local-handle.h:527
iterator end() noexcept
Definition: v8-local-handle.h:538
const Local< T > & at(size_t n) const
Definition: v8-local-handle.h:550
void clear() noexcept
Definition: v8-local-handle.h:588
void swap(LocalVector< T > &other)
Definition: v8-local-handle.h:590
iterator insert(const_iterator pos, InputIt first, InputIt last)
Definition: v8-local-handle.h:565
friend bool operator==(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:592
LocalVector(Isolate *isolate)
Definition: v8-local-handle.h:524
size_t size() const noexcept
Definition: v8-local-handle.h:541
void resize(size_t n)
Definition: v8-local-handle.h:589
Local< T > & back()
Definition: v8-local-handle.h:554
LocalVector(Isolate *isolate, size_t n)
Definition: v8-local-handle.h:525
void push_back(const Local< T > &x)
Definition: v8-local-handle.h:580
iterator begin() noexcept
Definition: v8-local-handle.h:534
friend bool operator>(const LocalVector< T > &x, const LocalVector< T > &y)
Definition: v8-local-handle.h:601
Definition: v8-local-handle.h:266
friend class TracedReferenceBase
Definition: v8-local-handle.h:361
friend class Object
Definition: v8-local-handle.h:378
friend class PersistentValueMapBase
Definition: v8-local-handle.h:392
static Local< T > New(Isolate *isolate, const PersistentBase< T > &that)
Definition: v8-local-handle.h:350
friend class PropertyCallbackInfo
Definition: v8-local-handle.h:376
friend class ReturnValue
Definition: v8-local-handle.h:394
friend class HandleScope
Definition: v8-local-handle.h:388
friend class Traced
Definition: v8-local-handle.h:396
T * operator*() const
Definition: v8-local-handle.h:282
static Local< T > Cast(Local< S > that)
Definition: v8-local-handle.h:321
friend class FunctionCallbackInfo
Definition: v8-local-handle.h:374
Local< S > As() const
Definition: v8-local-handle.h:337
friend class String
Definition: v8-local-handle.h:377
bool operator!=(const Local< S > &that) const
Definition: v8-local-handle.h:306
friend class MaybeLocal
Definition: v8-local-handle.h:370
static Local< T > New(Isolate *isolate, const BasicTracedReference< T > &that)
Definition: v8-local-handle.h:355
bool operator==(const PersistentBase< S > &that) const
Definition: v8-local-handle.h:301
bool operator!=(const Persistent< S > &that) const
Definition: v8-local-handle.h:311
friend class Isolate
Definition: v8-local-handle.h:380
friend class Utils
Definition: v8-local-handle.h:362
static Local< T > New(Isolate *isolate, Local< T > that)
Definition: v8-local-handle.h:346
friend class Context
Definition: v8-local-handle.h:379
friend class Private
Definition: v8-local-handle.h:381
friend class Persistent
Definition: v8-local-handle.h:372
friend class Global
Definition: v8-local-handle.h:366
T * operator->() const
Definition: v8-local-handle.h:280
friend class EscapableHandleScope
Definition: v8-local-handle.h:389
friend class Eternal
Definition: v8-local-handle.h:364
bool operator==(const Local< S > &that) const
Definition: v8-local-handle.h:296
friend class InternalEscapableScope
Definition: v8-local-handle.h:390
Local(Local< S > that)
Definition: v8-local-handle.h:271
friend class Local
Definition: v8-local-handle.h:368
Definition: v8-local-handle.h:632
bool ToLocal(Local< S > *out) const
Definition: v8-local-handle.h:645
static MaybeLocal< T > Cast(MaybeLocal< S > that)
Definition: v8-local-handle.h:674
MaybeLocal< S > As() const
Definition: v8-local-handle.h:690
Local< T > ToLocalChecked()
Definition: v8-local-handle.h:654
Local< S > FromMaybe(Local< S > default_value) const
Definition: v8-local-handle.h:664
MaybeLocal()
Definition: v8-local-handle.h:634
bool IsEmpty() const
Definition: v8-local-handle.h:638
MaybeLocal(Local< S > that)
Definition: v8-local-handle.h:636
Definition: v8-object.h:233
Definition: v8-persistent-handle.h:89
Definition: v8-persistent-handle.h:246
Definition: v8-local-handle.h:755
SealHandleScope(const SealHandleScope &)=delete
void operator=(const SealHandleScope &)=delete
SealHandleScope(Isolate *isolate)
Definition: v8-local-handle.h:62
Definition: v8-value.h:497
Definition: v8-handle-base.h:53
T * value() const
Definition: v8-handle-base.h:85
internal::Address ptr() const
Definition: v8-handle-base.h:76
IndirectHandleBase()=default
internal::Address *const & slot() const
Definition: v8-handle-base.h:79
bool IsEmpty() const
Definition: v8-handle-base.h:56
internal::ValueHelper::InternalRepresentationType repr() const
Definition: v8-handle-base.h:94
Definition: v8-handle-base.h:13
Definition: v8-local-handle.h:72
Definition: v8-internal.h:1713
Definition: v8-local-handle.h:445
LocalUnchecked()
Definition: v8-local-handle.h:447
LocalUnchecked(const Local< T > &other) noexcept
Definition: v8-local-handle.h:459
Definition: v8-internal.h:1399
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1687
internal::Address * InternalRepresentationType
Definition: v8-internal.h:1641
static bool IsEmpty(T *value)
Definition: v8-internal.h:1646
Definition: v8-internal.h:1458
constexpr const Iterator & base() const noexcept
Definition: v8-internal.h:1618
internal::BasicPersistent< T, internal::StrongPersistentPolicy > Persistent
Definition: persistent.h:363
uintptr_t Address
Definition: v8-internal.h:51
Definition: libplatform.h:15
Local< Primitive > Null(Isolate *isolate)
Definition: v8-primitive.h:1029
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1021
Local< Boolean > False(Isolate *isolate)
Definition: v8-primitive.h:1045
Local< Boolean > True(Isolate *isolate)
Definition: v8-primitive.h:1037
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:660
#define V8_UNLIKELY(condition)
Definition: v8config.h:649
#define V8_TRIVIAL_ABI
Definition: v8config.h:743
#define V8_NODISCARD
Definition: v8config.h:682