Loading...
Searching...
No Matches
JSValue

#include <AppCore/JSHelpers.h>

Overview

JavaScript variant value wrapper that automatically manages JSValueRef lifetime and provides helpful conversions.

Inheritance diagram for JSValue:
JSPropertyValue

Public Member Functions

 JSValue ()
 Create null (empty) JSValue.
 
 JSValue (JSValueNullTag)
 Create null JSValue explicitly.
 
 JSValue (JSValueUndefinedTag)
 Create undefined JSValue.
 
 JSValue (bool val)
 Create boolean JSValue.
 
 JSValue (uint32_t val)
 Create unsigned integer JSValue (aka, Number) [will be cast to double].
 
 JSValue (int32_t val)
 Create integer JSValue (aka, Number) [will be cast to double].
 
 JSValue (uint64_t val)
 Create unsigned integer JSValue (aka, Number) [will be cast to double].
 
 JSValue (int64_t val)
 Create integer JSValue (aka, Number) [will be cast to double].
 
 JSValue (double val)
 Create double JSValue (aka, Number)
 
 JSValue (const char *val)
 Create string JSValue.
 
 JSValue (const String &val)
 Create string JSValue.
 
 JSValue (JSString val)
 Create string JSValue.
 
 JSValue (JSValueRef val)
 Create from existing JSValueRef.
 
 JSValue (JSObjectRef obj)
 Create object JSValue.
 
 JSValue (const JSValue &other)
 Copy constructor, a shallow copy is made, the constructed JSValue will point to the same JSValueRef.
 
virtual ~JSValue ()
 Destructor.
 
virtual JSValueoperator= (const JSValue &other)
 A shallow copy is made, this JSValue will point to the same JSValueRef.
 
bool IsNull () const
 Whether or not the value is a JavaScript Null type.
 
bool IsUndefined () const
 Whether or not the value is a JavaScript Undefined type.
 
bool IsBoolean () const
 Whether or not the value is a JavaScript Boolean type.
 
bool IsNumber () const
 Whether or not the value is a JavaScript Number type.
 
bool IsString () const
 Whether or not the value is a JavaScript String type.
 
bool IsObject () const
 Whether or not the value is a JavaScript Object type.
 
bool IsArray () const
 Whether or not the value is a JavaScript Array type.
 
bool IsFunction () const
 Whether or not the value is a JavaScript Function type.
 
bool ToBoolean () const
 Get the value as a Boolean.
 
double ToNumber () const
 Get the value as a Number (Double)
 
int64_t ToInteger () const
 Get the value as a Number (Integer)
 
JSString ToString () const
 Get the value as a String.
 
JSObject ToObject () const
 Get the value as an Object (will debug assert if not an Object)
 
JSArray ToArray () const
 Get the value as an Array (will debug asset if not an Array)
 
JSFunction ToFunction () const
 Get the value as a Function (will debug asset if not a Function)
 
 operator bool () const
 
 operator double () const
 
 operator uint32_t () const
 
 operator int32_t () const
 
 operator uint64_t () const
 
 operator int64_t () const
 
 operator String () const
 
 operator JSString () const
 
 operator JSObject () const
 
 operator JSObjectRef () const
 
 operator JSArray () const
 
 operator JSFunction () const
 
 operator JSValueRef () const
 Get the underlying JSValueRef.
 
JSContextRef context () const
 Get the bound context for this JSValue (it is cached at creation).
 
void set_context (JSContextRef context)
 Set the JSContext for this JSValue.
 

Protected Member Functions

 JSValue (JSContextRef ctx)
 
 JSValue (JSContextRef ctx, JSValueRef val)
 
virtual JSValueRef instance () const
 

Protected Attributes

JSContextRef ctx_
 
JSValueRef instance_ = nullptr
 

Friends

class JSFunction
 

Constructor & Destructor Documentation

◆ JSValue() [1/17]

JSValue ( )

Create null (empty) JSValue.

◆ JSValue() [2/17]

Create null JSValue explicitly.

◆ JSValue() [3/17]

Create undefined JSValue.

◆ JSValue() [4/17]

JSValue ( bool val)

Create boolean JSValue.

◆ JSValue() [5/17]

JSValue ( uint32_t val)

Create unsigned integer JSValue (aka, Number) [will be cast to double].

◆ JSValue() [6/17]

JSValue ( int32_t val)

Create integer JSValue (aka, Number) [will be cast to double].

◆ JSValue() [7/17]

JSValue ( uint64_t val)

Create unsigned integer JSValue (aka, Number) [will be cast to double].

◆ JSValue() [8/17]

JSValue ( int64_t val)

Create integer JSValue (aka, Number) [will be cast to double].

◆ JSValue() [9/17]

JSValue ( double val)

Create double JSValue (aka, Number)

◆ JSValue() [10/17]

JSValue ( const char * val)

Create string JSValue.

◆ JSValue() [11/17]

JSValue ( const String & val)

Create string JSValue.

◆ JSValue() [12/17]

JSValue ( JSString val)

Create string JSValue.

◆ JSValue() [13/17]

Create from existing JSValueRef.

◆ JSValue() [14/17]

Create object JSValue.

◆ JSValue() [15/17]

JSValue ( const JSValue & other)

Copy constructor, a shallow copy is made, the constructed JSValue will point to the same JSValueRef.

◆ ~JSValue()

virtual ~JSValue ( )
virtual

Destructor.

◆ JSValue() [16/17]

JSValue ( JSContextRef ctx)
protected

◆ JSValue() [17/17]

JSValue ( JSContextRef ctx,
JSValueRef val )
protected

Member Function Documentation

◆ context()

JSContextRef context ( ) const
inline

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

◆ instance()

virtual JSValueRef instance ( ) const
protectedvirtual

Reimplemented in JSPropertyValue.

◆ IsArray()

bool IsArray ( ) const

Whether or not the value is a JavaScript Array type.

◆ IsBoolean()

bool IsBoolean ( ) const

Whether or not the value is a JavaScript Boolean type.

◆ IsFunction()

bool IsFunction ( ) const

Whether or not the value is a JavaScript Function type.

◆ IsNull()

bool IsNull ( ) const

Whether or not the value is a JavaScript Null type.

◆ IsNumber()

bool IsNumber ( ) const

Whether or not the value is a JavaScript Number type.

◆ IsObject()

bool IsObject ( ) const

Whether or not the value is a JavaScript Object type.

◆ IsString()

bool IsString ( ) const

Whether or not the value is a JavaScript String type.

◆ IsUndefined()

bool IsUndefined ( ) const

Whether or not the value is a JavaScript Undefined type.

◆ operator bool()

operator bool ( ) const
inline

◆ operator double()

operator double ( ) const
inline

◆ operator int32_t()

operator int32_t ( ) const
inline

◆ operator int64_t()

operator int64_t ( ) const
inline

◆ operator JSArray()

operator JSArray ( ) const

◆ operator JSFunction()

operator JSFunction ( ) const

◆ operator JSObject()

operator JSObject ( ) const

◆ operator JSObjectRef()

operator JSObjectRef ( ) const

◆ operator JSString()

operator JSString ( ) const
inline

◆ operator JSValueRef()

operator JSValueRef ( ) const
inline

Get the underlying JSValueRef.

◆ operator String()

operator String ( ) const
inline

◆ operator uint32_t()

operator uint32_t ( ) const
inline

◆ operator uint64_t()

operator uint64_t ( ) const
inline

◆ operator=()

virtual JSValue & operator= ( const JSValue & other)
virtual

A shallow copy is made, this JSValue will point to the same JSValueRef.

Reimplemented in JSPropertyValue.

◆ set_context()

void set_context ( JSContextRef context)
inline

Set the JSContext for this JSValue.

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

◆ ToArray()

JSArray ToArray ( ) const

Get the value as an Array (will debug asset if not an Array)

◆ ToBoolean()

bool ToBoolean ( ) const

Get the value as a Boolean.

◆ ToFunction()

JSFunction ToFunction ( ) const

Get the value as a Function (will debug asset if not a Function)

◆ ToInteger()

int64_t ToInteger ( ) const
inline

Get the value as a Number (Integer)

◆ ToNumber()

double ToNumber ( ) const

Get the value as a Number (Double)

◆ ToObject()

JSObject ToObject ( ) const

Get the value as an Object (will debug assert if not an Object)

◆ ToString()

JSString ToString ( ) const

Get the value as a String.

Friends And Related Symbol Documentation

◆ JSFunction

friend class JSFunction
friend

Member Data Documentation

◆ ctx_

JSContextRef ctx_
protected

◆ instance_

JSValueRef instance_ = nullptr
protected

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