Loading...
Searching...
No Matches
JSArray

#include <AppCore/JSHelpers.h>

Overview

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]

JSArray ( )

Create empty Array.

◆ JSArray() [2/5]

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

Create Array from list of JSValues.

◆ JSArray() [3/5]

JSArray ( JSObjectRef array_obj)

Create Array from existing JSObjectRef (JavaScriptCore C API)

◆ JSArray() [4/5]

JSArray ( const JSArray & other)

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

◆ ~JSArray()

~JSArray ( )

◆ JSArray() [5/5]

JSArray ( JSContextRef ctx,
JSValueRef val )
protected

Member Function Documentation

◆ context()

JSContextRef context ( ) const
inline

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

◆ indexOf()

int indexOf ( const JSValue & val,
int start = 0 ) const

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

◆ length()

unsigned length ( )

Get number of elements in the Array.

◆ operator JSObjectRef()

operator JSObjectRef ( ) const
inline

Get the underlying JSObjectRef (JavaScriptCore C API)

◆ operator=()

JSArray & operator= ( const JSArray & other)

Assignment (shallow assignment, will point to same instance)

◆ operator[]()

JSPropertyValue operator[] ( unsigned idx) const

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

◆ push()

void push ( const JSValue & val)

Push an element to back of Array.

◆ set_context()

void 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 ctx_
protected

◆ instance_

JSObjectRef instance_
protected

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