Skip to content

Class jac::ArrayBufferWrapper

template <bool managed>

ClassList > jac > ArrayBufferWrapper

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

  • #include <values.h>

Inherits the following classes: jac::ObjectWrapper

Public Functions

Type Name
ArrayBufferWrapper (ObjectWrapper< managed > value)
Wrap an existing JSValue. If managed is true, JSValue will be freed when the ArrayBuffer is destroyed.
ArrayBufferWrapper (ContextRef ctx, JSValue val)
uint8_t * data ()
Get a pointer to the underlying buffer.
size_t size ()
Get the size of the underlying buffer.
std::span< T > typedView ()
Get a typed view of the underlying buffer.

Public Functions inherited from jac::ObjectWrapper

See jac::ObjectWrapper

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 prop, 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
ArrayBuffer create (ContextRef ctx, size_t size)
Create a new ArrayBuffer object.
ArrayBuffer create (ContextRef ctx, std::span< const uint8_t > data)
Create a new ArrayBuffer object.

Public Static Functions inherited from jac::ObjectWrapper

See jac::ObjectWrapper

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

Protected Static Functions

Type Name
void freeArrayBuffer (JSRuntime * rt, void * opaque, void * ptr)

Detailed Description

Template parameters:

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

Public Functions Documentation

function ArrayBufferWrapper [1/2]

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

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

Note:

Used internally when directly working with QuickJS API. New ArrayBuffer should be created using ArrayBuffer::create().

Parameters:

  • ctx context to work in
  • val JSValue to wrap

function ArrayBufferWrapper [2/2]

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

function data

Get a pointer to the underlying buffer.

inline uint8_t * jac::ArrayBufferWrapper::data () 

Returns:

Pointer to the data

function size

Get the size of the underlying buffer.

inline size_t jac::ArrayBufferWrapper::size () 

Returns:

Size of the data

function typedView

Get a typed view of the underlying buffer.

template<typename T typename T>
inline std::span< T > jac::ArrayBufferWrapper::typedView () 

Template parameters:

  • T Type of the view

Returns:

Typed view of the data

Public Static Functions Documentation

function create [1/2]

Create a new ArrayBuffer object.

static inline ArrayBuffer jac::ArrayBufferWrapper::create (
    ContextRef ctx,
    size_t size
) 

Parameters:

  • ctx context to work in
  • size size of the buffer

Returns:

The new ArrayBuffer object

function create [2/2]

Create a new ArrayBuffer object.

static inline ArrayBuffer jac::ArrayBufferWrapper::create (
    ContextRef ctx,
    std::span< const uint8_t > data
) 

Parameters:

  • ctx context to work in
  • data data to copy into the buffer

Returns:

The new ArrayBuffer object

Protected Static Functions Documentation

function freeArrayBuffer

static inline void jac::ArrayBufferWrapper::freeArrayBuffer (
    JSRuntime * rt,
    void * opaque,
    void * ptr
) 

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