v8 13.6.233 (node 24.1.0)
V8 is Google's open source JavaScript engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
MaybeLocal< T > Class Template Reference

#include <v8-local-handle.h>

Public Member Functions

V8_INLINE MaybeLocal ()=default
 
template<class S>
requires std::is_base_of_v<T, S>
V8_INLINE MaybeLocal (Local< S > that)
 
template<class S>
requires std::is_base_of_v<T, S>
V8_INLINE MaybeLocal (MaybeLocal< S > that)
 
V8_INLINE bool IsEmpty () const
 
template<class S>
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal (Local< S > *out) const
 
V8_INLINE Local< T > ToLocalChecked ()
 
template<class S>
V8_INLINE Local< S > FromMaybe (Local< S > default_value) const
 
template<class S>
V8_INLINE MaybeLocal< S > As () const
 

Static Public Member Functions

template<class S>
static V8_INLINE MaybeLocal< T > Cast (MaybeLocal< S > that)
 

Friends

template<typename S>
class MaybeLocal
 

Detailed Description

template<class T>
class v8::MaybeLocal< T >

A MaybeLocal<> is a wrapper around Local<> that enforces a check whether the Local<> is empty before it can be used.

If an API method returns a MaybeLocal<>, the API method can potentially fail either because an exception is thrown, or because an exception is pending, e.g. because a previous API call threw an exception that hasn't been caught yet, or because a TerminateExecution exception was thrown. In that case, an empty MaybeLocal is returned.

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

Constructor & Destructor Documentation

◆ MaybeLocal() [1/3]

template<class T>
V8_INLINE MaybeLocal ( )
default

Default constructor: Returns an empty handle.

◆ MaybeLocal() [2/3]

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

Implicitly construct MaybeLocal from Local.

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

◆ MaybeLocal() [3/3]

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

Implicitly up-cast MaybeLocal to MaybeLocal<T> if T is a base of S.

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

Member Function Documentation

◆ As()

template<class T>
template<class S>
V8_INLINE MaybeLocal< S > As ( ) const
inline

Calling this is equivalent to MaybeLocal<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 700 of file v8-local-handle.h.

◆ Cast()

template<class T>
template<class S>
static V8_INLINE MaybeLocal< T > Cast ( MaybeLocal< S > that)
inlinestatic

Cast a handle to a subclass, e.g. MaybeLocal<Value> to MaybeLocal<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 690 of file v8-local-handle.h.

Referenced by MaybeLocal< Promise >(*)(Local< Context > context, Local< Data > host_defined_options, Local< Value > resource_name, Local< String > specifier, Local< FixedArray > import_attributes)::As().

◆ FromMaybe()

template<class T>
template<class S>
V8_INLINE Local< S > FromMaybe ( Local< S > default_value) const
inline

Converts this MaybeLocal<> to a Local<>, using a default value if this MaybeLocal<> is empty.

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

Referenced by EscapableHandleScope::EscapeMaybe().

◆ IsEmpty()

◆ ToLocal()

template<class T>
template<class S>
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal ( Local< S > * out) const
inline

Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, |false| is returned and |out| is assigned with nullptr.

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

◆ ToLocalChecked()

template<class T>
V8_INLINE Local< T > ToLocalChecked ( )
inline

Converts this MaybeLocal<> to a Local<>. If this MaybeLocal<> is empty, V8 will crash the process.

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

Friends And Related Symbol Documentation

◆ MaybeLocal

template<class T>
template<typename S>
friend class MaybeLocal
friend

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


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