js_bindings library

Classes

JSClassAttributes
JSClassAttributes A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
JSClassDefinition
This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
JSPropertyAttributes
JSPropertyAttributes A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
JSStaticFunction
This structure describes a statically declared function property.
JSStaticFunctionDelegate
JSStaticValue
This structure describes a statically declared value property.
JSStaticValueDelegate
JSType
A constant identifying the type of a JSValue.
JSTypedArrayType
MacOS 10.12, iOS 10.0 A constant identifying the Typed Array type of a JSObjectRef.
OpaqueJSClass
OpaqueJSContext
OpaqueJSContextGroup
OpaqueJSPropertyNameAccumulator
OpaqueJSPropertyNameArray
OpaqueJSString
OpaqueJSValue

Properties

JSCheckScriptSyntax bool Function(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, Pointer<JSValueRef> exception)
Checks for syntax errors in a string of JavaScript. ctx The execution context to use. script A JSString containing the script to check for syntax errors. sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. @result true if the script is syntactically correct, otherwise false.
final
JSClassCreate JSClassRef Function(Pointer<JSClassDefinition> definition)
Creates a JavaScript class suitable for use with JSObjectMake. definition A JSClassDefinition that defines the class. @result A JSClass with the given definition. Ownership follows the Create Rule.
final
JSClassRelease → void Function(JSClassRef jsClass)
Releases a JavaScript class. jsClass The JSClass to release.
final
JSClassRetain JSClassRef Function(JSClassRef jsClass)
Retains a JavaScript class. jsClass The JSClass to retain. @result A JSClass that is the same as jsClass.
final
jscLib DynamicLibrary
final
JSContextGetGlobalContext JSGlobalContextRef Function(JSContextRef ctx)
Gets the global context of a JavaScript execution context. ctx The JSContext whose global context you want to get. @result ctx's global context.
final
JSContextGetGlobalObject JSObjectRef Function(JSContextRef ctx)
Gets the global object of a JavaScript execution context. ctx The JSContext whose global object you want to get. @result ctx's global object.
final
JSContextGetGroup JSContextGroupRef Function(JSContextRef ctx)
Gets the context group to which a JavaScript execution context belongs. ctx The JSContext whose group you want to get. @result ctx's group.
final
JSContextGroupCreate JSContextGroupRef Function()
Creates a JavaScript context group. @result The created JSContextGroup. @discussion A JSContextGroup associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging JavaScript objects between contexts in different groups will produce undefined behavior. When objects from the same context group are used in multiple threads, explicit synchronization is required.
final
JSContextGroupRelease → void Function(JSContextGroupRef group)
Releases a JavaScript context group. group The JSContextGroup to release.
final
JSContextGroupRetain JSContextGroupRef Function(JSContextGroupRef group)
Retains a JavaScript context group. group The JSContextGroup to retain. @result A JSContextGroup that is the same as group.
final
JSEvaluateScript JSValueRef Function(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, Pointer<JSValueRef> exception)
Evaluates a string of JavaScript. ctx The execution context to use. script A JSString containing the script to evaluate. thisObject The object to use as "this," or NULL to use the global object as "this." sourceURL A JSString containing a URL for the script's source file. This is used by debuggers and when reporting exceptions. Pass NULL if you do not care to include source file information. startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The JSValue that results from evaluating script, or NULL if an exception is thrown.
final
JSGarbageCollect → void Function(JSContextRef ctx)
Performs a JavaScript garbage collection. ctx The execution context to use. @discussion JavaScript values that are on the machine stack, in a register, protected by JSValueProtect, set as the global object of an execution context, or reachable from any such value will not be collected.
final
JSGlobalContextCopyName JSStringRef Function(JSGlobalContextRef ctx)
Gets a copy of the name of a context. ctx The JSGlobalContext whose name you want to get. @result The name for ctx. @discussion A JSGlobalContext's name is exposed for remote debugging to make it easier to identify the context you would like to attach to.
final
JSGlobalContextCreate JSGlobalContextRef Function(JSClassRef globalObjectClass)
Creates a global JavaScript execution context. globalObjectClass The class to use when creating the global object. Pass NULL to use the default object class. @result A JSGlobalContext with a global object of class globalObjectClass. @discussion JSGlobalContextCreate allocates a global object and populates it with all the built-in JavaScript objects, such as Object, Function, String, and Array.
final
JSGlobalContextCreateInGroup JSGlobalContextRef Function(JSContextGroupRef group, JSClassRef globalObjectClass)
Creates a global JavaScript execution context in the context group provided. group The context group to use. The created global context retains the group. Pass NULL to create a unique group for the context. globalObjectClass The class to use when creating the global object. Pass NULL to use the default object class. @result A JSGlobalContext with a global object of class globalObjectClass and a context group equal to group. @discussion JSGlobalContextCreateInGroup allocates a global object and populates it with all the built-in JavaScript objects, such as Object, Function, String, and Array.
final
JSGlobalContextRelease → void Function(JSGlobalContextRef ctx)
Releases a global JavaScript execution context. ctx The JSGlobalContext to release.
final
JSGlobalContextRetain JSGlobalContextRef Function(JSGlobalContextRef ctx)
Retains a global JavaScript execution context. ctx The JSGlobalContext to retain. @result A JSGlobalContext that is the same as ctx.
final
JSGlobalContextSetName → void Function(JSGlobalContextRef ctx, JSStringRef name)
Sets the remote debugging name for a context. ctx The JSGlobalContext that you want to name. name The remote debugging name to set on ctx.
final
JSObjectCallAsConstructor JSObjectRef Function(JSContextRef ctx, JSObjectRef object, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Calls an object as a constructor. ctx The execution context to use. object The JSObject to call as a constructor. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
final
JSObjectCallAsFunction JSValueRef Function(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Calls an object as a function. ctx The execution context to use. object The JSObject to call as a function. thisObject The object to use as "this," or NULL to use the global object as "this." argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
final
JSObjectCopyPropertyNames JSPropertyNameArrayRef Function(JSContextRef ctx, JSObjectRef object)
Gets the names of an object's enumerable properties. ctx The execution context to use. object The object whose property names you want to get. @result A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
final
JSObjectDeleteProperty bool Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, Pointer<JSValueRef> exception)
Deletes a property from an object. ctx The execution context to use. object The JSObject whose property you want to delete. propertyName A JSString containing the property's name. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
final
JSObjectDeletePropertyForKey bool Function(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, Pointer<JSValueRef> exception)
MacOS 10.15, iOS 13.0 Deletes a property from an object using a JSValueRef as the property key. ctx The execution context to use. object The JSObject whose property you want to delete. propertyKey A JSValueRef containing the property key to use when looking up the property. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). @discussion This function is the same as performing "delete objectpropertyKey" from JavaScript.
final
JSObjectGetArrayBufferByteLength int Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns the number of bytes in a JavaScript data object. ctx The execution context to use. object The JS Arary Buffer object whose length in bytes to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The number of bytes stored in the data object.
final
JSObjectGetArrayBufferBytesPtr Pointer<Void> Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns a pointer to the data buffer that serves as the backing store for a JavaScript Typed Array object. object The Array Buffer object whose internal backing store pointer to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A pointer to the raw data buffer that serves as object's backing store or NULL if object is not an Array Buffer object. @discussion The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
final
JSObjectGetPrivate Pointer<Void> Function(JSObjectRef object)
Gets an object's private data. object A JSObject whose private data you want to get. @result A void* that is the object's private data, if the object has private data, otherwise NULL.
final
JSObjectGetProperty JSValueRef Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, Pointer<JSValueRef> exception)
Gets a property from an object. ctx The execution context to use. object The JSObject whose property you want to get. propertyName A JSString containing the property's name. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The property's value if object has the property, otherwise the undefined value.
final
JSObjectGetPropertyAtIndex JSValueRef Function(JSContextRef ctx, JSObjectRef object, int propertyIndex, Pointer<JSValueRef> exception)
Gets a property from an object by numeric index. ctx The execution context to use. object The JSObject whose property you want to get. propertyIndex An integer value that is the property's name. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The property's value if object has the property, otherwise the undefined value. @discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
final
JSObjectGetPropertyForKey JSValueRef Function(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, Pointer<JSValueRef> exception)
MacOS 10.15, iOS 13.0 Gets a property from an object using a JSValueRef as the property key. ctx The execution context to use. object The JSObject whose property you want to get. propertyKey A JSValueRef containing the property key to use when looking up the property. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The property's value if object has the property key, otherwise the undefined value. @discussion This function is the same as performing "objectpropertyKey" from JavaScript.
final
JSObjectGetPrototype JSValueRef Function(JSContextRef ctx, JSObjectRef object)
Gets an object's prototype. ctx The execution context to use. object A JSObject whose prototype you want to get. @result A JSValue that is the object's prototype.
final
JSObjectGetTypedArrayBuffer JSObjectRef Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns the JavaScript Array Buffer object that is used as the backing of a JavaScript Typed Array object. ctx The execution context to use. object The JSObjectRef whose Typed Array type data pointer to obtain. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef with a JSTypedArrayType of kJSTypedArrayTypeArrayBuffer or NULL if object is not a Typed Array.
final
JSObjectGetTypedArrayByteLength int Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns the byte length of a JavaScript Typed Array object. ctx The execution context to use. object The Typed Array object whose byte length to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The byte length of the Typed Array object or 0 if the object is not a Typed Array object.
final
JSObjectGetTypedArrayByteOffset int Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns the byte offset of a JavaScript Typed Array object. ctx The execution context to use. object The Typed Array object whose byte offset to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The byte offset of the Typed Array object or 0 if the object is not a Typed Array object.
final
JSObjectGetTypedArrayBytesPtr Pointer<Void> Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns a temporary pointer to the backing store of a JavaScript Typed Array object. ctx The execution context to use. object The Typed Array object whose backing store pointer to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A pointer to the raw data buffer that serves as object's backing store or NULL if object is not a Typed Array object. @discussion The pointer returned by this function is temporary and is not guaranteed to remain valid across JavaScriptCore API calls.
final
JSObjectGetTypedArrayLength int Function(JSContextRef ctx, JSObjectRef object, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns the length of a JavaScript Typed Array object. ctx The execution context to use. object The Typed Array object whose length to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The length of the Typed Array object or 0 if the object is not a Typed Array object.
final
JSObjectHasProperty bool Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
Tests whether an object has a given property. object The JSObject to test. propertyName A JSString containing the property's name. @result true if the object has a property whose name matches propertyName, otherwise false.
final
JSObjectHasPropertyForKey bool Function(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, Pointer<JSValueRef> exception)
MacOS 10.15, iOS 13.0 Tests whether an object has a given property using a JSValueRef as the property key. object The JSObject to test. propertyKey A JSValueRef containing the property key to use when looking up the property. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result true if the object has a property whose name matches propertyKey, otherwise false. @discussion This function is the same as performing "propertyKey in object" from JavaScript.
final
JSObjectIsConstructor bool Function(JSContextRef ctx, JSObjectRef object)
Tests whether an object can be called as a constructor. ctx The execution context to use. object The JSObject to test. @result true if the object can be called as a constructor, otherwise false.
final
JSObjectIsFunction bool Function(JSContextRef ctx, JSObjectRef object)
Tests whether an object can be called as a function. ctx The execution context to use. object The JSObject to test. @result true if the object can be called as a function, otherwise false.
final
JSObjectMake JSObjectRef Function(JSContextRef ctx, JSClassRef jsClass, Pointer<Void> data)
Creates a JavaScript object. ctx The execution context to use. jsClass The JSClass to assign to the object. Pass NULL to use the default object class. data A void* to set as the object's private data. Pass NULL to specify no private data. @result A JSObject with the given class and private data. @discussion The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
final
JSObjectMakeArray JSObjectRef Function(JSContextRef ctx, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Creates a JavaScript Array object. ctx The execution context to use. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is an Array. @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument is supplied, this function returns an array with one element.
final
JSObjectMakeArrayBufferWithBytesNoCopy JSObjectRef Function(JSContextRef ctx, Pointer<Void> bytes, int byteLength, Pointer<NativeFunction<JSTypedArrayBytesDeallocator>> bytesDeallocator, Pointer<Void> deallocatorContext, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Creates a JavaScript Array Buffer object from an existing pointer. ctx The execution context to use. bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object. byteLength The number of bytes pointed to by the parameter bytes. bytesDeallocator The allocator to use to deallocate the external buffer when the Typed Array data object is deallocated. deallocatorContext A pointer to pass back to the deallocator. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef Array Buffer whose backing store is the same as the one pointed to by bytes or NULL if there was an error. @discussion If an exception is thrown during this function the bytesDeallocator will always be called.
final
JSObjectMakeConstructor JSObjectRef Function(JSContextRef ctx, JSClassRef jsClass, Pointer<NativeFunction<JSObjectCallAsConstructorCallback>> callAsConstructor)
Convenience method for creating a JavaScript constructor. ctx The execution context to use. jsClass A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class. callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor. @result A JSObject that is a constructor. The object's prototype will be the default object prototype. @discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data. If the constructor is inherited via JS subclassing and the value returned from callAsConstructor was created with jsClass, then the returned object will have it's prototype overridden to the derived class's prototype.
final
JSObjectMakeDate JSObjectRef Function(JSContextRef ctx, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Creates a JavaScript Date object, as if by invoking the built-in Date constructor. ctx The execution context to use. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is a Date.
final
JSObjectMakeDeferredPromise JSObjectRef Function(JSContextRef ctx, Pointer<JSObjectRef> resolve, Pointer<JSObjectRef> reject, Pointer<JSValueRef> exception)
MacOS 10.15, iOS 13.0 Creates a JavaScript promise object by invoking the provided executor. ctx The execution context to use. resolve A pointer to a JSObjectRef in which to store the resolve function for the new promise. Pass NULL if you do not care to store the resolve callback. reject A pointer to a JSObjectRef in which to store the reject function for the new promise. Pass NULL if you do not care to store the reject callback. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is a promise or NULL if an exception occurred.
final
JSObjectMakeError JSObjectRef Function(JSContextRef ctx, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Creates a JavaScript Error object, as if by invoking the built-in Error constructor. ctx The execution context to use. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is an Error.
final
JSObjectMakeFunction JSObjectRef Function(JSContextRef ctx, JSStringRef name, int parameterCount, Pointer<JSStringRef> parameterNames, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, Pointer<JSValueRef> exception)
Creates a function with a given script as its body. ctx The execution context to use. name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function. parameterCount An integer count of the number of parameter names in parameterNames. parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0. body A JSString containing the script to use as the function's body. sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. @result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype. @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
final
JSObjectMakeFunctionWithCallback JSObjectRef Function(JSContextRef ctx, JSStringRef name, Pointer<NativeFunction<JSObjectCallAsFunctionCallback>> callAsFunction)
Convenience method for creating a JavaScript function with a given callback as its implementation. ctx The execution context to use. name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function. callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called. @result A JSObject that is a function. The object's prototype will be the default function prototype.
final
JSObjectMakeRegExp JSObjectRef Function(JSContextRef ctx, int argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor. ctx The execution context to use. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObject that is a RegExp.
final
JSObjectMakeTypedArray JSObjectRef Function(JSContextRef ctx, int arrayType, int length, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Creates a JavaScript Typed Array object with the given number of elements. ctx The execution context to use. arrayType A value identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned. length The number of elements to be in the new Typed Array. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef that is a Typed Array with all elements set to zero or NULL if there was an error.
final
JSObjectMakeTypedArrayWithArrayBuffer JSObjectRef Function(JSContextRef ctx, int arrayType, JSObjectRef buffer, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Creates a JavaScript Typed Array object from an existing JavaScript Array Buffer object. ctx The execution context to use. arrayType A value identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned. buffer An Array Buffer object that should be used as the backing store for the created JavaScript Typed Array object. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef that is a Typed Array or NULL if there was an error. The backing store of the Typed Array will be buffer.
final
JSObjectMakeTypedArrayWithArrayBufferAndOffset JSObjectRef Function(JSContextRef ctx, int arrayType, JSObjectRef buffer, int byteOffset, int length, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Creates a JavaScript Typed Array object from an existing JavaScript Array Buffer object with the given offset and length. ctx The execution context to use. arrayType A value identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned. buffer An Array Buffer object that should be used as the backing store for the created JavaScript Typed Array object. byteOffset The byte offset for the created Typed Array. byteOffset should aligned with the element size of arrayType. length The number of elements to include in the Typed Array. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef that is a Typed Array or NULL if there was an error. The backing store of the Typed Array will be buffer.
final
JSObjectMakeTypedArrayWithBytesNoCopy JSObjectRef Function(JSContextRef ctx, int arrayType, Pointer<Void> bytes, int byteLength, Pointer<NativeFunction<JSTypedArrayBytesDeallocator>> bytesDeallocator, Pointer<Void> deallocatorContext, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Creates a JavaScript Typed Array object from an existing pointer. ctx The execution context to use. arrayType A value identifying the type of array to create. If arrayType is kJSTypedArrayTypeNone or kJSTypedArrayTypeArrayBuffer then NULL will be returned. bytes A pointer to the byte buffer to be used as the backing store of the Typed Array object. byteLength The number of bytes pointed to by the parameter bytes. bytesDeallocator The allocator to use to deallocate the external buffer when the JSTypedArrayData object is deallocated. deallocatorContext A pointer to pass back to the deallocator. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSObjectRef Typed Array whose backing store is the same as the one pointed to by bytes or NULL if there was an error. @discussion If an exception is thrown during this function the bytesDeallocator will always be called.
final
JSObjectSetPrivate bool Function(JSObjectRef object, Pointer<Void> data)
Sets a pointer to private data on an object. object The JSObject whose private data you want to set. data A void* to set as the object's private data. @result true if object can store private data, otherwise false. @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
final
JSObjectSetProperty → void Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, int attributes, Pointer<JSValueRef> exception)
Sets a property on an object. ctx The execution context to use. object The JSObject whose property you want to set. propertyName A JSString containing the property's name. value A JSValueRef to use as the property's value. attributes A logically ORed set of JSPropertyAttributes to give to the property. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
final
JSObjectSetPropertyAtIndex → void Function(JSContextRef ctx, JSObjectRef object, int propertyIndex, JSValueRef value, Pointer<JSValueRef> exception)
Sets a property on an object by numeric index. ctx The execution context to use. object The JSObject whose property you want to set. propertyIndex The property's name as a number. value A JSValue to use as the property's value. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
final
JSObjectSetPropertyForKey → void Function(JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, int attributes, Pointer<JSValueRef> exception)
MacOS 10.15, iOS 13.0 Sets a property on an object using a JSValueRef as the property key. ctx The execution context to use. object The JSObject whose property you want to set. propertyKey A JSValueRef containing the property key to use when looking up the property. value A JSValueRef to use as the property's value. attributes A logically ORed set of JSPropertyAttributes to give to the property. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @discussion This function is the same as performing "objectpropertyKey = value" from JavaScript.
final
JSObjectSetPrototype → void Function(JSContextRef ctx, JSObjectRef object, JSValueRef value)
Sets an object's prototype. ctx The execution context to use. object The JSObject whose prototype you want to set. value A JSValue to set as the object's prototype.
final
JSPropertyNameAccumulatorAddName → void Function(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName)
Adds a property name to a JavaScript property name accumulator. accumulator The accumulator object to which to add the property name. propertyName The property name to add.
final
JSPropertyNameArrayGetCount int Function(JSPropertyNameArrayRef array)
Gets a count of the number of items in a JavaScript property name array. array The array from which to retrieve the count. @result An integer count of the number of names in array.
final
JSPropertyNameArrayGetNameAtIndex JSStringRef Function(JSPropertyNameArrayRef array, int index)
Gets a property name at a given index in a JavaScript property name array. array The array from which to retrieve the property name. index The index of the property name to retrieve. @result A JSStringRef containing the property name.
final
JSPropertyNameArrayRelease → void Function(JSPropertyNameArrayRef array)
Releases a JavaScript property name array. array The JSPropetyNameArray to release.
final
JSPropertyNameArrayRetain JSPropertyNameArrayRef Function(JSPropertyNameArrayRef array)
Retains a JavaScript property name array. array The JSPropertyNameArray to retain. @result A JSPropertyNameArray that is the same as array.
final
JSStringCreateWithCharacters JSStringRef Function(Pointer<JSChar> chars, int numChars)
Creates a JavaScript string from a buffer of Unicode characters. chars The buffer of Unicode characters to copy into the new JSString. numChars The number of characters to copy from the buffer pointed to by chars. @result A JSString containing chars. Ownership follows the Create Rule.
final
JSStringCreateWithUTF8CString JSStringRef Function(Pointer<Utf8> string)
Creates a JavaScript string from a null-terminated UTF8 string. string The null-terminated UTF8 string to copy into the new JSString. @result A JSString containing string. Ownership follows the Create Rule.
final
JSStringGetCharactersPtr Pointer<JSChar> Function(JSStringRef string)
Returns a pointer to the Unicode character buffer that serves as the backing store for a JavaScript string. string The JSString whose backing store you want to access. @result A pointer to the Unicode character buffer that serves as string's backing store, which will be deallocated when string is deallocated.
final
JSStringGetLength int Function(JSStringRef string)
Returns the number of Unicode characters in a JavaScript string. string The JSString whose length (in Unicode characters) you want to know. @result The number of Unicode characters stored in string.
final
JSStringGetMaximumUTF8CStringSize int Function(JSStringRef string)
Returns the maximum number of bytes a JavaScript string will take up if converted into a null-terminated UTF8 string. string The JSString whose maximum converted size (in bytes) you want to know. @result The maximum number of bytes that could be required to convert string into a null-terminated UTF8 string. The number of bytes that the conversion actually ends up requiring could be less than this, but never more.
final
JSStringGetUTF8CString int Function(JSStringRef string, Pointer<Char> buffer, int bufferSize)
Converts a JavaScript string into a null-terminated UTF8 string, and copies the result into an external byte buffer. string The source JSString. buffer The destination byte buffer into which to copy a null-terminated UTF8 representation of string. On return, buffer contains a UTF8 string representation of string. If bufferSize is too small, buffer will contain only partial results. If buffer is not at least bufferSize bytes in size, behavior is undefined. bufferSize The size of the external buffer in bytes. @result The number of bytes written into buffer (including the null-terminator byte).
final
JSStringIsEqual bool Function(JSStringRef a, JSStringRef b)
Tests whether two JavaScript strings match. a The first JSString to test. b The second JSString to test. @result true if the two strings match, otherwise false.
final
JSStringIsEqualToUTF8CString bool Function(JSStringRef a, Pointer<Utf8> b)
Tests whether a JavaScript string matches a null-terminated UTF8 string. a The JSString to test. b The null-terminated UTF8 string to test. @result true if the two strings match, otherwise false.
final
JSStringRelease → void Function(JSStringRef string)
Releases a JavaScript string. string The JSString to release.
final
JSStringRetain JSStringRef Function(JSStringRef string)
Retains a JavaScript string. string The JSString to retain. @result A JSString that is the same as string.
final
JSValueCreateJSONString JSStringRef Function(JSContextRef ctx, JSValueRef value, int indent, Pointer<JSValueRef> exception)
Creates a JavaScript string containing the JSON serialized representation of a JS value. ctx The execution context to use. value The value to serialize. indent The number of spaces to indent when nesting. If 0, the resulting JSON will not contains newlines. The size of the indent is clamped to 10 spaces. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSString with the result of serialization, or NULL if an exception is thrown.
final
JSValueGetType int Function(JSContextRef ctx, JSValueRef value)
Returns a JavaScript value's type. ctx The execution context to use. value The JSValue whose type you want to obtain. @result A value of type JSType that identifies value's type.
final
JSValueGetTypedArrayType int Function(JSContextRef ctx, JSValueRef value, Pointer<JSValueRef> exception)
MacOS 10.12, iOS 10.0 Returns a JavaScript value's Typed Array type. ctx The execution context to use. value The JSValue whose Typed Array type to return. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A value of type JSTypedArrayType that identifies value's Typed Array type, or kJSTypedArrayTypeNone if the value is not a Typed Array object.
final
JSValueIsArray bool Function(JSContextRef ctx, JSValueRef value)
MacOS 10.11, iOS 9.0 Tests whether a JavaScript value is an array. ctx The execution context to use. value The JSValue to test. @result true if value is an array, otherwise false.
final
JSValueIsBoolean bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the boolean type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the boolean type, otherwise false.
final
JSValueIsDate bool Function(JSContextRef ctx, JSValueRef value)
MacOS 10.11, iOS 9.0 Tests whether a JavaScript value is a date. ctx The execution context to use. value The JSValue to test. @result true if value is a date, otherwise false.
final
JSValueIsEqual bool Function(JSContextRef ctx, JSValueRef a, JSValueRef b, Pointer<JSValueRef> exception)
Tests whether two JavaScript values are equal, as compared by the JS == operator. ctx The execution context to use. a The first value to test. b The second value to test. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result true if the two values are equal, false if they are not equal or an exception is thrown.
final
JSValueIsInstanceOfConstructor bool Function(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, Pointer<JSValueRef> exception)
Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator. ctx The execution context to use. value The JSValue to test. constructor The constructor to test against. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
final
JSValueIsNull bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the null type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the null type, otherwise false.
final
JSValueIsNumber bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the number type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the number type, otherwise false.
final
JSValueIsObject bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the object type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the object type, otherwise false.
final
JSValueIsObjectOfClass bool Function(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
Tests whether a JavaScript value is an object with a given class in its class chain. ctx The execution context to use. value The JSValue to test. jsClass The JSClass to test against. @result true if value is an object and has jsClass in its class chain, otherwise false.
final
JSValueIsStrictEqual bool Function(JSContextRef ctx, JSValueRef a, JSValueRef b)
Tests whether two JavaScript values are strict equal, as compared by the JS === operator. ctx The execution context to use. a The first value to test. b The second value to test. @result true if the two values are strict equal, otherwise false.
final
JSValueIsString bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the string type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the string type, otherwise false.
final
JSValueIsSymbol bool Function(JSContextRef ctx, JSValueRef value)
MacOS 10.15, iOS 13.0 Tests whether a JavaScript value's type is the symbol type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the symbol type, otherwise false.
final
JSValueIsUndefined bool Function(JSContextRef ctx, JSValueRef value)
Tests whether a JavaScript value's type is the undefined type. ctx The execution context to use. value The JSValue to test. @result true if value's type is the undefined type, otherwise false.
final
JSValueMakeBoolean JSValueRef Function(JSContextRef ctx, bool boolean)
Creates a JavaScript value of the boolean type. ctx The execution context to use. boolean The bool to assign to the newly created JSValue. @result A JSValue of the boolean type, representing the value of boolean.
final
JSValueMakeFromJSONString JSValueRef Function(JSContextRef ctx, JSStringRef string)
Creates a JavaScript value from a JSON formatted string. ctx The execution context to use. string The JSString containing the JSON string to be parsed. @result A JSValue containing the parsed value, or NULL if the input is invalid.
final
JSValueMakeNull JSValueRef Function(JSContextRef ctx)
Creates a JavaScript value of the null type. ctx The execution context to use. @result The unique null value.
final
JSValueMakeNumber JSValueRef Function(JSContextRef ctx, double number)
Creates a JavaScript value of the number type. ctx The execution context to use. number The double to assign to the newly created JSValue. @result A JSValue of the number type, representing the value of number.
final
JSValueMakeString JSValueRef Function(JSContextRef ctx, JSStringRef string)
Creates a JavaScript value of the string type. ctx The execution context to use. string The JSString to assign to the newly created JSValue. The newly created JSValue retains string, and releases it upon garbage collection. @result A JSValue of the string type, representing the value of string.
final
JSValueMakeSymbol JSValueRef Function(JSContextRef ctx, JSStringRef description)
MacOS 10.15, iOS 13.0 Creates a JavaScript value of the symbol type. ctx The execution context to use. description A description of the newly created symbol value. @result A unique JSValue of the symbol type, whose description matches the one provided.
final
JSValueMakeUndefined JSValueRef Function(JSContextRef ctx)
Creates a JavaScript value of the undefined type. ctx The execution context to use. @result The unique undefined value.
final
JSValueProtect → void Function(JSContextRef ctx, JSValueRef value)
Protects a JavaScript value from garbage collection. ctx The execution context to use. value The JSValue to protect. @discussion Use this method when you want to store a JSValue in a global or on the heap, where the garbage collector will not be able to discover your reference to it.
final
JSValueToBoolean bool Function(JSContextRef ctx, JSValueRef value)
Converts a JavaScript value to boolean and returns the resulting boolean. ctx The execution context to use. value The JSValue to convert. @result The boolean result of conversion.
final
JSValueToNumber double Function(JSContextRef ctx, JSValueRef value, Pointer<JSValueRef> exception)
Converts a JavaScript value to number and returns the resulting number. ctx The execution context to use. value The JSValue to convert. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The numeric result of conversion, or NaN if an exception is thrown. JS_EXPORT double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
final
JSValueToObject JSObjectRef Function(JSContextRef ctx, JSValueRef value, Pointer<JSValueRef> exception)
Converts a JavaScript value to object and returns the resulting object. ctx The execution context to use. value The JSValue to convert. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result The JSObject result of conversion, or NULL if an exception is thrown.
final
JSValueToStringCopy JSStringRef Function(JSContextRef ctx, JSValueRef value, Pointer<JSValueRef> exception)
Converts a JavaScript value to string and copies the result into a JavaScript string. ctx The execution context to use. value The JSValue to convert. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. @result A JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
final
JSValueUnprotect → void Function(JSContextRef ctx, JSValueRef value)
Unprotects a JavaScript value from garbage collection. ctx The execution context to use. value The JSValue to unprotect. @discussion A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection. JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
final

Typedefs

JSChar = UnsignedShort
JSClassRef = Pointer<OpaqueJSClass>
JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior.
JSContextGroupRef = Pointer<OpaqueJSContextGroup>
JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects.
JSContextRef = Pointer<OpaqueJSContext>
JSContextRef A JavaScript execution context. Holds the global object and other execution state.
JSGlobalContextRef = JSContextRef
JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext.
JSObjectCallAsConstructorCallback = JSObjectRef Function(JSContextRef ctx, JSObjectRef constructor, Size argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
The callback invoked when an object is used as a constructor in a 'new' expression. ctx The execution context to use. constructor A JSObject that is the constructor being called. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of the arguments passed to the function. exception A pointer to a JSValueRef in which to return an exception, if any. @result A JSObject that is the constructor's return value. @discussion If you named your function CallAsConstructor, you would declare it like this:
JSObjectCallAsFunctionCallback = JSValueRef Function(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, Size argumentCount, Pointer<JSValueRef> arguments, Pointer<JSValueRef> exception)
The callback invoked when an object is called as a function. ctx The execution context to use. function A JSObject that is the function being called. thisObject A JSObject that is the 'this' variable in the function's scope. argumentCount An integer count of the number of arguments in arguments. arguments A JSValue array of the arguments passed to the function. exception A pointer to a JSValueRef in which to return an exception, if any. @result A JSValue that is the function's return value. @discussion If you named your function CallAsFunction, you would declare it like this:
JSObjectConvertToTypeCallback = JSValueRef Function(JSContextRef ctx, JSObjectRef object, Int8 type, Pointer<JSValueRef> exception)
The callback invoked when converting an object to a particular JavaScript type. ctx The execution context to use. object The JSObject to convert. type A JSType specifying the JavaScript type to convert to. exception A pointer to a JSValueRef in which to return an exception, if any. @result The objects's converted value, or NULL if the object was not converted. @discussion If you named your function ConvertToType, you would declare it like this:
JSObjectDeletePropertyCallback = Bool Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, Pointer<JSValueRef> exception)
The callback invoked when deleting a property. ctx The execution context to use. object The JSObject in which to delete the property. propertyName A JSString containing the name of the property to delete. exception A pointer to a JSValueRef in which to return an exception, if any. @result true if propertyName was successfully deleted, otherwise false. @discussion If you named your function DeleteProperty, you would declare it like this:
JSObjectFinalizeCallback = Void Function(JSObjectRef object)
The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread. object The JSObject being finalized. @discussion If you named your function Finalize, you would declare it like this:
JSObjectGetPropertyCallback = JSValueRef Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, Pointer<JSValueRef> exception)
The callback invoked when getting a property's value. ctx The execution context to use. object The JSObject to search for the property. propertyName A JSString containing the name of the property to get. exception A pointer to a JSValueRef in which to return an exception, if any. @result The property's value if object has the property, otherwise NULL. @discussion If you named your function GetProperty, you would declare it like this:
JSObjectGetPropertyNamesCallback = Void Function(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
The callback invoked when collecting the names of an object's properties. ctx The execution context to use. object The JSObject whose property names are being collected. propertyNames A JavaScript property name accumulator in which to accumulate the names of object's properties. @discussion If you named your function GetPropertyNames, you would declare it like this:
JSObjectHasInstanceCallback = Bool Function(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, Pointer<JSValueRef> exception)
hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression. ctx The execution context to use. constructor The JSObject that is the target of the 'instanceof' expression. possibleInstance The JSValue being tested to determine if it is an instance of constructor. exception A pointer to a JSValueRef in which to return an exception, if any. @result true if possibleInstance is an instance of constructor, otherwise false. @discussion If you named your function HasInstance, you would declare it like this:
JSObjectHasPropertyCallback = Bool Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
The callback invoked when determining whether an object has a property. ctx The execution context to use. object The JSObject to search for the property. propertyName A JSString containing the name of the property look up. @result true if object has the property, otherwise false. @discussion If you named your function HasProperty, you would declare it like this:
JSObjectInitializeCallback = Void Function(JSContextRef ctx, JSObjectRef object)
The callback invoked when an object is first created. ctx The execution context to use. object The JSObject being created. @discussion If you named your function Initialize, you would declare it like this:
JSObjectRef = Pointer<OpaqueJSValue>
JSObjectRef A JavaScript object. A JSObject is a JSValue.
JSObjectSetPropertyCallback = Bool Function(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, Pointer<JSValueRef> exception)
The callback invoked when setting a property's value. ctx The execution context to use. object The JSObject on which to set the property's value. propertyName A JSString containing the name of the property to set. value A JSValue to use as the property's value. exception A pointer to a JSValueRef in which to return an exception, if any. @result true if the property was set, otherwise false. @discussion If you named your function SetProperty, you would declare it like this:
JSPropertyNameAccumulatorRef = Pointer<OpaqueJSPropertyNameAccumulator>
JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties.
JSPropertyNameArrayRef = Pointer<OpaqueJSPropertyNameArray>
JSPropertyNameArrayRef An array of JavaScript property names.
JSStringRef = Pointer<OpaqueJSString>
JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript.
JSTypedArrayBytesDeallocator = Void Function(Pointer<Void> bytes, Pointer<Void> deallocatorContext)
JSTypedArrayBytesDeallocator A function used to deallocate bytes passed to a Typed Array constructor. The function should take two arguments. The first is a pointer to the bytes that were originally passed to the Typed Array constructor. The second is a pointer to additional information desired at the time the bytes are to be freed.
JSValueRef = Pointer<OpaqueJSValue>
JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them.