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);
942 #if defined(__cplusplus) 959 #define JSNI_VERSION_1_0 0x00010000 965 #define JSNI_VERSION_1_1 0x00010001 974 #define JSNI_VERSION_2_0 0x00020000 979 #define JSNI_VERSION_2_1 0x00020001 984 #define JSNI_VERSION_2_2 0x00020002 989 #define JSNI_VERSION_2_3 0x00020003 991 #if defined(__cplusplus) 999 #if defined(__cplusplus) 1003 #endif // INCLUDE_JSNI_H_ JSValueRef JSNINewTypeError(JSNIEnv *env, const char *errmsg)
Constructs a JavaScript TypeError object.
Definition: jsni.cc:1251
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.
Definition: jsni.cc:812
JSNICallback getter
Definition: jsni.h:126
JSValueRef JSNINewSymbol(JSNIEnv *env, JSValueRef val)
Constructs a new Symbol JavaScript value.
Definition: jsni.cc:608
bool JSNIStrictEquals(JSNIEnv *env, JSValueRef left, JSValueRef right)
Tests whether the left JavaScript value is strict-equal to the right JavaScript value.
Definition: jsni.cc:1326
bool JSNIIsEmpty(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is empty.
Definition: jsni.cc:704
size_t JSNIGetStringUtf8Length(JSNIEnv *env, JSValueRef string)
Returns the length in bytes of the UTF-8 representation of a string.
Definition: jsni.cc:633
bool JSNIIsTypedArray(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is TypedArray.
Definition: jsni.cc:949
JSValueRef JSNINewArrayBuffer(JSNIEnv *env, size_t length)
Constructs a JavaScript ArrayBuffer.
Definition: jsni.cc:1333
JSNIAccessorPropertyDescriptor * accessor_attributes
Definition: jsni.h:140
JSNI environment structure.
Definition: jsni.h:949
bool JSNIHasException(JSNIEnv *env)
Tests whether a JavaScript exception is being thrown. It's different with error get from JSNIGetLastE...
Definition: jsni.cc:1225
JsTypedArrayType JSNIGetTypedArrayType(JSNIEnv *env, JSValueRef typed_array)
Returns the type of the JavaScript TypedArray value.
Definition: jsni.cc:970
struct _JSNICallbackInfo * JSNICallbackInfo
Callback helper type.
Definition: jsni.h:63
JSValueRef JSNINewNumber(JSNIEnv *env, double val)
Constructs a new Number JavaScript value.
Definition: jsni.cc:546
bool JSNIIsObject(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is a JavaScript object.
Definition: jsni.cc:699
bool JSNIIsSymbol(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Symbol.
Definition: jsni.cc:603
void * JSNIGetInternalField(JSNIEnv *env, JSValueRef object, int index)
Gets an internal field of a JavaScript object.
Definition: jsni.cc:827
JSNIErrorCode
Definition: jsni.h:144
bool JSNIHasProperty(JSNIEnv *env, JSValueRef object, const char *name)
Tests whether a JavaScript object has a property named name.
Definition: jsni.cc:727
JSValueRef JSNIGetProperty(JSNIEnv *env, JSValueRef object, const char *name)
Returns the property of the JavaScript object.
Definition: jsni.cc:742
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.
Definition: jsni.cc:552
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...
Definition: jsni.cc:1079
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.
Definition: jsni.cc:1096
const char * msg
Definition: jsni.h:154
JSValueRef JSNINewRangeError(JSNIEnv *env, const char *errmsg)
Constructs a JavaScript RangeError object.
Definition: jsni.cc:1263
JSValueRef JSNINewError(JSNIEnv *env, const char *errmsg)
Constructs a JavaScript Error object.
Definition: jsni.cc:1239
JSValueRef JSNINewStringFromUtf8(JSNIEnv *env, const char *src, size_t length)
Constructs a new String value from an array of characters in UTF-8 encoding.
Definition: jsni.cc:624
bool JSNIIsError(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is Error object.
Definition: jsni.cc:1282
bool JSNIIsBoolean(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Boolean.
Definition: jsni.cc:518
void JSNISetArrayElement(JSNIEnv *env, JSValueRef array, size_t index, JSValueRef value)
Sets an element of a JavaScript array.
Definition: jsni.cc:924
JSValueRef value
Definition: jsni.h:118
JSValueRef JSNIGetNewTarget(JSNIEnv *env, JSNICallbackInfo info)
Gets the new.target value of the call.
Definition: jsni.cc:1316
void JSNISetReturnValue(JSNIEnv *env, JSNICallbackInfo info, JSValueRef val)
Sets the JavaScript return value for the callback.
Definition: jsni.cc:463
bool JSNIIsNumber(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Number.
Definition: jsni.cc:541
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...
Definition: jsni.cc:1034
bool JSNIInstanceOf(JSNIEnv *env, JSValueRef left, JSValueRef right)
Tests whether left object is an instance of right object.
Definition: jsni.cc:1306
void JSNIDeleteGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Deletes the global reference pointed by val.
Definition: jsni.cc:1074
JSNIPropertyAttributes attributes
Definition: jsni.h:120
size_t JSNIGetTypedArrayLength(JSNIEnv *env, JSValueRef typed_array)
Returns the number of elements in the TypedArray value.
Definition: jsni.cc:995
bool JSNIIsString(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is String.
Definition: jsni.cc:619
JSValueRef JSNIGetPrototype(JSNIEnv *env, JSValueRef object)
Returns a prototype of a JavaScript object.
Definition: jsni.cc:803
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...
Definition: jsni.cc:1154
uint32_t JSNIToUint32(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to uint32.
Definition: jsni.cc:577
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...
Definition: jsni.cc:1116
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()...
Definition: jsni.cc:1138
bool JSNIIsFunction(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is Function.
Definition: jsni.cc:837
int32_t JSNIToInt32(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to int32.
Definition: jsni.cc:564
void JSNIPushLocalScope(JSNIEnv *env)
Creates a local reference scope, and then all local references will be allocated within this referenc...
Definition: jsni.cc:1007
JSValueRef JSNINewObject(JSNIEnv *env)
Constructs a JavaScript object.
Definition: jsni.cc:709
bool JSNIToCBool(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to C bool.
Definition: jsni.cc:523
bool JSNIDeleteProperty(JSNIEnv *env, JSValueRef object, const char *name)
Deletes the property of a JavaScript object.
Definition: jsni.cc:784
bool JSNIIsArray(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is Array.
Definition: jsni.cc:881
JSValueRef JSNINewTypedArray(JSNIEnv *env, JsTypedArrayType type, void *data, size_t length)
Constructs a JavaScript TypedArray object.
Definition: jsni.cc:954
JSNIDataPropertyDescriptor * data_attributes
Definition: jsni.h:138
JSValueRef JSNIGetArgOfCallback(JSNIEnv *env, JSNICallbackInfo info, int id)
Returns the argument for the callback.
Definition: jsni.cc:411
JSValueRef JSNINewString(JSNIEnv *env, const uint16_t *src, size_t length)
Constructs a new String value from an array of characters in two bytes.
Definition: jsni.cc:661
JSValueRef JSNINewObjectWithInternalField(JSNIEnv *env, int count)
Constructs a JavaScript object with internal field. Internal field is a raw C pointer which can not b...
Definition: jsni.cc:716
void JSNIThrowErrorObject(JSNIEnv *env, JSValueRef error)
Throw JavaScript Error object.
Definition: jsni.cc:1275
JSNIPropertyAttributes
Definition: jsni.h:104
bool JSNISetProperty(JSNIEnv *env, JSValueRef object, const char *name, JSValueRef property)
Sets a property of a JavaScript object.
Definition: jsni.cc:761
JSValueRef JSNINewFunction(JSNIEnv *env, JSNICallback callback)
Constructs a JavaScript function with callback.
Definition: jsni.cc:842
JSValueRef JSNINewArrayBufferExternalized(JSNIEnv *env, void *data, size_t length)
Constructs a JavaScirpt ArrayBuffer with the externalized data.
Definition: jsni.cc:1340
JSValueRef JSNIGetArrayElement(JSNIEnv *env, JSValueRef array, size_t index)
Returns an element of a JavaScript array.
Definition: jsni.cc:905
bool JSNIIsUndefined(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is undefined.
Definition: jsni.cc:498
void * reserved
Definition: jsni.h:951
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...
Definition: jsni.cc:1127
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...
Definition: jsni.cc:1042
JSValueRef JSNIGetPropertyNames(JSNIEnv *env, JSValueRef val)
Gets the names of the properties of the object.
Definition: jsni.cc:1367
JSNICallback setter
Definition: jsni.h:128
JSValueRef JSNINewInstance(JSNIEnv *env, JSValueRef constructor, int argc, JSValueRef *argv)
New an instance from a constructor.
Definition: jsni.cc:1290
size_t JSNIGetStringUtf8Chars(JSNIEnv *env, JSValueRef string, char *copy, size_t length)
Copyies a JavaScript string into a UTF-8 encoding string buffer.
Definition: jsni.cc:642
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.
Definition: jsni.cc:817
int JSNIGetArgsLengthOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Returns the number of arguments for the callback.
Definition: jsni.cc:388
int64_t JSNIToInt64(JSNIEnv *env, JSValueRef val)
Converts the JavaScript value to int64.
Definition: jsni.cc:590
void JSNIPopLocalScope(JSNIEnv *env)
Pops off the current local reference scope, frees all the local references in the local reference sco...
Definition: jsni.cc:1015
bool JSNIRegisterMethod(JSNIEnv *env, const JSValueRef recv, const char *name, JSNICallback callback)
Registers a native callback function.
Definition: jsni.cc:363
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.
Definition: jsni.cc:886
int JSNIGetVersion(JSNIEnv *env)
Returns the version of the JSNI.
Definition: jsni.cc:358
JSValueRef JSNIGetGlobalValue(JSNIEnv *env, JSGlobalValueRef val)
Returns a local JSValueRef value from a JSGlobalValueRef value.
Definition: jsni.cc:1090
JSValueRef JSNINewBoolean(JSNIEnv *env, bool val)
Constructs a new Boolean JavaScript value.
Definition: jsni.cc:535
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...
Definition: jsni.cc:1085
void JSNIThrowErrorException(JSNIEnv *env, const char *errmsg)
Constructs an error object with the message specified by errmsg and causes that error to be thrown...
Definition: jsni.cc:1105
void JSNIClearException(JSNIEnv *env)
Clear a JavaScript exception that is being thrown. If there is no exception, this routine has no effe...
Definition: jsni.cc:1230
void * JSNIGetArrayBufferData(JSNIEnv *env, JSValueRef val)
Gets the pointer to the buffer of ArrayBuffer data.
Definition: jsni.cc:1353
bool JSNIIsArrayBuffer(JSNIEnv *env, JSValueRef val)
Tests whether a JavaScript value is ArrayBuffer.
Definition: jsni.cc:1347
JSValueRef JSNINewNull(JSNIEnv *env)
Constructs a new Null JavaScript value.
Definition: jsni.cc:513
bool JSNIIsNull(JSNIEnv *env, JSValueRef val)
Tests whether the JavaScript value is Null.
Definition: jsni.cc:508
JSValueRef JSNIGetThisOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Returns "this" JavaScript object of the JavaScript function which current callback associated with...
Definition: jsni.cc:438
JSValueRef JSNINewUndefined(JSNIEnv *env)
Constructs a new Undefined JavaScript value.
Definition: jsni.cc:503
void * JSNIGetDataOfCallback(JSNIEnv *env, JSNICallbackInfo info)
Get the raw data which is passed to this callback.
Definition: jsni.cc:1201
JSValueRef JSNINewArray(JSNIEnv *env, size_t initial_length)
Constructs a JavaScript array with initial length: initial_length.
Definition: jsni.cc:898
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.
Definition: jsni.cc:1068
void * JSNIGetTypedArrayData(JSNIEnv *env, JSValueRef typed_array)
Returns the pointer to the buffer of TypedArray data.
Definition: jsni.cc:982
size_t JSNIGetArrayBufferLength(JSNIEnv *env, JSValueRef val)
Gets the length of ArrayBuffer.
Definition: jsni.cc:1360
JSValueRef JSNICallFunction(JSNIEnv *env, JSValueRef func, JSValueRef recv, int argc, JSValueRef *argv)
Calls a JavaScript function.
Definition: jsni.cc:859