170 int64_t
ToInteger()
const {
return static_cast<int64_t
>(ToNumber()); }
184 operator bool()
const {
return ToBoolean(); }
186 operator double()
const {
return ToNumber(); }
188 operator uint32_t()
const {
return static_cast<uint32_t
>(ToNumber()); }
190 operator int32_t()
const {
return static_cast<uint32_t
>(ToNumber()); }
192 operator uint64_t()
const {
return static_cast<uint64_t
>(ToNumber()); }
194 operator int64_t()
const {
return ToInteger(); }
196 operator String()
const {
return ToString(); }
247 JSArgs(
const std::initializer_list<JSValue>& values);
327#define BindJSCallback(fn) (JSCallback)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
337#define BindJSCallbackWithRetval(fn) (JSCallbackWithRetval)std::bind(fn, this, std::placeholders::_1, std::placeholders::_2)
382 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:241
void pop_back()
Remove the last item from the end of the list.
JSArgs(const JSArgs &other)
Copy-constructor.
JSValue operator[](size_t pos)
Access an element of the argument list by index.
void push_back(const JSValue &val)
Add a new argument to the end of the list.
size_t size() const
The number of elements in the argument list.
JSArgs(const std::initializer_list< JSValue > &values)
Create a list of JavaScript arguments using a C++ initializer list.
bool empty() const
Whether or not the argument list is empty.
JSValue * data()
Get the argument list as a C-array of JSValues.
JSArgs()
Create an empty list of JavaScript arguments.
JSArgs & operator=(const JSArgs &other)
Assignment operator.
void * instance_
Definition JSHelpers.h:299
void clear()
Clear the argument list.
const JSValue * data() const
Get the argument list as a C-array of JSValues (const overload)
const JSValue operator[](size_t pos) const
Access an element of the argument list by index.
JSArray wrapper that automatically manages lifetime and provides convenient access to indices and Arr...
Definition JSHelpers.h:376
JSPropertyValue operator[](unsigned idx) const
Get a property by array index (numbering starts at 0)
void set_context(JSContextRef context)
Set the JSContext for this JSArray.
Definition JSHelpers.h:425
JSObjectRef instance_
Definition JSHelpers.h:431
JSArray(const JSArray &other)
Copy constructor (shallow copy, will point to same instance)
JSArray & operator=(const JSArray &other)
Assignment (shallow assignment, will point to same instance)
JSArray(JSContextRef ctx, JSValueRef val)
JSArray(const std::initializer_list< JSValue > &values)
Create Array from list of JSValues.
JSArray()
Create empty Array.
JSContextRef ctx_
Definition JSHelpers.h:430
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.
JSContextRef context() const
Get the bound context for this JSArray (it is cached at creation).
Definition JSHelpers.h:413
JSArray(JSObjectRef array_obj)
Create Array from existing JSObjectRef (JavaScriptCore C API)
unsigned length()
Get number of elements in the Array.
JSFunction wrapper that automatically manages lifetime and provides convenient function invocation op...
Definition JSHelpers.h:498
void set_context(JSContextRef context)
Set the JSContext for this JSFunction.
Definition JSHelpers.h:539
JSObjectRef instance_
Definition JSHelpers.h:545
JSFunction(JSContextRef ctx, JSValueRef val)
JSFunction & operator=(const JSFunction &other)
Assignment (shallow assignment, will point to same instance)
JSFunction()
Create an empty Function.
bool IsValid() const
Whether or not this is a valid, callable Function object.
JSContextRef ctx_
Definition JSHelpers.h:544
JSValue operator()(const JSObject &thisObject, const JSArgs &args)
Call function (with explicit object for 'this') and return the result.
JSFunction(const JSFunction &other)
Copy constructor (shallow copy, will point to same instance)
JSValue operator()(const JSArgs &args)
Call function (using Global Object for 'this') and return the result.
JSContextRef context() const
Get the bound context for this JSFunction (it is cached at creation).
Definition JSHelpers.h:527
JSObject wrapper that automatically manages lifetime and provides convenient access to properties.
Definition JSHelpers.h:439
void set_context(JSContextRef context)
Set the JSContext for this JSObject.
Definition JSHelpers.h:482
JSObjectRef instance_
Definition JSHelpers.h:489
JSObject(JSObjectRef obj)
Create from existing JSObjectRef from JavaScriptCore C API.
JSObject(JSContextRef ctx, JSObjectRef obj)
bool DeleteProperty(JSString propertyName)
Remove a property.
JSPropertyValue operator[](JSString propertyName) const
Get a property by name.
JSObject()
Create empty Object.
bool HasProperty(JSString propertyName) const
Check if a property exists.
JSObject(const JSObject &other)
Copy constructor (shallow copy, will point to same instance)
JSObject(JSContextRef ctx, JSValueRef val)
JSContextRef ctx_
Definition JSHelpers.h:488
JSContextRef context() const
Get the bound context for this JSObject (it is cached at creation).
Definition JSHelpers.h:470
JSObject & operator=(const JSObject &other)
Assignment (shallow assignment, will point to same instance)
Wrapper for JSObject property value (JSValue subclass).
Definition JSHelpers.h:344
JSString string_idx_
Definition JSHelpers.h:367
JSPropertyValue & operator=(const JSCallbackWithRetval &callback)
Bind to native C++ callback with return value (creates a Function object that can be called from JS)
virtual JSValueRef instance() const
JSPropertyValue & operator=(const JSPropertyValue &)=delete
JSObject * proxyObj_
Definition JSHelpers.h:364
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, JSString idx)
JSPropertyValue(const JSPropertyValue &)=default
bool using_numeric_idx_
Definition JSHelpers.h:365
virtual JSPropertyValue & operator=(const JSValue &value)
Assign a new value to the property (internally calls JSObjectSetProperty)
JSPropertyValue & operator=(const JSCallback &callback)
Bind to native C++ callback (creates a Function object that can be called from JS)
JSPropertyValue(JSContextRef ctx, JSObjectRef proxy_obj, unsigned idx)
unsigned numeric_idx_
Definition JSHelpers.h:366
virtual ~JSPropertyValue()
JavaScript String wrapper that automatically manages JSStringRef lifetime and provides helpful conver...
Definition JSHelpers.h:38
JSStringRef instance_
Definition JSHelpers.h:68
JSString(const JSString &other)
Copy constructor.
JSString(JSStringRef str)
Create from existing JSStringRef.
JSString(const char *str)
Create from C-string.
JSString()
Create empty string.
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:85
JSValue(JSObjectRef obj)
Create object JSValue.
JSValue(JSContextRef ctx)
void set_context(JSContextRef context)
Set the JSContext for this JSValue.
Definition JSHelpers.h:226
virtual JSValueRef instance() const
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)
JSValue(uint32_t val)
Create unsigned integer JSValue (aka, Number) [will be cast to double].
bool ToBoolean() const
Get the value as a Boolean.
JSValue(const JSValue &other)
Copy constructor, a shallow copy is made, the constructed JSValue will point to the same JSValueRef.
JSValue(JSValueUndefinedTag)
Create undefined JSValue.
JSValue(JSContextRef ctx, JSValueRef val)
JSValue(bool val)
Create boolean JSValue.
bool IsNumber() const
Whether or not the value is a JavaScript Number type.
JSValue(int64_t val)
Create integer JSValue (aka, Number) [will be cast to double].
bool IsObject() const
Whether or not the value is a JavaScript Object type.
bool IsString() const
Whether or not the value is a JavaScript String type.
JSFunction ToFunction() const
Get the value as a Function (will debug asset if not a Function)
JSValue(JSValueNullTag)
Create null JSValue explicitly.
double ToNumber() const
Get the value as a Number (Double)
JSValue(double val)
Create double JSValue (aka, Number)
JSValue()
Create null (empty) JSValue.
bool IsNull() const
Whether or not the value is a JavaScript Null type.
JSContextRef ctx_
Definition JSHelpers.h:233
bool IsBoolean() const
Whether or not the value is a JavaScript Boolean type.
JSValue(JSValueRef val)
Create from existing JSValueRef.
JSValue(int32_t val)
Create integer JSValue (aka, Number) [will be cast to double].
int64_t ToInteger() const
Get the value as a Number (Integer)
Definition JSHelpers.h:170
JSValue(JSString val)
Create string JSValue.
virtual JSValue & operator=(const JSValue &other)
A shallow copy is made, this JSValue will point to the same JSValueRef.
JSValue(const String &val)
Create string JSValue.
JSContextRef context() const
Get the bound context for this JSValue (it is cached at creation).
Definition JSHelpers.h:214
JSValue(uint64_t val)
Create unsigned integer JSValue (aka, Number) [will be cast to double].
bool IsUndefined() const
Whether or not the value is a JavaScript Undefined type.
JSArray ToArray() const
Get the value as an Array (will debug asset if not an Array)
bool IsFunction() const
Whether or not the value is a JavaScript Function type.
JSValue(const char *val)
Create string JSValue.
bool IsArray() const
Whether or not the value is a JavaScript Array type.
virtual ~JSValue()
Destructor.
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:34
std::function< void(const JSObject &, const JSArgs &)> JSCallback
JSCallback typedef used for binding C++ callbacks to JavaScript functions.
Definition JSHelpers.h:308
JSContextRef GetJSContext()
Get 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:317
JSObject JSGlobalObject()
Get the Global Object for the current JSContext.
void SetJSContext(JSContextRef ctx)
Set the current JSContext.
JSValue JSEval(const JSString &str)
Evaluate a string of JavaScript and return a result.
Tag type used with the JSValue constructor to create "Null" types.
Definition JSHelpers.h:76
Tag type used with the JSValue constructor to create "Undefined" types.
Definition JSHelpers.h:79