docs
Loading...
Searching...
No Matches
Arg

#include <Ultralight/js/Value.h>

Overview

An argument passed to a bound function.

An Arg is only valid during the callback that received it (it adds no reference, so reading it is cheap). Call ToValue() to keep the argument after the callback returns.

An Arg has To(), Maybe(), and Or(). Other conversions need a Value first (eg, arg.ToValue().ToNumber()).

See also
CallInfo::arg()

Public Member Functions

 Arg (ULJSValue borrowed)
 Wrap a borrowed handle.
bool IsEmpty () const
 Whether or not the argument is absent (the call passed fewer arguments than the index given to CallInfo::arg()).
Type type () const
 Get the argument's type (Type::Invalid if the argument is absent).
template<typename T>
Result< T > To () const
 Convert to a C++ type (see Value::To()).
template<typename T>
std::optional< T > Maybe () const
 Convert to a C++ type like To() but without the failure reason.
template<typename T>
T Or (T fallback) const
 Convert to a C++ type like To() but with a fallback.
std::string Or (const char *fallback) const
 Convert to a std::string like To() but with a string-literal fallback.
Value ToValue () const
 Get a Value that keeps the argument after the callback returns.
ULJSValue raw () const
 Get the C API handle.

Constructor & Destructor Documentation

◆ Arg()

Arg ( ULJSValue borrowed)
inlineexplicit

Wrap a borrowed handle.

Parameters
borrowedThe handle (valid only during the callback).
Note
You normally get an Arg from CallInfo::arg() instead of creating one.

Member Function Documentation

◆ IsEmpty()

bool IsEmpty ( ) const
inline

Whether or not the argument is absent (the call passed fewer arguments than the index given to CallInfo::arg()).

Note
An absent argument converts only to an optional type (as an empty optional). Any other To() fails with a TypeError, and ToValue() returns an empty Value.

◆ Maybe()

template<typename T>
std::optional< T > Maybe ( ) const
nodiscard

Convert to a C++ type like To() but without the failure reason.

Returns
Returns the converted value or nullopt on any failure.

◆ Or() [1/2]

std::string Or ( const char * fallback) const
nodiscard

Convert to a std::string like To() but with a string-literal fallback.

Parameters
fallbackThe text to return if the conversion fails.
Returns
Returns the converted string or fallback on any failure.

◆ Or() [2/2]

template<typename T>
T Or ( T fallback) const
nodiscard

Convert to a C++ type like To() but with a fallback.

Parameters
fallbackThe value to return if the conversion fails.
Returns
Returns the converted value or fallback on any failure.

◆ raw()

ULJSValue raw ( ) const
inline

Get the C API handle.

Returns
Returns the handle (valid only during the callback).

◆ To()

template<typename T>
Result< T > To ( ) const
nodiscard

Convert to a C++ type (see Value::To()).

Returns
Returns the converted value and fails the same way as Value::To().
Note
Requires <Ultralight/js/TypeTraits.h> (or any header that includes it).

◆ ToValue()

Value ToValue ( ) const
inline

Get a Value that keeps the argument after the callback returns.

Returns
Returns the new Value.

◆ type()

Type type ( ) const
inline

Get the argument's type (Type::Invalid if the argument is absent).


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