v8  6.8.275 (node 10.15.3)
V8 is Google's open source JavaScript engine
Local< T > Class Template Reference

#include <v8.h>

Public Member Functions

V8_INLINE Local ()
 
template<class S >
V8_INLINE Local (Local< S > that)
 
V8_INLINE bool IsEmpty () const
 
V8_INLINE void Clear ()
 
V8_INLINE T * operator-> () const
 
V8_INLINE T * operator* () 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
 

Static Public Member Functions

template<class S >
static V8_INLINE Local< T > Cast (Local< S > that)
 
static V8_INLINE Local< T > New (Isolate *isolate, Local< T > that)
 
static V8_INLINE Local< T > New (Isolate *isolate, const PersistentBase< T > &that)
 

Friends

class Utils
 
template<class F >
class Eternal
 
template<class F >
class PersistentBase
 
template<class F , class M >
class Persistent
 
template<class F >
class Local
 
template<class F >
class MaybeLocal
 
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
 
template<class F1 , class F2 , class F3 >
class PersistentValueMapBase
 
template<class F1 , class F2 >
class PersistentValueVector
 
template<class F >
class ReturnValue
 
Local< PrimitiveUndefined (Isolate *isolate)
 
Local< PrimitiveNull (Isolate *isolate)
 
Local< BooleanTrue (Isolate *isolate)
 
Local< BooleanFalse (Isolate *isolate)
 

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 293 of file v8.h.

Constructor & Destructor Documentation

◆ Local() [1/2]

◆ Local() [2/2]

V8_INLINE Local ( Local< S >  that)
inline

This check fails when trying to convert between incompatible handles. For example, converting from a Local<String> to a Local<Number>.

Definition at line 297 of file v8.h.

Member Function Documentation

◆ As()

V8_INLINE Local<S> 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.

Definition at line 381 of file v8.h.

References Local< T >::Local.

◆ Cast()

static V8_INLINE 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.

Definition at line 366 of file v8.h.

References Local< T >::Local.

◆ Clear()

V8_INLINE void Clear ( )
inline

Sets the handle to be empty. IsEmpty() will then return true.

Definition at line 315 of file v8.h.

◆ IsEmpty()

V8_INLINE bool IsEmpty ( ) const
inline

Returns true if the handle is empty.

Definition at line 310 of file v8.h.

Referenced by ScriptOrigin::ScriptOrigin().

◆ New() [1/2]

Local< T > New ( Isolate isolate,
const PersistentBase< T > &  that 
)
static

Definition at line 9334 of file v8.h.

◆ New() [2/2]

Local< T > New ( Isolate isolate,
Local< T >  that 
)
static

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 9329 of file v8.h.

◆ operator!=() [1/2]

V8_INLINE bool operator!= ( const Local< S > &  that) const
inline

Checks whether two handles are different. Returns true if only one of the handles is empty, or if the objects to which they refer are different. The handles' references are not checked.

Definition at line 352 of file v8.h.

◆ operator!=() [2/2]

V8_INLINE bool operator!= ( const Persistent< S > &  that) const
inline

Definition at line 356 of file v8.h.

◆ operator*()

V8_INLINE T* operator* ( ) const
inline

Definition at line 319 of file v8.h.

◆ operator->()

V8_INLINE T* operator-> ( ) const
inline

Definition at line 317 of file v8.h.

Referenced by Context::Scope::Scope(), ScriptOrigin::ScriptOrigin(), and Context::Scope::~Scope().

◆ operator==() [1/2]

V8_INLINE bool operator== ( const Local< S > &  that) const
inline

Checks whether two handles are the same. Returns true if both are empty, or if the objects to which they refer are identical. The handles' references are not checked.

Definition at line 328 of file v8.h.

◆ operator==() [2/2]

V8_INLINE bool operator== ( const PersistentBase< S > &  that) const
inline

Definition at line 336 of file v8.h.

Friends And Related Function Documentation

◆ Context

friend class Context
friend

Definition at line 406 of file v8.h.

◆ EscapableHandleScope

friend class EscapableHandleScope
friend

Definition at line 415 of file v8.h.

◆ Eternal

friend class Eternal
friend

Definition at line 396 of file v8.h.

◆ False

Local<Boolean> False ( Isolate isolate)
friend

Definition at line 10406 of file v8.h.

Referenced by Boolean::New().

◆ FunctionCallbackInfo

friend class FunctionCallbackInfo
friend

Definition at line 402 of file v8.h.

◆ HandleScope

friend class HandleScope
friend

Definition at line 414 of file v8.h.

◆ internal::CustomArguments

friend class internal::CustomArguments
friend

Definition at line 409 of file v8.h.

◆ Isolate

friend class Isolate
friend

Definition at line 407 of file v8.h.

◆ Local

◆ MaybeLocal

friend class MaybeLocal
friend

Definition at line 401 of file v8.h.

Referenced by V8InspectorClient::memoryInfo().

◆ Null

Local<Primitive> Null ( Isolate isolate)
friend

Definition at line 10388 of file v8.h.

◆ Object

friend class Object
friend

Definition at line 405 of file v8.h.

◆ Persistent

friend class Persistent
friend

Definition at line 398 of file v8.h.

Referenced by Persistent< T, M >::As(), and Persistent< T, M >::Cast().

◆ PersistentBase

friend class PersistentBase
friend

Definition at line 397 of file v8.h.

Referenced by Global< T >::Global(), and Persistent< T, M >::Persistent().

◆ PersistentValueMapBase

friend class PersistentValueMapBase
friend

Definition at line 417 of file v8.h.

◆ PersistentValueVector

friend class PersistentValueVector
friend

Definition at line 418 of file v8.h.

◆ Private

friend class Private
friend

Definition at line 408 of file v8.h.

◆ PropertyCallbackInfo

friend class PropertyCallbackInfo
friend

Definition at line 403 of file v8.h.

◆ ReturnValue

friend class ReturnValue
friend

◆ String

friend class String
friend

Definition at line 404 of file v8.h.

◆ True

Local<Boolean> True ( Isolate isolate)
friend

Definition at line 10397 of file v8.h.

Referenced by Boolean::New().

◆ Undefined

Local<Primitive> Undefined ( Isolate isolate)
friend

Definition at line 10379 of file v8.h.

◆ Utils

friend class Utils
friend

Definition at line 395 of file v8.h.


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