v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
Maybe< T > Class Template Reference

#include <v8-maybe.h>

Inheritance diagram for Maybe< T >:
Collaboration diagram for Maybe< T >:

Public Member Functions

constexpr Maybe ()=default
 
V8_INLINE Maybe (internal::NullMaybeType)
 
V8_INLINE bool IsNothing () const
 
V8_INLINE bool IsJust () const
 
V8_INLINE bool IsEmpty () const
 
V8_INLINEToChecked () const
 
V8_INLINE void Check () const
 
V8_WARN_UNUSED_RESULT V8_INLINE bool To (T *out) const
 
V8_WARN_UNUSED_RESULT V8_INLINE bool MoveTo (T *out) &&
 
V8_INLINEFromJust () const &
 
V8_INLINEFromJust () &&
 
V8_INLINEFromMaybe (const T &default_value) const
 
V8_INLINE bool operator== (const Maybe &other) const
 
V8_INLINE bool operator!= (const Maybe &other) const
 
- Public Member Functions inherited from ConditionalStackAllocatedBase< T >
 CPPGC_STACK_ALLOCATED ()
 

Friends

template<class U >
Maybe< U > Just (const U &u)
 
template<class U , std::enable_if_t<!std::is_lvalue_reference_v< U > > * >
Maybe< U > Just (U &&u)
 

Detailed Description

template<class T>
class v8::Maybe< T >

A simple Maybe type, representing an object which may or may not have a value, see https://hackage.haskell.org/package/base/docs/Data-Maybe.html.

If an API method returns a Maybe<>, 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, a "Nothing" value is returned.

Definition at line 39 of file v8-maybe.h.

Constructor & Destructor Documentation

◆ Maybe() [1/2]

template<class T >
constexpr Maybe ( )
constexprdefault

◆ Maybe() [2/2]

template<class T >
V8_INLINE Maybe ( internal::NullMaybeType  )
inline

Definition at line 43 of file v8-maybe.h.

Member Function Documentation

◆ Check()

template<class T >
V8_INLINE void Check ( ) const
inline

Short-hand for ToChecked(), which doesn't return a value. To be used, where the actual value of the Maybe is not needed like Object::Set.

Definition at line 63 of file v8-maybe.h.

References v8::api_internal::FromJustIsNothing(), and Maybe< T >::IsJust().

◆ FromJust() [1/2]

template<class T >
V8_INLINE T FromJust ( ) &&
inline

Converts this Maybe<> to a value of type T. If this Maybe<> is nothing (empty), V8 will crash the process.

Definition at line 99 of file v8-maybe.h.

References v8::api_internal::FromJustIsNothing(), and Maybe< T >::IsJust().

◆ FromJust() [2/2]

template<class T >
V8_INLINE T FromJust ( ) const &
inline

Converts this Maybe<> to a value of type T. If this Maybe<> is nothing (empty), V8 will crash the process.

Definition at line 90 of file v8-maybe.h.

References v8::api_internal::FromJustIsNothing(), and Maybe< T >::IsJust().

◆ FromMaybe()

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

Converts this Maybe<> to a value of type T, using a default value if this Maybe<> is nothing (empty).

Definition at line 108 of file v8-maybe.h.

◆ IsEmpty()

template<class T >
V8_INLINE bool IsEmpty ( ) const
inline

Same as IsNothing(). It's useful for unified handling of empty states with v8::MaybeLocal<T>.

Definition at line 52 of file v8-maybe.h.

References Maybe< T >::IsNothing().

◆ IsJust()

template<class T >
V8_INLINE bool IsJust ( ) const
inline

◆ IsNothing()

template<class T >
V8_INLINE bool IsNothing ( ) const
inline

Definition at line 45 of file v8-maybe.h.

Referenced by Maybe< T >::IsEmpty().

◆ MoveTo()

template<class T >
V8_WARN_UNUSED_RESULT V8_INLINE bool MoveTo ( T *  out) &&
inline

Converts this Maybe<> to a value of type T, moving out of it. If this Maybe<> is nothing (empty), |false| is returned and |out| is left untouched.

Definition at line 81 of file v8-maybe.h.

References Maybe< T >::IsJust().

◆ operator!=()

template<class T >
V8_INLINE bool operator!= ( const Maybe< T > &  other) const
inline

Definition at line 117 of file v8-maybe.h.

References Maybe< T >::operator==().

◆ operator==()

template<class T >
V8_INLINE bool operator== ( const Maybe< T > &  other) const
inline

Definition at line 112 of file v8-maybe.h.

References Maybe< T >::IsJust().

Referenced by Maybe< T >::operator!=().

◆ To()

template<class T >
V8_WARN_UNUSED_RESULT V8_INLINE bool To ( T *  out) const
inline

Converts this Maybe<> to a value of type T. If this Maybe<> is nothing (empty), |false| is returned and |out| is left untouched.

Definition at line 71 of file v8-maybe.h.

References Maybe< T >::IsJust().

◆ ToChecked()

template<class T >
V8_INLINE T ToChecked ( ) const
inline

An alias for |FromJust|. Will crash if the Maybe<> is nothing.

Definition at line 57 of file v8-maybe.h.

Friends And Related Symbol Documentation

◆ Just [1/2]

template<class T >
template<class U >
Maybe< U > Just ( const U &  u)
friend

◆ Just [2/2]

template<class T >
template<class U , std::enable_if_t<!std::is_lvalue_reference_v< U > > * >
Maybe< U > Just ( U &&  u)
friend

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