Skip to content

Class jac::ValueWrapper

template <bool managed>

ClassList > jac > ValueWrapper

A wrapper around JSValue with RAII. More...

  • #include <values.h>

Inherited by the following classes: jac::ExceptionWrapper, jac::ObjectWrapper

Public Functions

Type Name
ValueWrapper (ContextRef ctx, JSValue val)
Wrap an existing JSValue. If managed is true, JSValue will be freed when the Value is destroyed.
ValueWrapper (const ValueWrapper & other)
ValueWrapper (ValueWrapper && other)
JSValue & getVal ()
Get reference to the underlying JSValue.
bool isArray ()
Check if the Value is an array.
bool isFunction ()
Check if the Value is a function.
bool isNull ()
Check if the Value is null.
bool isObject ()
Check if the Value is an object.
bool isUndefined ()
Check if the Value is undefined.
std::pair< ContextRef, JSValue > loot ()
Release ownership of the JSValue. The JSValue will have to be freed manually.
operator ValueWeak ()
ValueWrapper & operator= (const ValueWrapper & other)
ValueWrapper & operator= (ValueWrapper && other)
Value stringify (int indent=0)
Convert the Value to a JSON representation.
T to ()
Convert the Value to a specified type.
StringView toString ()
Convert the Value to a StringView .
~ValueWrapper ()

Public Static Functions

Type Name
Value from (ContextRef ctx, T val)
Create a new Value by converting a given value.
Value fromJSON (ContextRef ctx, std::string json, std::string filename="<json>", bool extended=false)
Create a new Value from a given JSON string.
Value null (ContextRef ctx)
Create a new Value containing null.
Value undefined (ContextRef ctx)
Create a new Value containing undefined.

Protected Attributes

Type Name
ContextRef _ctx
JSValue _val

Detailed Description

Template parameters:

  • managed whether the JSValue should be freed when the wrapper is destroyed.

Public Functions Documentation

function ValueWrapper [1/3]

Wrap an existing JSValue. If managed is true, JSValue will be freed when the Value is destroyed.

jac::ValueWrapper::ValueWrapper (
    ContextRef ctx,
    JSValue val
) 

Note:

Used internally when directly working with QuickJS API. New Value should be created using Value::from<T>(), Value::undefined(), etc.

Parameters:

  • ctx context to work in
  • val JSValue to wrap

function ValueWrapper [2/3]

inline jac::ValueWrapper::ValueWrapper (
    const ValueWrapper & other
) 

function ValueWrapper [3/3]

inline jac::ValueWrapper::ValueWrapper (
    ValueWrapper && other
) 

function getVal

Get reference to the underlying JSValue.

inline JSValue & jac::ValueWrapper::getVal () 

Returns:

JSValue reference


function isArray

Check if the Value is an array.

inline bool jac::ValueWrapper::isArray () 

Returns:

true if the Value is an array, false otherwise


function isFunction

Check if the Value is a function.

inline bool jac::ValueWrapper::isFunction () 

Returns:

true if the Value is a function, false otherwise


function isNull

Check if the Value is null.

inline bool jac::ValueWrapper::isNull () 

Returns:

true if the Value is null, false otherwise


function isObject

Check if the Value is an object.

inline bool jac::ValueWrapper::isObject () 

Returns:

true if the Value is an object, false otherwise


function isUndefined

Check if the Value is undefined.

inline bool jac::ValueWrapper::isUndefined () 

Returns:

true if the Value is undefined, false otherwise


function loot

Release ownership of the JSValue. The JSValue will have to be freed manually.

inline std::pair< ContextRef , JSValue > jac::ValueWrapper::loot () 

Note:

After this call, the Value is in an undefined state.

Returns:

Pair of ContextRef and JSValue


function operator ValueWeak

inline jac::ValueWrapper::operator ValueWeak () 

function operator=

inline ValueWrapper & jac::ValueWrapper::operator= (
    const ValueWrapper & other
) 

function operator=

inline ValueWrapper & jac::ValueWrapper::operator= (
    ValueWrapper && other
) 

function stringify

Convert the Value to a JSON representation.

inline Value jac::ValueWrapper::stringify (
    int indent=0
) 

Parameters:

  • indent indentation level

Returns:

Value containing the JSON representation


function to

Convert the Value to a specified type.

template<typename T>
inline T jac::ValueWrapper::to () 

Template parameters:

  • T Type to convert to

Returns:

The converted value


function toString

Convert the Value to a StringView .

inline StringView jac::ValueWrapper::toString () 

Returns:

The StringView


function ~ValueWrapper

inline jac::ValueWrapper::~ValueWrapper () 

Public Static Functions Documentation

function from

Create a new Value by converting a given value.

template<typename T>
static inline Value jac::ValueWrapper::from (
    ContextRef ctx,
    T val
) 

Template parameters:

  • T Type of the value

Parameters:

  • ctx context to work in
  • val value to convert

Returns:

The resulting Value


function fromJSON

Create a new Value from a given JSON string.

static inline Value jac::ValueWrapper::fromJSON (
    ContextRef ctx,
    std::string json,
    std::string filename="<json>",
    bool extended=false
) 

Parameters:

  • ctx context to work in
  • json JSON string
  • filename filename to use as the source of the JSON
  • extended whether to use extended JSON

Returns:

The resulting Value


function null

Create a new Value containing null.

static inline Value jac::ValueWrapper::null (
    ContextRef ctx
) 

Parameters:

  • ctx context to work in

Returns:

The resulting Value


function undefined

Create a new Value containing undefined.

static inline Value jac::ValueWrapper::undefined (
    ContextRef ctx
) 

Parameters:

  • ctx context to work in

Returns:

The resulting Value


Protected Attributes Documentation

variable _ctx

ContextRef jac::ValueWrapper< managed >::_ctx;

variable _val

JSValue jac::ValueWrapper< managed >::_val;

Friends Documentation

friend operator<<

inline std::ostream & jac::ValueWrapper::operator<< (
    std::ostream & os,
    ValueWrapper & val
) 


The documentation for this class was generated from the following file src/jac/machine/values.h