docs
Loading...
Searching...
No Matches
JSObjectRef.h

Classes

struct  JSStaticValue
 This structure describes a statically declared value property. More...
struct  JSStaticValueEx
struct  JSStaticFunction
 This structure describes a statically declared function property. More...
struct  JSStaticFunctionEx
struct  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. More...

Functions

JSClassRef JSClassCreate (const JSClassDefinition *definition)
 Creates a JavaScript class suitable for use with JSObjectMake.
JSClassRef JSClassRetain (JSClassRef jsClass)
 Retains a JavaScript class.
void JSClassRelease (JSClassRef jsClass)
 Releases a JavaScript class.
JSObjectRef JSObjectMake (JSContextRef ctx, JSClassRef jsClass, void *data)
 Creates a JavaScript object.
JSObjectRef JSObjectMakeFunctionWithCallback (JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
 Convenience method for creating a JavaScript function with a given callback as its implementation.
JSObjectRef JSObjectMakeConstructor (JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
 Convenience method for creating a JavaScript constructor.
JSObjectRef JSObjectMakeArray (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
 Creates a JavaScript Array object.
JSObjectRef ios (7.0))
JSObjectRef JSObjectMakeDate (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
 Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
JSObjectRef JSObjectMakeError (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
 Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
JSObjectRef JSObjectMakeRegExp (JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) JSC_API_AVAILABLE(macos(10.6)
 Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
JSObjectRef JSObjectMakeDeferredPromise (JSContextRef ctx, JSObjectRef *resolve, JSObjectRef *reject, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
 Creates a JavaScript promise object by invoking the provided executor.
JSObjectRef ios (13.0))
JSObjectRef JSObjectMakeFunction (JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef *exception)
 Creates a function with a given script as its body.
JSValueRef JSObjectGetPrototype (JSContextRef ctx, JSObjectRef object)
 Gets an object's prototype.
void JSObjectSetPrototype (JSContextRef ctx, JSObjectRef object, JSValueRef value)
 Sets an object's prototype.
bool JSObjectHasProperty (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
 Tests whether an object has a given property.
JSValueRef JSObjectGetProperty (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 Gets a property from an object.
void JSObjectSetProperty (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef *exception)
 Sets a property on an object.
bool JSObjectDeleteProperty (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 Deletes a property from an object.
bool JSObjectHasPropertyForKey (JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
 Tests whether an object has a given property using a JSValueRef as the property key.
JSValueRef JSObjectGetPropertyForKey (JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
 Gets a property from an object using a JSValueRef as the property key.
void JSObjectSetPropertyForKey (JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef value, JSPropertyAttributes attributes, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
 Sets a property on an object using a JSValueRef as the property key.
bool JSObjectDeletePropertyForKey (JSContextRef ctx, JSObjectRef object, JSValueRef propertyKey, JSValueRef *exception) JSC_API_AVAILABLE(macos(10.15)
 Deletes a property from an object using a JSValueRef as the property key.
JSValueRef JSObjectGetPropertyAtIndex (JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef *exception)
 Gets a property from an object by numeric index.
void JSObjectSetPropertyAtIndex (JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef *exception)
 Sets a property on an object by numeric index.
void * JSObjectGetPrivate (JSObjectRef object)
 Gets an object's private data.
bool JSObjectSetPrivate (JSObjectRef object, void *data)
 Sets a pointer to private data on an object.
bool JSObjectIsFunction (JSContextRef ctx, JSObjectRef object)
 Tests whether an object can be called as a function.
JSValueRef JSObjectCallAsFunction (JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 Calls an object as a function.
bool JSObjectIsConstructor (JSContextRef ctx, JSObjectRef object)
 Tests whether an object can be called as a constructor.
JSObjectRef JSObjectCallAsConstructor (JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 Calls an object as a constructor.
JSPropertyNameArrayRef JSObjectCopyPropertyNames (JSContextRef ctx, JSObjectRef object)
 Gets the names of an object's enumerable properties.
JSPropertyNameArrayRef JSPropertyNameArrayRetain (JSPropertyNameArrayRef array)
 Retains a JavaScript property name array.
void JSPropertyNameArrayRelease (JSPropertyNameArrayRef array)
 Releases a JavaScript property name array.
size_t JSPropertyNameArrayGetCount (JSPropertyNameArrayRef array)
 Gets a count of the number of items in a JavaScript property name array.
JSStringRef JSPropertyNameArrayGetNameAtIndex (JSPropertyNameArrayRef array, size_t index)
 Gets a property name at a given index in a JavaScript property name array.
void JSPropertyNameAccumulatorAddName (JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName)
 Adds a property name to a JavaScript property name accumulator.
void * JSClassGetPrivate (JSClassRef jsClass)
 Gets the private data from a JSClass (version 1000 only).
bool JSClassSetPrivate (JSClassRef jsClass, void *data)
 Sets the private data for a JSClass (version 1000 only).
JSObjectRef JSObjectMakeFunctionWithData (JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionDataCallback callAsFunction, void *userData, JSFunctionDataFinalizeCallback finalize)
 Creates a JavaScript function with a callback, a user data pointer, and an optional finalizer.
bool JSObjectGetPropertiesUTF8 (JSContextRef ctx, JSObjectRef object, const char *const *names, size_t count, JSValueRef *outValues, JSValueRef *exception)
 Gets multiple properties of an object in one call, using UTF-8 property names.
bool JSObjectSetPropertiesUTF8 (JSContextRef ctx, JSObjectRef object, const char *const *names, const JSValueRef *values, size_t count, unsigned attributes, JSValueRef *exception)
 Sets multiple properties of an object in one call, using UTF-8 property names.
JSObjectRef JSObjectMakeWithPropertiesUTF8 (JSContextRef ctx, const char *const *names, const JSValueRef *values, size_t count, JSValueRef *exception)
 Creates a JavaScript object initialized with a set of properties, using UTF-8 property names.
bool JSObjectGetOwnEntriesUTF8 (JSContextRef ctx, JSObjectRef object, size_t start, JSStringRef *outNames, JSValueRef *outValues, size_t capacity, size_t *outCount, JSValueRef *exception)
 Gets an object's own enumerable string-keyed properties (names and values) in one call.
bool JSObjectDefineAccessorUTF8 (JSContextRef ctx, JSObjectRef object, const char *name, JSObjectRef getter, JSObjectRef setter, unsigned attributes, JSValueRef *exception)
 Defines an accessor (getter/setter) property on an object, using a UTF-8 property name.
bool JSObjectDefinePropertyUTF8 (JSContextRef ctx, JSObjectRef object, const char *name, JSValueRef value, unsigned attributes, JSValueRef *exception)
 Defines an own data property on an object with the given attributes, equivalent to Object.defineProperty.
bool JSObjectFreeze (JSContextRef ctx, JSObjectRef object, JSValueRef *exception)
 Freezes an object, equivalent to Object.freeze.
JSObjectRef JSObjectMakeTypedError (JSContextRef ctx, JSTypedErrorType type, JSStringRef message)
 Creates a JavaScript error object of a given type.
bool JSPromiseGetStatus (JSContextRef ctx, JSObjectRef promise, JSPromiseStatus *outStatus)
 Gets the state of a JavaScript Promise without scheduling any reaction.
JSValueRef JSPromiseGetResult (JSContextRef ctx, JSObjectRef promise)
 Gets the settled result of a JavaScript Promise: its value if fulfilled, or its rejection reason if rejected.
bool JSPromiseMarkAsHandled (JSContextRef ctx, JSObjectRef promise)
 Marks a JavaScript Promise as handled for unhandled-rejection reporting.
bool JSObjectSetExternalMemoryHint (JSContextRef ctx, JSObjectRef object, size_t bytes)
 Reports the amount of non-JavaScript memory kept alive by an object, to guide garbage collection.

Variables

const JSClassDefinition kJSClassDefinitionEmpty
 A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.

Typedefs

typedef unsigned JSPropertyAttributes
 A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
typedef unsigned JSClassAttributes
 A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
typedef void(*) JSObjectInitializeCallback(JSContextRef ctx, JSObjectRef object)
 The callback invoked when an object is first created.
typedef void(*) JSObjectInitializeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object)
typedef void(*) JSObjectFinalizeCallback(JSObjectRef object)
 The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
typedef void(*) JSObjectFinalizeCallbackEx(JSClassRef jsClass, JSObjectRef object)
typedef bool(*) JSObjectHasPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
 The callback invoked when determining whether an object has a property.
typedef bool(*) JSObjectHasPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName)
typedef JSValueRef(*) JSObjectGetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 The callback invoked when getting a property's value.
typedef JSValueRef(*) JSObjectGetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
typedef bool(*) JSObjectSetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
 The callback invoked when setting a property's value.
typedef bool(*) JSObjectSetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)
typedef bool(*) JSObjectDeletePropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 The callback invoked when deleting a property.
typedef bool(*) JSObjectDeletePropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
typedef void(*) JSObjectGetPropertyNamesCallback(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
 The callback invoked when collecting the names of an object's properties.
typedef void(*) JSObjectGetPropertyNamesCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
typedef JSValueRef(*) JSObjectCallAsFunctionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 The callback invoked when an object is called as a function.
typedef JSValueRef(*) JSObjectCallAsFunctionCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSStringRef className, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
typedef JSValueRef(*) JSObjectCallAsFunctionDataCallback(JSContextRef ctx, void *userData, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 The callback invoked when a function created with JSObjectMakeFunctionWithData is called.
typedef void(*) JSFunctionDataFinalizeCallback(void *userData)
 The callback invoked when a function created with JSObjectMakeFunctionWithData is garbage collected.
typedef JSObjectRef(*) JSObjectCallAsConstructorCallback(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 The callback invoked when an object is used as a constructor in a 'new' expression.
typedef JSObjectRef(*) JSObjectCallAsConstructorCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
typedef bool(*) JSObjectHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)
 hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
typedef bool(*) JSObjectHasInstanceCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)
typedef JSValueRef(*) JSObjectConvertToTypeCallback(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef *exception)
 The callback invoked when converting an object to a particular JavaScript type.
typedef JSValueRef(*) JSObjectConvertToTypeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSType type, JSValueRef *exception)

Enumerations

enum  { kJSPropertyAttributeNone = 0 , kJSPropertyAttributeReadOnly = 1 << 1 , kJSPropertyAttributeDontEnum = 1 << 2 , kJSPropertyAttributeDontDelete = 1 << 3 }
enum  { kJSClassAttributeNone = 0 , kJSClassAttributeNoAutomaticPrototype = 1 << 1 }
enum  JSPromiseStatus { kJSPromiseStatus_Pending = 0 , kJSPromiseStatus_Fulfilled = 1 , kJSPromiseStatus_Rejected = 2 }
 The possible states of a JavaScript Promise. More...

Function Documentation

◆ ios() [1/2]

JSObjectRef ios ( 13. 0)

◆ ios() [2/2]

JSObjectRef ios ( 7. 0)

◆ JSClassCreate()

JSClassRef JSClassCreate ( const JSClassDefinition * definition)

Creates a JavaScript class suitable for use with JSObjectMake.

Parameters
definitionA JSClassDefinition that defines the class.
Returns
A JSClass with the given definition. Ownership follows the Create Rule.

◆ JSClassGetPrivate()

void * JSClassGetPrivate ( JSClassRef jsClass)

Gets the private data from a JSClass (version 1000 only).

Parameters
jsClassThe JSClass whose private data you want to get.
Returns
The private data for the class, or NULL if the class is not version 1000.

◆ JSClassRelease()

void JSClassRelease ( JSClassRef jsClass)

Releases a JavaScript class.

Parameters
jsClassThe JSClass to release.

◆ JSClassRetain()

JSClassRef JSClassRetain ( JSClassRef jsClass)

Retains a JavaScript class.

Parameters
jsClassThe JSClass to retain.
Returns
A JSClass that is the same as jsClass.

◆ JSClassSetPrivate()

bool JSClassSetPrivate ( JSClassRef jsClass,
void * data )

Sets the private data for a JSClass (version 1000 only).

Parameters
jsClassThe JSClass whose private data you want to set.
dataThe private data to set.
Returns
true if the private data was set (class is version 1000), false otherwise.

◆ JSObjectCallAsConstructor()

JSObjectRef JSObjectCallAsConstructor ( JSContextRef ctx,
JSObjectRef object,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Calls an object as a constructor.

Parameters
ctxThe execution context to use.
objectThe JSObject to call as a constructor.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.

◆ JSObjectCallAsFunction()

JSValueRef JSObjectCallAsFunction ( JSContextRef ctx,
JSObjectRef object,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Calls an object as a function.

Parameters
ctxThe execution context to use.
objectThe JSObject to call as a function.
thisObjectThe object to use as "this," or NULL to use the global object as "this."
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.

◆ JSObjectCopyPropertyNames()

JSPropertyNameArrayRef JSObjectCopyPropertyNames ( JSContextRef ctx,
JSObjectRef object )

Gets the names of an object's enumerable properties.

Parameters
ctxThe execution context to use.
objectThe object whose property names you want to get.
Returns
A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.

◆ JSObjectDefineAccessorUTF8()

bool JSObjectDefineAccessorUTF8 ( JSContextRef ctx,
JSObjectRef object,
const char * name,
JSObjectRef getter,
JSObjectRef setter,
unsigned attributes,
JSValueRef * exception )

Defines an accessor (getter/setter) property on an object, using a UTF-8 property name.

Parameters
ctxThe execution context to use.
objectThe JSObject on which to define the accessor.
nameA null-terminated UTF-8 string containing the property name.
getterA JSObject that is a function to invoke on property reads. May be NULL to define a write-only accessor.
setterA JSObject that is a function to invoke on property writes. May be NULL to define a read-only accessor.
attributesA logically ORed set of JSPropertyAttributes to give to the property. kJSPropertyAttributeReadOnly is ignored for accessors.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the accessor was defined; false if an exception was thrown (for example, redefining a non-configurable property, or passing a non-callable getter or setter).
Note
At least one of getter and setter must be non-NULL.

◆ JSObjectDefinePropertyUTF8()

bool JSObjectDefinePropertyUTF8 ( JSContextRef ctx,
JSObjectRef object,
const char * name,
JSValueRef value,
unsigned attributes,
JSValueRef * exception )

Defines an own data property on an object with the given attributes, equivalent to Object.defineProperty.

Parameters
ctxThe execution context to use.
objectThe JSObject on which to define the property.
nameA null-terminated UTF-8 string containing the property name.
valueA JSValueRef that is the property value. Pass NULL for the undefined value.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the property was defined; false if the object refused it (for example, redefining a non-configurable property or adding a property to a frozen object).
Note
Unlike JSObjectSetProperty, this never falls back to ordinary assignment when a same-named property exists on the prototype chain: the attributes always apply, and setters never run.

◆ JSObjectDeleteProperty()

bool JSObjectDeleteProperty ( JSContextRef ctx,
JSObjectRef object,
JSStringRef propertyName,
JSValueRef * exception )

Deletes a property from an object.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to delete.
propertyNameA JSString containing the property's name.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).

◆ JSObjectDeletePropertyForKey()

bool JSObjectDeletePropertyForKey ( JSContextRef ctx,
JSObjectRef object,
JSValueRef propertyKey,
JSValueRef * exception )

Deletes a property from an object using a JSValueRef as the property key.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to delete.
propertyKeyA JSValueRef containing the property key to use when looking up the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
Note
This function is the same as performing "delete object[propertyKey]" from JavaScript.

◆ JSObjectFreeze()

bool JSObjectFreeze ( JSContextRef ctx,
JSObjectRef object,
JSValueRef * exception )

Freezes an object, equivalent to Object.freeze.

Parameters
ctxThe execution context to use.
objectThe JSObject to freeze.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the object was frozen; false if an exception was thrown (for example, a Proxy that refuses to prevent extensions).

◆ JSObjectGetOwnEntriesUTF8()

bool JSObjectGetOwnEntriesUTF8 ( JSContextRef ctx,
JSObjectRef object,
size_t start,
JSStringRef * outNames,
JSValueRef * outValues,
size_t capacity,
size_t * outCount,
JSValueRef * exception )

Gets an object's own enumerable string-keyed properties (names and values) in one call.

Parameters
ctxThe execution context to use.
objectThe JSObject whose entries you want to get.
startThe enumeration-order position to start reading entries from (0 reads from the beginning). Positions at or beyond the property count read nothing.
outNamesAn array that receives up to capacity JSStringRefs, one per property name. May be NULL if capacity is 0. Each returned string is owned by the caller, who is responsible for releasing it with JSStringRelease.
outValuesAn array that receives up to capacity property values. May be NULL if capacity is 0.
capacityThe number of entries the out arrays can hold.
outCountOn success, receives the total number of own enumerable string-keyed properties, which may exceed start + capacity. Pass a capacity of 0 to query the count without reading entries.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true on success; false if an exception was thrown, in which case the contents of the out arrays are unspecified.
Note
Entries are returned in the standard property enumeration order, matching Object.entries. Values are read with the object's ordinary get behavior, so getters run. The property set is re-enumerated per call, so a caller reading a large object in windows should expect skipped or repeated entries if a getter mutates the object between calls.

◆ JSObjectGetPrivate()

void * JSObjectGetPrivate ( JSObjectRef object)

Gets an object's private data.

Parameters
objectA JSObject whose private data you want to get.
Returns
A void* that is the object's private data, if the object has private data, otherwise NULL.

◆ JSObjectGetPropertiesUTF8()

bool JSObjectGetPropertiesUTF8 ( JSContextRef ctx,
JSObjectRef object,
const char *const * names,
size_t count,
JSValueRef * outValues,
JSValueRef * exception )

Gets multiple properties of an object in one call, using UTF-8 property names.

Parameters
ctxThe execution context to use.
objectThe JSObject whose properties you want to get.
namesAn array of count null-terminated UTF-8 property names.
countThe number of properties to get.
outValuesAn array of count JSValueRefs that receives the property values. A property that does not exist yields the undefined value.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if all properties were read; false if an exception was thrown, in which case the contents of outValues are unspecified.

◆ JSObjectGetProperty()

JSValueRef JSObjectGetProperty ( JSContextRef ctx,
JSObjectRef object,
JSStringRef propertyName,
JSValueRef * exception )

Gets a property from an object.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to get.
propertyNameA JSString containing the property's name.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
The property's value if object has the property, otherwise the undefined value.

◆ JSObjectGetPropertyAtIndex()

JSValueRef JSObjectGetPropertyAtIndex ( JSContextRef ctx,
JSObjectRef object,
unsigned propertyIndex,
JSValueRef * exception )

Gets a property from an object by numeric index.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to get.
propertyIndexAn integer value that is the property's name.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
The property's value if object has the property, otherwise the undefined value.
Note
Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.

◆ JSObjectGetPropertyForKey()

JSValueRef JSObjectGetPropertyForKey ( JSContextRef ctx,
JSObjectRef object,
JSValueRef propertyKey,
JSValueRef * exception )

Gets a property from an object using a JSValueRef as the property key.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to get.
propertyKeyA JSValueRef containing the property key to use when looking up the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
The property's value if object has the property key, otherwise the undefined value.
Note
This function is the same as performing "object[propertyKey]" from JavaScript.

◆ JSObjectGetPrototype()

JSValueRef JSObjectGetPrototype ( JSContextRef ctx,
JSObjectRef object )

Gets an object's prototype.

Parameters
ctxThe execution context to use.
objectA JSObject whose prototype you want to get.
Returns
A JSValue that is the object's prototype.

◆ JSObjectHasProperty()

bool JSObjectHasProperty ( JSContextRef ctx,
JSObjectRef object,
JSStringRef propertyName )

Tests whether an object has a given property.

Parameters
objectThe JSObject to test.
propertyNameA JSString containing the property's name.
Returns
true if the object has a property whose name matches propertyName, otherwise false.

◆ JSObjectHasPropertyForKey()

bool JSObjectHasPropertyForKey ( JSContextRef ctx,
JSObjectRef object,
JSValueRef propertyKey,
JSValueRef * exception )

Tests whether an object has a given property using a JSValueRef as the property key.

Parameters
objectThe JSObject to test.
propertyKeyA JSValueRef containing the property key to use when looking up the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if the object has a property whose name matches propertyKey, otherwise false.
Note
This function is the same as performing "propertyKey in object" from JavaScript.

◆ JSObjectIsConstructor()

bool JSObjectIsConstructor ( JSContextRef ctx,
JSObjectRef object )

Tests whether an object can be called as a constructor.

Parameters
ctxThe execution context to use.
objectThe JSObject to test.
Returns
true if the object can be called as a constructor, otherwise false.

◆ JSObjectIsFunction()

bool JSObjectIsFunction ( JSContextRef ctx,
JSObjectRef object )

Tests whether an object can be called as a function.

Parameters
ctxThe execution context to use.
objectThe JSObject to test.
Returns
true if the object can be called as a function, otherwise false.

◆ JSObjectMake()

JSObjectRef JSObjectMake ( JSContextRef ctx,
JSClassRef jsClass,
void * data )

Creates a JavaScript object.

Parameters
ctxThe execution context to use.
jsClassThe JSClass to assign to the object. Pass NULL to use the default object class.
dataA void* to set as the object's private data. Pass NULL to specify no private data.
Returns
A JSObject with the given class and private data.
Note

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.

data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.

◆ JSObjectMakeArray()

JSObjectRef JSObjectMakeArray ( JSContextRef ctx,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Creates a JavaScript Array object.

Parameters
ctxThe execution context to use.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject that is an Array.
Note
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.

◆ JSObjectMakeConstructor()

JSObjectRef JSObjectMakeConstructor ( JSContextRef ctx,
JSClassRef jsClass,
JSObjectCallAsConstructorCallback callAsConstructor )

Convenience method for creating a JavaScript constructor.

Parameters
ctxThe execution context to use.
jsClassA 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.
callAsConstructorA JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
Returns
A JSObject that is a constructor. The object's prototype will be the default object prototype.
Note
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.

◆ JSObjectMakeDate()

JSObjectRef JSObjectMakeDate ( JSContextRef ctx,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Creates a JavaScript Date object, as if by invoking the built-in Date constructor.

Parameters
ctxThe execution context to use.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject that is a Date.

◆ JSObjectMakeDeferredPromise()

JSObjectRef JSObjectMakeDeferredPromise ( JSContextRef ctx,
JSObjectRef * resolve,
JSObjectRef * reject,
JSValueRef * exception )

Creates a JavaScript promise object by invoking the provided executor.

Parameters
ctxThe execution context to use.
resolveA 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.
rejectA 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.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject that is a promise or NULL if an exception occurred.

◆ JSObjectMakeError()

JSObjectRef JSObjectMakeError ( JSContextRef ctx,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Creates a JavaScript Error object, as if by invoking the built-in Error constructor.

Parameters
ctxThe execution context to use.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject that is an Error.

◆ JSObjectMakeFunction()

JSObjectRef JSObjectMakeFunction ( JSContextRef ctx,
JSStringRef name,
unsigned parameterCount,
const JSStringRef parameterNames[],
JSStringRef body,
JSStringRef sourceURL,
int startingLineNumber,
JSValueRef * exception )

Creates a function with a given script as its body.

Parameters
ctxThe execution context to use.
nameA JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
parameterCountAn integer count of the number of parameter names in parameterNames.
parameterNamesA JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
bodyA JSString containing the script to use as the function's body.
sourceURLA 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.
startingLineNumberAn 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.
exceptionA 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.
Returns
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.
Note
Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.

◆ JSObjectMakeFunctionWithCallback()

JSObjectRef JSObjectMakeFunctionWithCallback ( JSContextRef ctx,
JSStringRef name,
JSObjectCallAsFunctionCallback callAsFunction )

Convenience method for creating a JavaScript function with a given callback as its implementation.

Parameters
ctxThe execution context to use.
nameA JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
callAsFunctionThe JSObjectCallAsFunctionCallback to invoke when the function is called.
Returns
A JSObject that is a function. The object's prototype will be the default function prototype.

◆ JSObjectMakeFunctionWithData()

JSObjectRef JSObjectMakeFunctionWithData ( JSContextRef ctx,
JSStringRef name,
JSObjectCallAsFunctionDataCallback callAsFunction,
void * userData,
JSFunctionDataFinalizeCallback finalize )

Creates a JavaScript function with a callback, a user data pointer, and an optional finalizer.

Parameters
ctxThe execution context to use.
nameA JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
callAsFunctionThe JSObjectCallAsFunctionDataCallback to invoke when the function is called. The userData pointer is passed to every invocation.
userDataA pointer to user data associated with the function. May be NULL.
finalizeA JSFunctionDataFinalizeCallback invoked exactly once when the function is garbage collected or its context group is destroyed. Pass NULL if no cleanup is needed.
Returns
A JSObject that is a function. The object's prototype will be the default function prototype.
Note
Unlike objects faked as callable through a JSClass, the returned object is a real function: it inherits from Function.prototype, so bind, call, and apply work on it from script.

◆ JSObjectMakeRegExp()

JSObjectRef JSObjectMakeRegExp ( JSContextRef ctx,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef * exception )

Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.

Parameters
ctxThe execution context to use.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject that is a RegExp.

◆ JSObjectMakeTypedError()

JSObjectRef JSObjectMakeTypedError ( JSContextRef ctx,
JSTypedErrorType type,
JSStringRef message )

Creates a JavaScript error object of a given type.

Parameters
ctxThe execution context to use.
typeThe JSTypedErrorType of error to create, for example kJSTypedError_TypeError.
messageA JSString containing the error message. May be NULL to create an error with no message.
Returns
A JSObject that is an error object of the given type, or NULL if creation failed.

◆ JSObjectMakeWithPropertiesUTF8()

JSObjectRef JSObjectMakeWithPropertiesUTF8 ( JSContextRef ctx,
const char *const * names,
const JSValueRef * values,
size_t count,
JSValueRef * exception )

Creates a JavaScript object initialized with a set of properties, using UTF-8 property names.

Parameters
ctxThe execution context to use.
namesAn array of count null-terminated UTF-8 property names.
valuesAn array of count JSValueRefs that are the property values.
countThe number of properties.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
A JSObject with the given properties, or NULL if an exception was thrown.

◆ JSObjectSetExternalMemoryHint()

bool JSObjectSetExternalMemoryHint ( JSContextRef ctx,
JSObjectRef object,
size_t bytes )

Reports the amount of non-JavaScript memory kept alive by an object, to guide garbage collection.

Parameters
ctxThe execution context to use.
objectThe JSObject the memory is attributed to.
bytesThe number of bytes of external memory the object keeps alive. Replaces any previously set hint. Pass 0 to clear the hint.
Returns
true if the hint was stored; false if the object cannot carry a hint, in which case nothing was reported.
Note
Use this when a small JavaScript wrapper pins a large native allocation, so that the collector can account for the true memory cost of the wrapper. The hint is attributed to the object for as long as it is alive and is dropped automatically when the object is collected. Only objects created with a non-NULL JSClass (for example via JSObjectMake) can carry a hint. The hint influences collection scheduling; it is not an exact accounting ledger.

◆ JSObjectSetPrivate()

bool JSObjectSetPrivate ( JSObjectRef object,
void * data )

Sets a pointer to private data on an object.

Parameters
objectThe JSObject whose private data you want to set.
dataA void* to set as the object's private data.
Returns
true if object can store private data, otherwise false.
Note
The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.

◆ JSObjectSetPropertiesUTF8()

bool JSObjectSetPropertiesUTF8 ( JSContextRef ctx,
JSObjectRef object,
const char *const * names,
const JSValueRef * values,
size_t count,
unsigned attributes,
JSValueRef * exception )

Sets multiple properties of an object in one call, using UTF-8 property names.

Parameters
ctxThe execution context to use.
objectThe JSObject whose properties you want to set.
namesAn array of count null-terminated UTF-8 property names.
valuesAn array of count JSValueRefs that are the property values to set.
countThe number of properties to set.
attributesA logically ORed set of JSPropertyAttributes to give to each property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Returns
true if all properties were set; false if an exception was thrown. Properties before the failing one remain set.

◆ JSObjectSetProperty()

void JSObjectSetProperty ( JSContextRef ctx,
JSObjectRef object,
JSStringRef propertyName,
JSValueRef value,
JSPropertyAttributes attributes,
JSValueRef * exception )

Sets a property on an object.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to set.
propertyNameA JSString containing the property's name.
valueA JSValueRef to use as the property's value.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.

◆ JSObjectSetPropertyAtIndex()

void JSObjectSetPropertyAtIndex ( JSContextRef ctx,
JSObjectRef object,
unsigned propertyIndex,
JSValueRef value,
JSValueRef * exception )

Sets a property on an object by numeric index.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to set.
propertyIndexThe property's name as a number.
valueA JSValue to use as the property's value.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Note
Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.

◆ JSObjectSetPropertyForKey()

void JSObjectSetPropertyForKey ( JSContextRef ctx,
JSObjectRef object,
JSValueRef propertyKey,
JSValueRef value,
JSPropertyAttributes attributes,
JSValueRef * exception )

Sets a property on an object using a JSValueRef as the property key.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property you want to set.
propertyKeyA JSValueRef containing the property key to use when looking up the property.
valueA JSValueRef to use as the property's value.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
exceptionA pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
Note
This function is the same as performing "object[propertyKey] = value" from JavaScript.

◆ JSObjectSetPrototype()

void JSObjectSetPrototype ( JSContextRef ctx,
JSObjectRef object,
JSValueRef value )

Sets an object's prototype.

Parameters
ctxThe execution context to use.
objectThe JSObject whose prototype you want to set.
valueA JSValue to set as the object's prototype.

◆ JSPromiseGetResult()

JSValueRef JSPromiseGetResult ( JSContextRef ctx,
JSObjectRef promise )

Gets the settled result of a JavaScript Promise: its value if fulfilled, or its rejection reason if rejected.

Parameters
ctxThe execution context to use.
promiseThe JSObject to inspect.
Returns
The promise's result, or NULL if promise is not a Promise. A pending promise yields the undefined value, which is indistinguishable from a promise fulfilled with undefined: consult JSPromiseGetStatus first.

◆ JSPromiseGetStatus()

bool JSPromiseGetStatus ( JSContextRef ctx,
JSObjectRef promise,
JSPromiseStatus * outStatus )

Gets the state of a JavaScript Promise without scheduling any reaction.

Parameters
ctxThe execution context to use.
promiseThe JSObject to inspect.
outStatusOn success, receives the promise's JSPromiseStatus.
Returns
true if promise is a Promise and outStatus was written; false if promise is not a Promise.

◆ JSPromiseMarkAsHandled()

bool JSPromiseMarkAsHandled ( JSContextRef ctx,
JSObjectRef promise )

Marks a JavaScript Promise as handled for unhandled-rejection reporting.

Parameters
ctxThe execution context to use.
promiseThe JSObject to mark.
Returns
true if promise is a Promise and was marked; false if promise is not a Promise.
Note
Use this when native code observes a promise's rejection through the inspection functions above instead of attaching a JavaScript reaction, so the page does not report an unhandled promise rejection for a rejection that native code in fact handles. Like attaching a catch handler, marking only suppresses reports made after it happens.

◆ JSPropertyNameAccumulatorAddName()

void JSPropertyNameAccumulatorAddName ( JSPropertyNameAccumulatorRef accumulator,
JSStringRef propertyName )

Adds a property name to a JavaScript property name accumulator.

Parameters
accumulatorThe accumulator object to which to add the property name.
propertyNameThe property name to add.

◆ JSPropertyNameArrayGetCount()

size_t JSPropertyNameArrayGetCount ( JSPropertyNameArrayRef array)

Gets a count of the number of items in a JavaScript property name array.

Parameters
arrayThe array from which to retrieve the count.
Returns
An integer count of the number of names in array.

◆ JSPropertyNameArrayGetNameAtIndex()

JSStringRef JSPropertyNameArrayGetNameAtIndex ( JSPropertyNameArrayRef array,
size_t index )

Gets a property name at a given index in a JavaScript property name array.

Parameters
arrayThe array from which to retrieve the property name.
indexThe index of the property name to retrieve.
Returns
A JSStringRef containing the property name.

◆ JSPropertyNameArrayRelease()

void JSPropertyNameArrayRelease ( JSPropertyNameArrayRef array)

Releases a JavaScript property name array.

Parameters
arrayThe JSPropetyNameArray to release.

◆ JSPropertyNameArrayRetain()

JSPropertyNameArrayRef JSPropertyNameArrayRetain ( JSPropertyNameArrayRef array)

Retains a JavaScript property name array.

Parameters
arrayThe JSPropertyNameArray to retain.
Returns
A JSPropertyNameArray that is the same as array.

Variable Documentation

◆ kJSClassDefinitionEmpty

const JSClassDefinition kJSClassDefinitionEmpty
extern

A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.

@const kJSClassDefinitionEmpty

Note

Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:

JSClassDefinition definition = kJSClassDefinitionEmpty; definition.finalize = Finalize;

Typedef Documentation

◆ JSClassAttributes

typedef unsigned JSClassAttributes

A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.

◆ JSFunctionDataFinalizeCallback

typedef void(*) JSFunctionDataFinalizeCallback(void *userData)

The callback invoked when a function created with JSObjectMakeFunctionWithData is garbage collected.

Parameters
userDataThe user data pointer the function was created with.
Note
Called exactly once, either when the function object is garbage collected or when its context group is destroyed. It runs with the context group's internal lock held: you must not call any function that may cause a garbage collection or an allocation of a garbage collected object from within a JSFunctionDataFinalizeCallback. This includes all functions that have a JSContextRef parameter.

◆ JSObjectCallAsConstructorCallback

typedef JSObjectRef(*) JSObjectCallAsConstructorCallback(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)

The callback invoked when an object is used as a constructor in a 'new' expression.

Parameters
ctxThe execution context to use.
constructorA JSObject that is the constructor being called.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of the arguments passed to the function.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
A JSObject that is the constructor's return value.
Note

If you named your function CallAsConstructor, you would declare it like this:

JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);

If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.

If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.

◆ JSObjectCallAsConstructorCallbackEx

typedef JSObjectRef(*) JSObjectCallAsConstructorCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)

◆ JSObjectCallAsFunctionCallback

typedef JSValueRef(*) JSObjectCallAsFunctionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)

The callback invoked when an object is called as a function.

Parameters
ctxThe execution context to use.
functionA JSObject that is the function being called.
thisObjectA JSObject that is the 'this' variable in the function's scope.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of the arguments passed to the function.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
A JSValue that is the function's return value.
Note

If you named your function CallAsFunction, you would declare it like this:

JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);

If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.

If this callback is NULL, calling your object as a function will throw an exception.

◆ JSObjectCallAsFunctionCallbackEx

typedef JSValueRef(*) JSObjectCallAsFunctionCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSStringRef className, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)

◆ JSObjectCallAsFunctionDataCallback

typedef JSValueRef(*) JSObjectCallAsFunctionDataCallback(JSContextRef ctx, void *userData, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)

The callback invoked when a function created with JSObjectMakeFunctionWithData is called.

Parameters
ctxThe execution context to use.
userDataThe user data pointer the function was created with.
functionA JSObject that is the function being called.
thisObjectA JSObject that is the 'this' variable in the function's scope.
argumentCountAn integer count of the number of arguments in arguments.
argumentsA JSValue array of the arguments passed to the function.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
A JSValue that is the function's return value.

◆ JSObjectConvertToTypeCallback

typedef JSValueRef(*) JSObjectConvertToTypeCallback(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef *exception)

The callback invoked when converting an object to a particular JavaScript type.

Parameters
ctxThe execution context to use.
objectThe JSObject to convert.
typeA JSType specifying the JavaScript type to convert to.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
The objects's converted value, or NULL if the object was not converted.
Note

If you named your function ConvertToType, you would declare it like this:

JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);

If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).

This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.

◆ JSObjectConvertToTypeCallbackEx

typedef JSValueRef(*) JSObjectConvertToTypeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSType type, JSValueRef *exception)

◆ JSObjectDeletePropertyCallback

typedef bool(*) JSObjectDeletePropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)

The callback invoked when deleting a property.

Parameters
ctxThe execution context to use.
objectThe JSObject in which to delete the property.
propertyNameA JSString containing the name of the property to delete.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
true if propertyName was successfully deleted, otherwise false.
Note

If you named your function DeleteProperty, you would declare it like this:

bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);

If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).

◆ JSObjectDeletePropertyCallbackEx

typedef bool(*) JSObjectDeletePropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)

◆ JSObjectFinalizeCallback

typedef void(*) JSObjectFinalizeCallback(JSObjectRef object)

The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.

Parameters
objectThe JSObject being finalized.
Note

If you named your function Finalize, you would declare it like this:

void Finalize(JSObjectRef object);

The finalize callback is called on the most derived class first, and the least derived class (the parent class) last.

You must not call any function that may cause a garbage collection or an allocation of a garbage collected object from within a JSObjectFinalizeCallback. This includes all functions that have a JSContextRef parameter.

◆ JSObjectFinalizeCallbackEx

typedef void(*) JSObjectFinalizeCallbackEx(JSClassRef jsClass, JSObjectRef object)

◆ JSObjectGetPropertyCallback

typedef JSValueRef(*) JSObjectGetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)

The callback invoked when getting a property's value.

Parameters
ctxThe execution context to use.
objectThe JSObject to search for the property.
propertyNameA JSString containing the name of the property to get.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
The property's value if object has the property, otherwise NULL.
Note

If you named your function GetProperty, you would declare it like this:

JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);

If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.

◆ JSObjectGetPropertyCallbackEx

typedef JSValueRef(*) JSObjectGetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)

◆ JSObjectGetPropertyNamesCallback

typedef void(*) JSObjectGetPropertyNamesCallback(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)

The callback invoked when collecting the names of an object's properties.

Parameters
ctxThe execution context to use.
objectThe JSObject whose property names are being collected.
propertyNamesA JavaScript property name accumulator in which to accumulate the names of object's properties.
Note

If you named your function GetPropertyNames, you would declare it like this:

void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);

Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.

Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.

◆ JSObjectGetPropertyNamesCallbackEx

typedef void(*) JSObjectGetPropertyNamesCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)

◆ JSObjectHasInstanceCallback

typedef bool(*) JSObjectHasInstanceCallback(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)

hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.

Parameters
ctxThe execution context to use.
constructorThe JSObject that is the target of the 'instanceof' expression.
possibleInstanceThe JSValue being tested to determine if it is an instance of constructor.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
true if possibleInstance is an instance of constructor, otherwise false.
Note

If you named your function HasInstance, you would declare it like this:

bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);

If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.

If this callback is NULL, 'instanceof' expressions that target your object will return false.

Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.

◆ JSObjectHasInstanceCallbackEx

typedef bool(*) JSObjectHasInstanceCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception)

◆ JSObjectHasPropertyCallback

typedef bool(*) JSObjectHasPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)

The callback invoked when determining whether an object has a property.

Parameters
ctxThe execution context to use.
objectThe JSObject to search for the property.
propertyNameA JSString containing the name of the property look up.
Returns
true if object has the property, otherwise false.
Note

If you named your function HasProperty, you would declare it like this:

bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);

If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.

This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive.

If this callback is NULL, the getProperty callback will be used to service hasProperty requests.

◆ JSObjectHasPropertyCallbackEx

typedef bool(*) JSObjectHasPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName)

◆ JSObjectInitializeCallback

typedef void(*) JSObjectInitializeCallback(JSContextRef ctx, JSObjectRef object)

The callback invoked when an object is first created.

Parameters
ctxThe execution context to use.
objectThe JSObject being created.
Note

If you named your function Initialize, you would declare it like this:

void Initialize(JSContextRef ctx, JSObjectRef object);

Unlike the other object callbacks, the initialize callback is called on the least derived class (the parent class) first, and the most derived class last.

◆ JSObjectInitializeCallbackEx

typedef void(*) JSObjectInitializeCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object)

◆ JSObjectSetPropertyCallback

typedef bool(*) JSObjectSetPropertyCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)

The callback invoked when setting a property's value.

Parameters
ctxThe execution context to use.
objectThe JSObject on which to set the property's value.
propertyNameA JSString containing the name of the property to set.
valueA JSValue to use as the property's value.
exceptionA pointer to a JSValueRef in which to return an exception, if any.
Returns
true if the property was set, otherwise false.
Note

If you named your function SetProperty, you would declare it like this:

bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);

If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).

◆ JSObjectSetPropertyCallbackEx

typedef bool(*) JSObjectSetPropertyCallbackEx(JSContextRef ctx, JSClassRef jsClass, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception)

◆ JSPropertyAttributes

typedef unsigned JSPropertyAttributes

A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kJSPropertyAttributeNone 
kJSPropertyAttributeReadOnly 
kJSPropertyAttributeDontEnum 
kJSPropertyAttributeDontDelete 

◆ anonymous enum

anonymous enum
Enumerator
kJSClassAttributeNone 
kJSClassAttributeNoAutomaticPrototype 

◆ JSPromiseStatus

The possible states of a JavaScript Promise.

  • kJSPromiseStatus_Pending The promise has not been settled yet.
  • kJSPromiseStatus_Fulfilled The promise has been resolved with a value.
  • kJSPromiseStatus_Rejected The promise has been rejected with a reason.
Enumerator
kJSPromiseStatus_Pending 
kJSPromiseStatus_Fulfilled 
kJSPromiseStatus_Rejected 

Go to the source code of this file.