v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::Local< T > Class Template Reference

#include <v8-local-handle.h>

Inheritance diagram for v8::Local< T >:
Collaboration diagram for v8::Local< T >:

Public Member Functions

V8_INLINE Local ()=default
 
template<class S >
requires std::is_base_of_v<T, S>
V8_INLINE Local (Local< S > that)
 
V8_INLINE Toperator-> () const
 
V8_INLINE Toperator* () const
 
template<class S >
V8_INLINE bool operator== (const Local< S > &that) const
 
template<class S >
V8_INLINE bool operator== (const PersistentBase< S > &that) const
 
template<class S >
V8_INLINE bool operator!= (const Local< S > &that) const
 
template<class S >
V8_INLINE bool operator!= (const Persistent< S > &that) const
 
template<class S >
V8_INLINE Local< S > As () const
 
- Public Member Functions inherited from v8::api_internal::IndirectHandleBase
V8_INLINE bool IsEmpty () const
 
V8_INLINE void Clear ()
 
- Public Member Functions inherited from v8::api_internal::StackAllocated< false >
V8_INLINE StackAllocated ()=default
 

Static Public Member Functions

template<class S >
static V8_INLINE Local< TCast (Local< S > that)
 
static V8_INLINE Local< TNew (Isolate *isolate, Local< T > that)
 
static V8_INLINE Local< TNew (Isolate *isolate, const PersistentBase< T > &that)
 
static V8_INLINE Local< TNew (Isolate *isolate, const BasicTracedReference< T > &that)
 

Private Member Functions

 Local (no_checking_tag do_not_check)
 
 Local (const Local< T > &other, no_checking_tag do_not_check)
 
V8_INLINE Local (const LocalBase< T > &other)
 
template<class S >
V8_INLINE Local< S > UnsafeAs () const
 

Static Private Member Functions

static V8_INLINE Local< TFromRepr (internal::ValueHelper::InternalRepresentationType repr)
 
static V8_INLINE Local< TFromSlot (internal::Address *slot)
 
static V8_INLINE Local< TNew (Isolate *isolate, internal::Address value)
 
static V8_INLINE Local< TNew (Isolate *isolate, T *that)
 

Friends

class TracedReferenceBase
 
class Utils
 
template<class F >
class Eternal
 
template<class F >
class Global
 
template<class F >
class Local
 
template<class F >
class MaybeLocal
 
template<class F , class M >
class Persistent
 
template<class F >
class FunctionCallbackInfo
 
template<class F >
class PropertyCallbackInfo
 
class String
 
class Object
 
class Context
 
class Isolate
 
class Private
 
template<class F >
class internal::CustomArguments
 
class HandleScope
 
class EscapableHandleScope
 
class InternalEscapableScope
 
template<class F1 , class F2 , class F3 >
class PersistentValueMapBase
 
template<class F >
class ReturnValue
 
template<class F >
class Traced
 
class internal::SamplingHeapProfiler
 
class internal::HandleHelper
 
class debug::ConsoleCallArguments
 
class internal::LocalUnchecked< T >
 
Local< PrimitiveUndefined (Isolate *isolate)
 
Local< PrimitiveNull (Isolate *isolate)
 
Local< BooleanTrue (Isolate *isolate)
 
Local< BooleanFalse (Isolate *isolate)
 

Additional Inherited Members

- Protected Member Functions inherited from v8::LocalBase< T >
V8_INLINE LocalBase ()=default
 
V8_INLINE LocalBase (internal::Address *location)
 
template<typename S >
V8_INLINE LocalBase (const LocalBase< S > &other)
 
- Protected Member Functions inherited from v8::api_internal::IndirectHandleBase
V8_INLINE IndirectHandleBase ()=default
 
V8_INLINE IndirectHandleBase (const IndirectHandleBase &other)=default
 
V8_INLINE IndirectHandleBaseoperator= (const IndirectHandleBase &that)=default
 
V8_INLINE IndirectHandleBase (internal::Address *location)
 
V8_INLINE internal::Address ptr () const
 
V8_INLINE internal::Address *const & slot () const
 
V8_INLINE internal::Address *& slot ()
 
template<typename T , bool check_null = false>
V8_INLINE Tvalue () const
 
V8_INLINE internal::ValueHelper::InternalRepresentationType repr () const
 
- Protected Member Functions inherited from v8::api_internal::StackAllocated< false >
V8_INLINE StackAllocated (no_checking_tag)
 
V8_INLINE StackAllocated (const StackAllocated &other, no_checking_tag)
 
V8_INLINE void VerifyOnStack () const
 
- Static Protected Member Functions inherited from v8::LocalBase< T >
static V8_INLINE LocalBase< TNew (Isolate *isolate, internal::Address value)
 
static V8_INLINE LocalBase< TNew (Isolate *isolate, T *that)
 
static V8_INLINE LocalBase< TFromSlot (internal::Address *slot)
 
static V8_INLINE LocalBase< TFromRepr (internal::ValueHelper::InternalRepresentationType repr)
 
- Static Protected Attributes inherited from v8::api_internal::StackAllocated< false >
static constexpr no_checking_tag do_not_check
 

Detailed Description

template<class T>
class v8::Local< T >

An object reference managed by the v8 garbage collector.

All objects returned from v8 have to be tracked by the garbage collector so that it knows that the objects are still alive. Also, because the garbage collector may move objects, it is unsafe to point directly to an object. Instead, all objects are stored in handles which are known by the garbage collector and updated whenever an object moves. Handles should always be passed by value (except in cases like out-parameters) and they should never be allocated on the heap.

There are two types of handles: local and persistent handles.

Local handles are light-weight and transient and typically used in local operations. They are managed by HandleScopes. That means that a HandleScope must exist on the stack when they are created and that they are only valid inside of the HandleScope active during their creation. For passing a local handle to an outer HandleScope, an EscapableHandleScope and its Escape() method must be used.

Persistent handles can be used when storing objects across several independent operations and have to be explicitly deallocated when they're no longer used.

It is safe to extract the object stored in the handle by dereferencing the handle (for instance, to extract the Object* from a Local<Object>); the value will still be governed by a handle behind the scenes and the same rules apply to these values as to their handles.

Definition at line 261 of file v8-local-handle.h.

Constructor & Destructor Documentation

◆ Local() [1/5]

template<class T >
V8_INLINE v8::Local< T >::Local ( )
default

Default constructor: Returns an empty handle.

◆ Local() [2/5]

template<class T >
template<class S >
requires std::is_base_of_v<T, S>
V8_INLINE v8::Local< T >::Local ( Local< S > that)
inline

Constructor for handling automatic up casting. Ex. Local<Object> can be passed when Local<Value> is expected but not the other way round.

Definition at line 281 of file v8-local-handle.h.

◆ Local() [3/5]

template<class T >
v8::Local< T >::Local ( no_checking_tag do_not_check)
inlineexplicitprivate

Definition at line 405 of file v8-local-handle.h.

◆ Local() [4/5]

template<class T >
v8::Local< T >::Local ( const Local< T > & other,
no_checking_tag do_not_check )
inlineexplicitprivate

Definition at line 407 of file v8-local-handle.h.

◆ Local() [5/5]

template<class T >
V8_INLINE v8::Local< T >::Local ( const LocalBase< T > & other)
inlineexplicitprivate

Definition at line 410 of file v8-local-handle.h.

Member Function Documentation

◆ As()

template<class T >
template<class S >
V8_INLINE Local< S > v8::Local< T >::As ( ) const
inline

Calling this is equivalent to Local<S>::Cast(). In particular, this is only valid if the handle actually refers to a value of the target type or if the handle is empty.

Definition at line 340 of file v8-local-handle.h.

Here is the caller graph for this function:

◆ Cast()

template<class T >
template<class S >
static V8_INLINE Local< T > v8::Local< T >::Cast ( Local< S > that)
inlinestatic

Cast a handle to a subclass, e.g. Local<Value> to Local<Object>. This is only valid if the handle actually refers to a value of the target type or if the handle is empty.

Definition at line 324 of file v8-local-handle.h.

Here is the caller graph for this function:

◆ FromRepr()

template<class T >
static V8_INLINE Local< T > v8::Local< T >::FromRepr ( internal::ValueHelper::InternalRepresentationType repr)
inlinestaticprivate

Definition at line 412 of file v8-local-handle.h.

Here is the caller graph for this function:

◆ FromSlot()

template<class T >
static V8_INLINE Local< T > v8::Local< T >::FromSlot ( internal::Address * slot)
inlinestaticprivate

Definition at line 417 of file v8-local-handle.h.

Here is the caller graph for this function:

◆ New() [1/5]

template<class T >
static V8_INLINE Local< T > v8::Local< T >::New ( Isolate * isolate,
const BasicTracedReference< T > & that )
inlinestatic

Definition at line 358 of file v8-local-handle.h.

◆ New() [2/5]

template<class T >
static V8_INLINE Local< T > v8::Local< T >::New ( Isolate * isolate,
const PersistentBase< T > & that )
inlinestatic

Definition at line 353 of file v8-local-handle.h.

◆ New() [3/5]

template<class T >
static V8_INLINE Local< T > v8::Local< T >::New ( Isolate * isolate,
internal::Address value )
inlinestaticprivate

Definition at line 429 of file v8-local-handle.h.

◆ New() [4/5]

template<class T >
static V8_INLINE Local< T > v8::Local< T >::New ( Isolate * isolate,
Local< T > that )
inlinestatic

Create a local handle for the content of another handle. The referee is kept alive by the local handle even when the original handle is destroyed/disposed.

Definition at line 349 of file v8-local-handle.h.

Here is the caller graph for this function:

◆ New() [5/5]

template<class T >
static V8_INLINE Local< T > v8::Local< T >::New ( Isolate * isolate,
T * that )
inlinestaticprivate

Definition at line 433 of file v8-local-handle.h.

◆ operator!=() [1/2]

template<class T >
template<class S >
V8_INLINE bool v8::Local< T >::operator!= ( const Local< S > & that) const
inline

Definition at line 309 of file v8-local-handle.h.

◆ operator!=() [2/2]

template<class T >
template<class S >
V8_INLINE bool v8::Local< T >::operator!= ( const Persistent< S > & that) const
inline

Definition at line 314 of file v8-local-handle.h.

◆ operator*()

template<class T >
V8_INLINE T * v8::Local< T >::operator* ( ) const
inline

Definition at line 285 of file v8-local-handle.h.

◆ operator->()

template<class T >
V8_INLINE T * v8::Local< T >::operator-> ( ) const
inline

Definition at line 283 of file v8-local-handle.h.

◆ operator==() [1/2]

template<class T >
template<class S >
V8_INLINE bool v8::Local< T >::operator== ( const Local< S > & that) const
inline

Checks whether two handles are equal or different. They are equal iff they are both empty or they are both non-empty and the objects to which they refer are physically equal.

If both handles refer to JS objects, this is the same as strict non-equality. For primitives, such as numbers or strings, a true return value does not indicate that the values aren't equal in the JavaScript sense. Use Value::StrictEquals() to check primitives for equality.

Definition at line 299 of file v8-local-handle.h.

◆ operator==() [2/2]

template<class T >
template<class S >
V8_INLINE bool v8::Local< T >::operator== ( const PersistentBase< S > & that) const
inline

Definition at line 304 of file v8-local-handle.h.

◆ UnsafeAs()

template<class T >
template<class S >
V8_INLINE Local< S > v8::Local< T >::UnsafeAs ( ) const
inlineprivate

Definition at line 439 of file v8-local-handle.h.

Friends And Related Symbol Documentation

◆ Context

template<class T >
friend class Context
friend

Definition at line 382 of file v8-local-handle.h.

◆ debug::ConsoleCallArguments

template<class T >
friend class debug::ConsoleCallArguments
friend

Definition at line 402 of file v8-local-handle.h.

◆ EscapableHandleScope

template<class T >
friend class EscapableHandleScope
friend

Definition at line 392 of file v8-local-handle.h.

◆ Eternal

template<class T >
template<class F >
friend class Eternal
friend

Definition at line 367 of file v8-local-handle.h.

◆ False

template<class T >
Local< Boolean > False ( Isolate * isolate)
friend

Definition at line 1081 of file v8-primitive.h.

◆ FunctionCallbackInfo

template<class T >
template<class F >
friend class FunctionCallbackInfo
friend

Definition at line 377 of file v8-local-handle.h.

◆ Global

template<class T >
template<class F >
friend class Global
friend

Definition at line 369 of file v8-local-handle.h.

◆ HandleScope

template<class T >
friend class HandleScope
friend

Definition at line 391 of file v8-local-handle.h.

◆ internal::CustomArguments

template<class T >
template<class F >
friend class internal::CustomArguments
friend

Definition at line 386 of file v8-local-handle.h.

◆ internal::HandleHelper

template<class T >
friend class internal::HandleHelper
friend

Definition at line 401 of file v8-local-handle.h.

◆ internal::LocalUnchecked< T >

template<class T >
friend class internal::LocalUnchecked< T >
friend

Definition at line 402 of file v8-local-handle.h.

◆ internal::SamplingHeapProfiler

template<class T >
friend class internal::SamplingHeapProfiler
friend

Definition at line 400 of file v8-local-handle.h.

◆ InternalEscapableScope

template<class T >
friend class InternalEscapableScope
friend

Definition at line 393 of file v8-local-handle.h.

◆ Isolate

template<class T >
friend class Isolate
friend

Definition at line 383 of file v8-local-handle.h.

◆ Local

template<class T >
template<class F >
friend class Local
friend

Definition at line 371 of file v8-local-handle.h.

◆ MaybeLocal

template<class T >
template<class F >
friend class MaybeLocal
friend

Definition at line 373 of file v8-local-handle.h.

◆ Null

template<class T >
Local< Primitive > Null ( Isolate * isolate)
friend

Definition at line 1065 of file v8-primitive.h.

◆ Object

template<class T >
friend class Object
friend

Definition at line 381 of file v8-local-handle.h.

◆ Persistent

template<class T >
template<class F , class M >
friend class Persistent
friend

Persistent is a way to create a strong pointer from an off-heap object to another on-heap object. As long as the Persistent handle is alive the GC will keep the object pointed to alive. The Persistent handle is always a GC root from the point of view of the GC. Persistent must be constructed and destructed in the same thread.

Definition at line 375 of file v8-local-handle.h.

◆ PersistentValueMapBase

template<class T >
template<class F1 , class F2 , class F3 >
friend class PersistentValueMapBase
friend

Definition at line 395 of file v8-local-handle.h.

◆ Private

template<class T >
friend class Private
friend

Definition at line 384 of file v8-local-handle.h.

◆ PropertyCallbackInfo

template<class T >
template<class F >
friend class PropertyCallbackInfo
friend

Definition at line 379 of file v8-local-handle.h.

◆ ReturnValue

template<class T >
template<class F >
friend class ReturnValue
friend

Definition at line 397 of file v8-local-handle.h.

◆ String

template<class T >
friend class String
friend

Definition at line 380 of file v8-local-handle.h.

◆ Traced

template<class T >
template<class F >
friend class Traced
friend

Definition at line 399 of file v8-local-handle.h.

◆ TracedReferenceBase

template<class T >
friend class TracedReferenceBase
friend

Definition at line 364 of file v8-local-handle.h.

◆ True

template<class T >
Local< Boolean > True ( Isolate * isolate)
friend

Definition at line 1073 of file v8-primitive.h.

◆ Undefined

template<class T >
Local< Primitive > Undefined ( Isolate * isolate)
friend

Definition at line 1057 of file v8-primitive.h.

◆ Utils

template<class T >
friend class Utils
friend

Definition at line 365 of file v8-local-handle.h.


The documentation for this class was generated from the following file: