171 int64_t
ToInteger()
const {
return static_cast<int64_t
>(ToNumber()); }
185 operator bool()
const {
return ToBoolean(); }
187 operator double()
const {
return ToNumber(); }
189 operator uint32_t()
const {
return static_cast<uint32_t
>(ToNumber()); }
191 operator int32_t()
const {
return static_cast<uint32_t
>(ToNumber()); }
193 operator uint64_t()
const {
return static_cast<uint64_t
>(ToNumber()); }
195 operator int64_t()
const {
return ToInteger(); }
197 operator String()
const {
return ToString(); }
248 JSArgs(
const std::initializer_list<JSValue>& values);
328#define BindJSCallback(fn) (JSCallback)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
338#define BindJSCallbackWithRetval(fn) (JSCallbackWithRetval)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
383 JSArray(
const std::initializer_list<JSValue>& values);
#define AExport
Definition Defines.h:42
struct OpaqueJSString * JSStringRef
Definition JSBase.h:49
struct OpaqueJSValue * JSObjectRef
Definition JSBase.h:69
const struct OpaqueJSValue * JSValueRef
Definition JSBase.h:66
const struct OpaqueJSContext * JSContextRef
Definition JSBase.h:43
A vector of JSValues, used for passing around arguments in JSCallback.
Definition JSHelpers.h:242
JSValue operator[](size_t pos)
Access an element of the argument list by index.
bool empty() const
Whether or not the argument list is empty.
JSArgs(const JSArgs &other)
Copy-constructor.
void push_back(const JSValue &val)
Add a new argument to the end of the list.
void clear()
Clear the argument list.
void * instance_
Definition JSHelpers.h:300
const JSValue * data() const
Get the argument list as a C-array of JSValues (const overload)
JSArgs & operator=(const JSArgs &other)
Assignment operator.
JSValue * data()
Get the argument list as a C-array of JSValues.
JSArgs(const std::initializer_list< JSValue > &values)
Create a list of JavaScript arguments using a C++ initializer list.
const JSValue operator[](size_t pos) const
Access an element of the argument list by index.
JSArgs()
Create an empty list of JavaScript arguments.
size_t size() const
The number of elements in the argument list.
void pop_back()
Remove the last item from the end of the list.
JSArray wrapper that automatically manages lifetime and provides convenient access to indices and Arr...
Definition JSHelpers.h:377
JSArray()
Create empty Array.
unsigned length()
Get number of elements in the Array.
JSObjectRef instance_
Definition JSHelpers.h:432
JSPropertyValue operator[](unsigned idx) const
Get a property by array index (numbering starts at 0)
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(const std::initializer_list< JSValue > &values)
Create Array from list of JSValues.
void push(const JSValue &val)
Push an element to back of Array.
JSArray(JSContextRef ctx, JSValueRef val)
JSArray & operator=(const JSArray &other)
Assignment (shallow assignment, will point to same instance)
JSContextRef context() const
Get the bound context for this JSArray (it is cached at creation).
Definition JSHelpers.h:414
JSContextRef ctx_
Definition JSHelpers.h:431
int indexOf(const JSValue &val, int start=0) const
Find the index (location) of a certain value, will return -1 if not found.
void set_context(JSContextRef context)
Set the JSContext for this JSArray.
Definition JSHelpers.h:426
JSFunction wrapper that automatically manages lifetime and provides convenient function invocation op...
Definition JSHelpers.h:499
JSFunction & operator=(const JSFunction &other)
Assignment (shallow assignment, will point to same instance)
bool IsValid() const
Whether or not this is a valid, callable Function object.
JSFunction(JSContextRef ctx, JSValueRef val)
JSFunction()
Create an empty Function.
void set_context(JSContextRef context)
Set the JSContext for this JSFunction.
Definition JSHelpers.h:540
JSValue operator()(const JSArgs &args)
Call function (using Global Object for 'this') and return the result.
JSContextRef ctx_
Definition JSHelpers.h:545
JSObjectRef instance_
Definition JSHelpers.h:546
JSFunction(const JSFunction &other)
Copy constructor (shallow copy, will point to same instance)
JSContextRef context() const
Get the bound context for this JSFunction (it is cached at creation).
Definition JSHelpers.h:528
JSValue operator()(const JSObject &thisObject, const JSArgs &args)
Call function (with explicit object for 'this') and return the result.
JSObject wrapper that automatically manages lifetime and provides convenient access to properties.
Definition JSHelpers.h:440
JSObjectRef instance_
Definition JSHelpers.h:490
JSObject(JSContextRef ctx, JSObjectRef obj)
JSObject(JSContextRef ctx, JSValueRef val)
void set_context(JSContextRef context)
Set the JSContext for this JSObject.
Definition JSHelpers.h:483
JSContextRef ctx_
Definition JSHelpers.h:489
bool DeleteProperty(JSString propertyName)
Remove a property.
JSObject()
Create empty Object.
JSObject(JSObjectRef obj)
Create from existing JSObjectRef from JavaScriptCore C API.
JSObject & operator=(const JSObject &other)
Assignment (shallow assignment, will point to same instance)
JSContextRef context() const
Get the bound context for this JSObject (it is cached at creation).
Definition JSHelpers.h:471
JSObject(const JSObject &other)
Copy constructor (shallow copy, will point to same instance)
JSPropertyValue operator[](JSString propertyName) const
Get a property by name.
bool HasProperty(JSString propertyName) const
Check if a property exists.
Wrapper for JSObject property value (JSValue subclass).
Definition JSHelpers.h:345
virtual ~JSPropertyValue()
JSString string_idx_
Definition JSHelpers.h:368
JSPropertyValue & operator=(const JSCallback &callback)
Bind to native C++ callback (creates a Function object that can be called from JS)
JSPropertyValue(const JSPropertyValue &)=default
virtual JSPropertyValue & operator=(const JSValue &value)
Assign a new value to the property (internally calls JSObjectSetProperty)
JSPropertyValue & operator=(const JSCallbackWithRetval &callback)
Bind to native C++ callback with return value (creates a Function object that can be called from JS)
JSPropertyValue & operator=(const JSPropertyValue &)=delete
unsigned numeric_idx_
Definition JSHelpers.h:367
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, unsigned idx)
virtual JSValueRef instance() const
bool using_numeric_idx_
Definition JSHelpers.h:366
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, JSString idx)
JSObject * proxyObj_
Definition JSHelpers.h:365
JavaScript String wrapper that automatically manages JSStringRef lifetime and provides helpful conver...
Definition JSHelpers.h:39
JSStringRef instance_
Definition JSHelpers.h:69
JSString(const JSString &other)
Copy constructor.
JSString(const char *str)
Create from C-string.
JSString()
Create empty string.
JSString(JSStringRef str)
Create from existing JSStringRef.
JSString(const String &str)
Create from Ultralight String.
JSString & operator=(const JSString &other)
Assignment operator.
JavaScript variant value wrapper that automatically manages JSValueRef lifetime and provides helpful ...
Definition JSHelpers.h:86
bool IsBoolean() const
Whether or not the value is a JavaScript Boolean type.
virtual JSValue & operator=(const JSValue &other)
A shallow copy is made, this JSValue will point to the same JSValueRef.
JSValue(const JSValue &other)
Copy constructor, a shallow copy is made, the constructed JSValue will point to the same JSValueRef.
JSValue(JSValueRef val)
Create from existing JSValueRef.
JSValue()
Create null (empty) JSValue.
JSValue(JSValueNullTag)
Create null JSValue explicitly.
JSValue(uint64_t val)
Create unsigned integer JSValue (aka, Number) [will be cast to double].
bool IsString() const
Whether or not the value is a JavaScript String type.
JSValue(bool val)
Create boolean JSValue.
int64_t ToInteger() const
Get the value as a Number (Integer)
Definition JSHelpers.h:171
bool IsNumber() const
Whether or not the value is a JavaScript Number type.
JSString ToString() const
Get the value as a String.
void set_context(JSContextRef context)
Set the JSContext for this JSValue.
Definition JSHelpers.h:227
bool IsObject() const
Whether or not the value is a JavaScript Object type.
JSValue(uint32_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].
bool IsNull() const
Whether or not the value is a JavaScript Null type.
JSContextRef context() const
Get the bound context for this JSValue (it is cached at creation).
Definition JSHelpers.h:215
JSObject ToObject() const
Get the value as an Object (will debug assert if not an Object)
JSValue(int32_t val)
Create integer JSValue (aka, Number) [will be cast to double].
virtual JSValueRef instance() const
JSValue(JSContextRef ctx)
JSValue(const char *val)
Create string JSValue.
JSFunction ToFunction() const
Get the value as a Function (will debug asset if not a Function)
JSArray ToArray() const
Get the value as an Array (will debug asset if not an Array)
bool ToBoolean() const
Get the value as a Boolean.
bool IsArray() const
Whether or not the value is a JavaScript Array type.
JSValue(JSObjectRef obj)
Create object JSValue.
double ToNumber() const
Get the value as a Number (Double)
bool IsUndefined() const
Whether or not the value is a JavaScript Undefined type.
JSValue(const String &val)
Create string JSValue.
JSValue(JSValueUndefinedTag)
Create undefined JSValue.
JSValue(double val)
Create double JSValue (aka, Number)
bool IsFunction() const
Whether or not the value is a JavaScript Function type.
JSValue(JSContextRef ctx, JSValueRef val)
JSContextRef ctx_
Definition JSHelpers.h:234
virtual ~JSValue()
Destructor.
JSValue(JSString val)
Create string JSValue.
UTF-8 String container with conversions for UTF-16 and UTF-32.
Definition String.h:21
std::function< void(const JSObject &, const JSArgs &)> JSCallback
JSCallback typedef used for binding C++ callbacks to JavaScript functions.
Definition JSHelpers.h:309
JSValue JSEval(const JSString &str)
Evaluate a string of JavaScript and return a result.
JSContextRef GetJSContext()
Get the current JSContext.
JSObject JSGlobalObject()
Get the Global Object for the current JSContext.
void SetJSContext(JSContextRef ctx)
Set the current JSContext.
std::function< JSValue(const JSObject &, const JSArgs &)> JSCallbackWithRetval
JSCallbackWithRetval typedef used for binding C++ callbacks to JavaScript functions with an optional ...
Definition JSHelpers.h:318
Tag type used with the JSValue constructor to create "Null" types.
Definition JSHelpers.h:77
Tag type used with the JSValue constructor to create "Undefined" types.
Definition JSHelpers.h:80