v8  7.8.279 (node 12.19.1)
V8 is Google's open source JavaScript engine
Maybe< T > Class Template Reference

#include <v8.h>

Public Member Functions

V8_INLINE bool IsNothing () const
 
V8_INLINE bool IsJust () const
 
V8_INLINEToChecked () const
 
V8_INLINE void Check () const
 
V8_WARN_UNUSED_RESULT V8_INLINE bool To (T *out) const
 
V8_INLINEFromJust () const
 
V8_INLINEFromMaybe (const T &default_value) const
 
V8_INLINE bool operator== (const Maybe &other) const
 
V8_INLINE bool operator!= (const Maybe &other) const
 

Friends

template<class U >
Maybe< U > Nothing ()
 
template<class U >
Maybe< U > Just (const 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 9231 of file v8.h.

Member Function Documentation

◆ Check()

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

References Maybe< T >::IsJust().

◆ FromJust()

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

References Maybe< T >::IsJust().

Referenced by Maybe< T >::operator==(), and Maybe< T >::ToChecked().

◆ FromMaybe()

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

◆ IsJust()

V8_INLINE bool IsJust ( ) const
inline

◆ IsNothing()

V8_INLINE bool IsNothing ( ) const
inline

Definition at line 9233 of file v8.h.

◆ operator!=()

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

Definition at line 9280 of file v8.h.

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

◆ operator==()

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

Definition at line 9275 of file v8.h.

References Maybe< T >::FromJust(), and Maybe< T >::IsJust().

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

◆ To()

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

References Maybe< T >::IsJust().

◆ ToChecked()

V8_INLINE T ToChecked ( ) const
inline

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

Definition at line 9239 of file v8.h.

References Maybe< T >::FromJust().

Friends And Related Function Documentation

◆ Just

Maybe<U> Just ( const U &  u)
friend

◆ Nothing

Maybe<U> Nothing ( )
friend

Definition at line 9298 of file v8.h.


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