35 #ifndef INCLUDE_JSNI_H_ 36 #define INCLUDE_JSNI_H_ 160 #if defined(__cplusplus) 418 size_t JSNIGetString(
JSNIEnv* env,
JSValueRef string, uint16_t* copy,
size_t length);
802 #if defined(__cplusplus) 819 #define JSNI_VERSION_1_0 0x00010000 825 #define JSNI_VERSION_1_1 0x00010001 834 #define JSNI_VERSION_2_0 0x00020000 839 #define JSNI_VERSION_2_1 0x00020001 844 #define JSNI_VERSION_2_2 0x00020002 846 #if defined(__cplusplus) 854 #if defined(__cplusplus) 858 #endif // INCLUDE_JSNI_H_ void(* JSNICallback)(JSNIEnv *, const JSNICallbackInfo)
Callback helper type.
Definition: jsni.h:68
int JSNIInternalFieldCount(JSNIEnv *env, JSValueRef object)
Gets the number of the internal field fo a JavaScript object.
void * JSNIGetInternalField(JSNIEnv *env, JSValueRef object, int index)
Gets an internal field of a JavaScript object.
JSNICallback getter
Definition: jsni.h:126
JSValueRef JSNINewSymbol(JSNIEnv *env, JSValueRef val)
Constructs a new Symbol JavaScript value.
bool JSNIIsEmpty(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is empty.
size_t JSNIGetStringUtf8Length(JSNIEnv *env, JSValueRef string)
Returns the length in bytes of the UTF-8 representation of a string.
bool JSNIIsTypedArray(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is TypedArray.
JSNIAccessorPropertyDescriptor * accessor_attributes
Definition: jsni.h:140
JSNI environment structure.
Definition: jsni.h:809
bool JSNIHasException(JSNIEnv *env)
Tests whether a JavaScript exception is being thrown. It's different with error get from JSNIGetLastE...
JsTypedArrayType JSNIGetTypedArrayType(JSNIEnv *env, JSValueRef typed_array)
Returns the type of the JavaScript TypedArray value.
struct _JSNICallbackInfo * JSNICallbackInfo
Callback helper type.
Definition: jsni.h:63
JSValueRef JSNINewNumber(JSNIEnv *env, double val)
Constructs a new Number JavaScript value.
bool JSNIIsObject(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is a JavaScript object.
bool JSNIIsSymbol(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Symbol.
JSNIErrorCode
Definition: jsni.h:144
bool JSNIHasProperty(JSNIEnv *env, JSValueRef object, const char *name)
Tests whether a JavaScript object has a property named name.
JSValueRef JSNIGetProperty(JSNIEnv *env, JSValueRef object, const char *name)
Returns the property of the JavaScript object.
void * data
Definition: jsni.h:132
int JSNIInit(JSNIEnv *env, JSValueRef exports)
This function is called by JSNI, not part of JSNI.
double JSNIToCDouble(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to C double.
size_t JSNIAcquireGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Acquire the val means to increase the reference count of the val. Once the reference count of the val...
void JSNISetGCCallback(JSNIEnv *env, JSGlobalValueRef val, void *args, JSNIGCCallback callback)
Sets a callback which will be called when the JavaScript value pointed by val is freed. The developer can pass an argument to callback by args. JSNISetGCCallback() is only valid when reference count is bigger than zero.
const char * msg
Definition: jsni.h:154
JSValueRef JSNINewStringFromUtf8(JSNIEnv *env, const char *src, size_t length)
Constructs a new String value from an array of characters in UTF-8 encoding.
bool JSNIIsBoolean(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Boolean.
void JSNISetArrayElement(JSNIEnv *env, JSValueRef array, size_t index, JSValueRef value)
Sets an element of a JavaScript array.
JSValueRef value
Definition: jsni.h:118
void JSNISetReturnValue(JSNIEnv *env, JSNICallbackInfo info, JSValueRef val)
Sets the JavaScript return value for the callback.
bool JSNIIsNumber(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Number.
struct _JSGlobalValueRef * JSGlobalValueRef
Global reference type.
Definition: jsni.h:73
void JSNIPushEscapableLocalScope(JSNIEnv *env)
Creates a local reference scope, and then all local references will be allocated within this referenc...
void JSNIDeleteGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Deletes the global reference pointed by val.
JSNIPropertyAttributes attributes
Definition: jsni.h:120
size_t JSNIGetTypedArrayLength(JSNIEnv *env, JSValueRef typed_array)
Returns the number of elements in the TypedArray value.
bool JSNIIsString(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is String.
JSValueRef JSNIGetPrototype(JSNIEnv *env, JSValueRef object)
Returns a prototype of a JavaScript object.
bool JSNIDefineProperty(JSNIEnv *env, JSValueRef object, const char *name, const JSNIPropertyDescriptor descriptor)
Defines a new property directly on an object, or modifies an existing property on an object...
uint32_t JSNIToUint32(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to uint32.
void JSNIThrowTypeErrorException(JSNIEnv *env, const char *errmsg)
Constructs an type error object with the message specified by errmsg and causes that type error to be...
struct _JSValueRef * JSValueRef
Reference type.
Definition: jsni.h:48
JSNIErrorInfo JSNIGetLastErrorInfo(JSNIEnv *env)
Tests whether there is error occured during pervious JSNI call. After calling JSNIGetLastErrorInfo()...
bool JSNIIsFunction(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is Function.
int32_t JSNIToInt32(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to int32.
void JSNIPushLocalScope(JSNIEnv *env)
Creates a local reference scope, and then all local references will be allocated within this referenc...
JSValueRef JSNINewObject(JSNIEnv *env)
Constructs a JavaScript object.
void * JSNIGetTypedArrayData(JSNIEnv *env, JSValueRef typed_array)
Returns the pointer to the buffer of TypedArray data.
bool JSNIToCBool(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to C bool.
bool JSNIDeleteProperty(JSNIEnv *env, JSValueRef object, const char *name)
Deletes the property of a JavaScript object.
bool JSNIIsArray(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is Array.
JSValueRef JSNINewTypedArray(JSNIEnv *env, JsTypedArrayType type, void *data, size_t length)
Constructs a JavaScript TypedArray object.
JSNIDataPropertyDescriptor * data_attributes
Definition: jsni.h:138
JSValueRef JSNIGetArgOfCallback(JSNIEnv *env, JSNICallbackInfo info, int id)
Returns the argument for the callback.
JSValueRef JSNINewString(JSNIEnv *env, const uint16_t *src, size_t length)
Constructs a new String value from an array of characters in two bytes.
JSValueRef JSNINewObjectWithInternalField(JSNIEnv *env, int count)
Constructs a JavaScript object with internal field. Internal field is a raw C pointer which can not b...
JSNIPropertyAttributes
Definition: jsni.h:104
bool JSNISetProperty(JSNIEnv *env, JSValueRef object, const char *name, JSValueRef property)
Sets a property of a JavaScript object.
JSValueRef JSNINewFunction(JSNIEnv *env, JSNICallback callback)
Constructs a JavaScript function with callback.
JSValueRef JSNIGetArrayElement(JSNIEnv *env, JSValueRef array, size_t index)
Returns an element of a JavaScript array.
bool JSNIIsUndefined(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is undefined.
void * reserved
Definition: jsni.h:811
void JSNIThrowRangeErrorException(JSNIEnv *env, const char *errmsg)
Constructs an range error object with the message specified by errmsg and causes that type error to b...
JSNIPropertyAttributes attributes
Definition: jsni.h:130
JSValueRef JSNIPopEscapableLocalScope(JSNIEnv *env, JSValueRef val)
Pops off the current local reference scope, frees all the local references in the local reference sco...
JSNICallback setter
Definition: jsni.h:128
size_t JSNIGetStringUtf8Chars(JSNIEnv *env, JSValueRef string, char *copy, size_t length)
Copyies a JavaScript string into a UTF-8 encoding string buffer.
JsTypedArrayType
The type of a typed JavaScript array.
Definition: jsni.h:78
void JSNISetInternalField(JSNIEnv *env, JSValueRef object, int index, void *field)
Sets an internal field of a JavaScript object.
int JSNIGetArgsLengthOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Returns the number of arguments for the callback.
int64_t JSNIToInt64(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to int64.
void JSNIPopLocalScope(JSNIEnv *env)
Pops off the current local reference scope, frees all the local references in the local reference sco...
bool JSNIRegisterMethod(JSNIEnv *env, const JSValueRef recv, const char *name, JSNICallback callback)
Registers a native callback function.
void(* JSNIGCCallback)(JSNIEnv *, void *)
GCCallback helper type.
Definition: jsni.h:58
size_t JSNIGetArrayLength(JSNIEnv *env, JSValueRef array)
Returns the number of elements in the array.
int JSNIGetVersion(JSNIEnv *env)
Returns the version of the JSNI.
JSValueRef JSNIGetGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Returns a local JSValueRef value from a JSGlobalValueRef value.
void * JSNIGetDataOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Get the raw data which is passed to this callback.
JSValueRef JSNINewBoolean(JSNIEnv *env, bool val)
Constructs a new Boolean JavaScript value.
size_t JSNIReleaseGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Release the val means to decrease the reference count of the val. Once the reference count of the val...
void JSNIThrowErrorException(JSNIEnv *env, const char *errmsg)
Constructs an error object with the message specified by errmsg and causes that error to be thrown...
void JSNIClearException(JSNIEnv *env)
Clear a JavaScript exception that is being thrown. If there is no exception, this routine has no effe...
JSValueRef JSNINewNull(JSNIEnv *env)
Constructs a new Null JavaScript value.
bool JSNIIsNull(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Null.
JSValueRef JSNIGetThisOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Returns "this" JavaScript object of the JavaScript function which current callback associated with...
JSValueRef JSNINewUndefined(JSNIEnv *env)
Constructs a new Undefined JavaScript value.
JSValueRef JSNINewArray(JSNIEnv *env, size_t initial_length)
Constructs a JavaScript array with initial length: initial_length.
JSNIErrorCode error_code
Definition: jsni.h:156
JSGlobalValueRef JSNINewGlobalValue(JSNIEnv *env, JSValueRef val)
Creates a new global reference to the JavaScript value referred to by the val argument. The global value must be explicitly disposed of by calling JSNIDeleteGlobalValue() or JSNIReleaseGlobalValue(). The global value will be alive untile calling JSNIDeleteGlobalValue() or JSNIReleaseGlobalValue() to dispose it. JSNIDeleteGlobalValue() dispose it immediately, whereas JSNIReleaseGlobalValue() dispose it when decrease the reference count to zero.
JSValueRef JSNICallFunction(JSNIEnv *env, JSValueRef func, JSValueRef recv, int argc, JSValueRef *argv)
Calls a JavaScript function.