Skip to content

Class jac::ObjectWrapper

template <bool managed>

ClassList > jac > ObjectWrapper

A wrapper for JSValue with Object type with RAII. More...

  • #include <values.h>

Inherits the following classes: jac::ValueWrapper

Inherited by the following classes: jac::ArrayBufferWrapper, jac::ArrayWrapper, jac::FunctionWrapper, jac::PromiseWrapper

Public Functions

Type Name
ObjectWrapper (ValueWrapper< managed > value)
Wrap an existing JSValue. If managed is true, JSValue will be freed when the Object is destroyed.
ObjectWrapper (ContextRef ctx, JSValue val)
void defineProperty (Id id, Value value, PropFlags flags=PropFlags::Default)
Define a property of the object.
void deleteProperty (Id id)
Delete a property of the object.
T get (Atom prop)
Get a property of the object.
T get (const std::string & name)
T get (uint32_t idx)
Object getPrototype ()
Get the prototype of the object.
bool hasProperty (Id id)
Check if the object has a property.
Res invoke (Atom key, Args... args)
Invoke a method of the object.
Res invoke (const std::string & key, Args... args)
Res invoke (uint32_t idx, Args... args)
void set (Atom prop, T val)
Set a property of the object.
void set (const std::string & name, T val)
void set (uint32_t idx, T val)
void setPrototype (Object proto)
Set the prototype of the object.

Public Functions inherited from jac::ValueWrapper

See jac::ValueWrapper

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
Object create (ContextRef ctx)
Create a new empty object.

Public Static Functions inherited from jac::ValueWrapper

See jac::ValueWrapper

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 inherited from jac::ValueWrapper

See jac::ValueWrapper

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 ObjectWrapper [1/2]

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

inline jac::ObjectWrapper::ObjectWrapper (
    ValueWrapper < managed > value
) 

Note:

Used internally when directly working with QuickJS API. New Object should be created using Object::create() or by converting an existing Value to an Object using Value::to<Object>().

Parameters:

  • ctx context to work in
  • val JSValue to wrap

function ObjectWrapper [2/2]

inline jac::ObjectWrapper::ObjectWrapper (
    ContextRef ctx,
    JSValue val
) 

function defineProperty

Define a property of the object.

template<typename Id>
inline void jac::ObjectWrapper::defineProperty (
    Id id,
    Value value,
    PropFlags flags=PropFlags::Default
) 

Template parameters:

  • Id the type of the property identifier (Atom, std::string, uint32_t)

Parameters:

  • id the property identifier
  • value the value to set
  • flags the property flags

function deleteProperty

Delete a property of the object.

template<typename Id>
inline void jac::ObjectWrapper::deleteProperty (
    Id id
) 

Template parameters:

  • Id the type of the property identifier (Atom, std::string, uint32_t)

Parameters:

  • id the property identifier

function get [1/3]

Get a property of the object.

template<typename T>
inline T jac::ObjectWrapper::get (
    Atom prop
) 

Template parameters:

  • T type to convert the property to

Parameters:

  • prop the property identifier

Returns:

The resulting value


function get [2/3]

template<typename T>
inline T jac::ObjectWrapper::get (
    const std::string & name
) 

function get [3/3]

template<typename T>
inline T jac::ObjectWrapper::get (
    uint32_t idx
) 

function getPrototype

Get the prototype of the object.

inline Object jac::ObjectWrapper::getPrototype () 

Returns:

The prototype


function hasProperty

Check if the object has a property.

template<typename Id>
inline bool jac::ObjectWrapper::hasProperty (
    Id id
) 

Template parameters:

  • Id the type of the property identifier (Atom, std::string, uint32_t)

Parameters:

  • id the property identifier

Returns:

true if the object has the property, false otherwise


function invoke [1/3]

Invoke a method of the object.

template<typename Res, typename... Args>
Res jac::ObjectWrapper::invoke (
    Atom key,
    Args... args
) 

Note:

The call will automatically convert the arguments to their JavaScript counterparts, the result will be converted to the specified type and Exceptions thrown in JS will be propagated to C++ as jac::Exception.

Template parameters:

  • Res type to convert the result to
  • Args types of the arguments

Parameters:

  • prop the property identifier
  • args the arguments

Returns:

The resulting value


function invoke [2/3]

template<typename Res, typename... Args>
inline Res jac::ObjectWrapper::invoke (
    const std::string & key,
    Args... args
) 

function invoke [3/3]

template<typename Res, typename... Args>
inline Res jac::ObjectWrapper::invoke (
    uint32_t idx,
    Args... args
) 

function set [1/3]

Set a property of the object.

template<typename T>
inline void jac::ObjectWrapper::set (
    Atom prop,
    T val
) 

Template parameters:

  • T type of the value to set

Parameters:

  • prop the property identifier
  • val the value to set

function set [2/3]

template<typename T>
inline void jac::ObjectWrapper::set (
    const std::string & name,
    T val
) 

function set [3/3]

template<typename T>
inline void jac::ObjectWrapper::set (
    uint32_t idx,
    T val
) 

function setPrototype

Set the prototype of the object.

inline void jac::ObjectWrapper::setPrototype (
    Object proto
) 

Parameters:

  • proto the prototype

Public Static Functions Documentation

function create

Create a new empty object.

static inline Object jac::ObjectWrapper::create (
    ContextRef ctx
) 

Parameters:

  • ctx the context to create the object in

Returns:

The new object



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