Ultralight C++ API 1.3.0
Loading...
Searching...
No Matches
ultralight::JSArray Class Reference

#include <AppCore/JSHelpers.h>

Details

JSArray wrapper that automatically manages lifetime and provides convenient access to indices and Array functions.

Public Member Functions

 JSArray ()
 Create empty Array.
 
 JSArray (const std::initializer_list< JSValue > &values)
 Create Array from list of JSValues.
 
 JSArray (JSObjectRef array_obj)
 Create Array from existing JSObjectRef (JavaScriptCore C API)
 
 JSArray (const JSArray &other)
 Copy constructor (shallow copy, will point to same instance)
 
 ~JSArray ()
 
JSArrayoperator= (const JSArray &other)
 Assignment (shallow assignment, will point to same instance)
 
unsigned length ()
 Get number of elements in the Array.
 
void push (const JSValue &val)
 Push an element to back of Array.
 
int indexOf (const JSValue &val, int start=0) const
 Find the index (location) of a certain value, will return -1 if not found.
 
JSPropertyValue operator[] (unsigned idx) const
 Get a property by array index (numbering starts at 0)
 
 operator JSObjectRef () const
 Get the underlying JSObjectRef (JavaScriptCore C API)
 
JSContextRef context () const
 Get the bound context for this JSArray (it is cached at creation).
 
void set_context (JSContextRef context)
 Set the JSContext for this JSArray.
 

Protected Member Functions

 JSArray (JSContextRef ctx, JSValueRef val)
 

Protected Attributes

JSContextRef ctx_
 
JSObjectRef instance_
 

Friends

class JSValue
 

Constructor & Destructor Documentation

◆ JSArray() [1/5]

ultralight::JSArray::JSArray ( )

Create empty Array.

◆ JSArray() [2/5]

ultralight::JSArray::JSArray ( const std::initializer_list< JSValue > &  values)

Create Array from list of JSValues.

◆ JSArray() [3/5]

ultralight::JSArray::JSArray ( JSObjectRef  array_obj)

Create Array from existing JSObjectRef (JavaScriptCore C API)

◆ JSArray() [4/5]

ultralight::JSArray::JSArray ( const JSArray other)

Copy constructor (shallow copy, will point to same instance)

◆ ~JSArray()

ultralight::JSArray::~JSArray ( )

◆ JSArray() [5/5]

ultralight::JSArray::JSArray ( JSContextRef  ctx,
JSValueRef  val 
)
protected

Member Function Documentation

◆ context()

JSContextRef ultralight::JSArray::context ( ) const
inline

Get the bound context for this JSArray (it is cached at creation).

◆ indexOf()

int ultralight::JSArray::indexOf ( const JSValue val,
int  start = 0 
) const

Find the index (location) of a certain value, will return -1 if not found.

◆ length()

unsigned ultralight::JSArray::length ( )

Get number of elements in the Array.

◆ operator JSObjectRef()

ultralight::JSArray::operator JSObjectRef ( ) const
inline

Get the underlying JSObjectRef (JavaScriptCore C API)

◆ operator=()

JSArray & ultralight::JSArray::operator= ( const JSArray other)

Assignment (shallow assignment, will point to same instance)

◆ operator[]()

JSPropertyValue ultralight::JSArray::operator[] ( unsigned  idx) const

Get a property by array index (numbering starts at 0)

◆ push()

void ultralight::JSArray::push ( const JSValue val)

Push an element to back of Array.

◆ set_context()

void ultralight::JSArray::set_context ( JSContextRef  context)
inline

Set the JSContext for this JSArray.

Note: JSArrays created from within a JSCallback have a temporary JSContext that is destroyed when the callback returns. You will need to "move" any JSArrays created within these callbacks to the View's main context (call set_context() with the main context) before using them outside the callback.

Friends And Related Symbol Documentation

◆ JSValue

friend class JSValue
friend

Member Data Documentation

◆ ctx_

JSContextRef ultralight::JSArray::ctx_
protected

◆ instance_

JSObjectRef ultralight::JSArray::instance_
protected

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