|
Mac Dev Center
Mac OS X Reference Library Networking, Internet, & Web JavaScriptCore Framework Reference
|
JSObjectRef.h |
| Includes: | <JavaScriptCore/JSBase.h> <JavaScriptCore/JSValueRef.h> <JavaScriptCore/WebKitAvailability.h> <stdbool.h> <stddef.h> |
Use the links in the table of contents to the left to access the documentation.
Creates a JavaScript class suitable for use with JSObjectMake.
Releases a JavaScript class.
Retains a JavaScript class.
Calls an object as a constructor.
Calls an object as a function.
Gets the names of an object's enumerable properties.
Deletes a property from an object.
Gets an object's private data.
Gets a property from an object.
Gets a property from an object by numeric index.
Gets an object's prototype.
Tests whether an object has a given property.
Tests whether an object can be called as a constructor.
Tests whether an object can be called as a function.
Creates a JavaScript object.
Creates a JavaScript Array object.
Convenience method for creating a JavaScript constructor.
Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
Creates a function with a given script as its body.
Convenience method for creating a JavaScript function with a given callback as its implementation.
Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
Sets a pointer to private data on an object.
Sets a property on an object.
Sets a property on an object by numeric index.
Sets an object's prototype.
Adds a property name to a JavaScript property name accumulator.
Gets a count of the number of items in a JavaScript property name array.
Gets a property name at a given index in a JavaScript property name array.
Releases a JavaScript property name array.
Retains a JavaScript property name array.
JSClassCreate |
Creates a JavaScript class suitable for use with JSObjectMake.
JS_EXPORT JSClassRef JSClassCreate( const JSClassDefinition* definition);
definitionA JSClassDefinition that defines the class.
A JSClass with the given definition. Ownership follows the Create Rule.
JSClassRelease |
Releases a JavaScript class.
JS_EXPORT void JSClassRelease( JSClassRef jsClass);
jsClassThe JSClass to release.
JSClassRetain |
Retains a JavaScript class.
JS_EXPORT JSClassRef JSClassRetain( JSClassRef jsClass);
jsClassThe JSClass to retain.
A JSClass that is the same as jsClass.
JSObjectCallAsConstructor |
Calls an object as a constructor.
JS_EXPORT JSObjectRef JSObjectCallAsConstructor( JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
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.
The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
JSObjectCallAsFunction |
Calls an object as a function.
JS_EXPORT JSValueRef JSObjectCallAsFunction( JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
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.
The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
JSObjectCopyPropertyNames |
Gets the names of an object's enumerable properties.
JS_EXPORT JSPropertyNameArrayRef JSObjectCopyPropertyNames( JSContextRef ctx, JSObjectRef object);
ctxThe execution context to use.
objectThe object whose property names you want to get.
A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
JSObjectDeleteProperty |
Deletes a property from an object.
JS_EXPORT bool JSObjectDeleteProperty( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
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.
true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
JSObjectGetPrivate |
Gets an object's private data.
JS_EXPORT void* JSObjectGetPrivate( JSObjectRef object);
objectA JSObject whose private data you want to get.
A void* that is the object's private data, if the object has private data, otherwise NULL.
JSObjectGetProperty |
Gets a property from an object.
JS_EXPORT JSValueRef JSObjectGetProperty( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
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.
The property's value if object has the property, otherwise the undefined value.
JSObjectGetPropertyAtIndex |
Gets a property from an object by numeric index.
JS_EXPORT JSValueRef JSObjectGetPropertyAtIndex( JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef *exception);
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.
The property's value if object has the property, otherwise the undefined value.
Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
JSObjectGetPrototype |
Gets an object's prototype.
JS_EXPORT JSValueRef JSObjectGetPrototype( JSContextRef ctx, JSObjectRef object);
ctxThe execution context to use.
objectA JSObject whose prototype you want to get.
A JSValue that is the object's prototype.
JSObjectHasProperty |
Tests whether an object has a given property.
JS_EXPORT bool JSObjectHasProperty( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
objectThe JSObject to test.
propertyNameA JSString containing the property's name.
true if the object has a property whose name matches propertyName, otherwise false.
JSObjectIsConstructor |
Tests whether an object can be called as a constructor.
JS_EXPORT bool JSObjectIsConstructor( JSContextRef ctx, JSObjectRef object);
ctxThe execution context to use.
objectThe JSObject to test.
true if the object can be called as a constructor, otherwise false.
JSObjectIsFunction |
Tests whether an object can be called as a function.
JS_EXPORT bool JSObjectIsFunction( JSContextRef ctx, JSObjectRef object);
ctxThe execution context to use.
objectThe JSObject to test.
true if the object can be called as a function, otherwise false.
JSObjectMake |
Creates a JavaScript object.
JS_EXPORT JSObjectRef JSObjectMake( JSContextRef ctx, JSClassRef jsClass, void *data);
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.
A JSObject with the given class and private data.
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 |
Creates a JavaScript Array object.
JS_EXPORT JSObjectRef JSObjectMakeArray( JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
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.
A JSObject that is an Array.
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 |
Convenience method for creating a JavaScript constructor.
JS_EXPORT JSObjectRef JSObjectMakeConstructor( JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);
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.
A JSObject that is a constructor. The object's prototype will be the default object prototype.
The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
JSObjectMakeDate |
Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
JS_EXPORT JSObjectRef JSObjectMakeDate( JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
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.
A JSObject that is a Date.
JSObjectMakeError |
Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
JS_EXPORT JSObjectRef JSObjectMakeError( JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
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.
A JSObject that is a Error.
JSObjectMakeFunction |
Creates a function with a given script as its body.
JS_EXPORT JSObjectRef JSObjectMakeFunction( JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
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.
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.
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.
Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
JSObjectMakeFunctionWithCallback |
Convenience method for creating a JavaScript function with a given callback as its implementation.
JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback( JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
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.
A JSObject that is a function. The object's prototype will be the default function prototype.
JSObjectMakeRegExp |
Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
JS_EXPORT JSObjectRef JSObjectMakeRegExp( JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
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.
A JSObject that is a RegExp.
JSObjectSetPrivate |
Sets a pointer to private data on an object.
JS_EXPORT bool JSObjectSetPrivate( JSObjectRef object, void *data);
objectThe JSObject whose private data you want to set.
dataA void* to set as the object's private data.
true if object can store private data, otherwise false.
The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
JSObjectSetProperty |
Sets a property on an object.
JS_EXPORT void JSObjectSetProperty( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef *exception);
ctxThe execution context to use.
objectThe JSObject whose property you want to set.
propertyNameA JSString containing the property's name.
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.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
JSObjectSetPropertyAtIndex |
Sets a property on an object by numeric index.
JS_EXPORT void JSObjectSetPropertyAtIndex( JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef *exception);
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.
Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
JSObjectSetPrototype |
Sets an object's prototype.
JS_EXPORT void JSObjectSetPrototype( JSContextRef ctx, JSObjectRef object, JSValueRef value);
ctxThe execution context to use.
objectThe JSObject whose prototype you want to set.
valueA JSValue to set as the object's prototype.
JSPropertyNameAccumulatorAddName |
Adds a property name to a JavaScript property name accumulator.
JS_EXPORT void JSPropertyNameAccumulatorAddName( JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
accumulatorThe accumulator object to which to add the property name.
propertyNameThe property name to add.
JSPropertyNameArrayGetCount |
Gets a count of the number of items in a JavaScript property name array.
JS_EXPORT size_t JSPropertyNameArrayGetCount( JSPropertyNameArrayRef array);
arrayThe array from which to retrieve the count.
An integer count of the number of names in array.
JSPropertyNameArrayGetNameAtIndex |
Gets a property name at a given index in a JavaScript property name array.
JS_EXPORT JSStringRef JSPropertyNameArrayGetNameAtIndex( JSPropertyNameArrayRef array, size_t index);
arrayThe array from which to retrieve the property name.
indexThe index of the property name to retrieve.
A JSStringRef containing the property name.
JSPropertyNameArrayRelease |
Releases a JavaScript property name array.
JS_EXPORT void JSPropertyNameArrayRelease( JSPropertyNameArrayRef array);
arrayThe JSPropetyNameArray to release.
JSPropertyNameArrayRetain |
Retains a JavaScript property name array.
JS_EXPORT JSPropertyNameArrayRef JSPropertyNameArrayRetain( JSPropertyNameArrayRef array);
arrayThe JSPropertyNameArray to retain.
A JSPropertyNameArray that is the same as array.
A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
kJSClassDefinitionEmpty |
A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
JS_EXPORT extern const JSClassDefinition kJSClassDefinitionEmpty;
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;
A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
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.
The callback invoked when an object is used as a constructor in a 'new' expression.
The callback invoked when an object is called as a function.
The callback invoked when converting an object to a particular JavaScript type.
The callback invoked when deleting a property.
The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
The callback invoked when getting a property's value.
The callback invoked when collecting the names of an object's properties.
hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
The callback invoked when determining whether an object has a property.
The callback invoked when an object is first created.
The callback invoked when setting a property's value.
A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
This structure describes a statically declared function property.
This structure describes a statically declared value property.
JSClassAttributes |
A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
typedef unsigned JSClassAttributes;
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.
typedef struct { int version; /* current (and only) version is 0 */ JSClassAttributes attributes; const char* className; JSClassRef parentClass; const JSStaticValue* staticValues; const JSStaticFunction* staticFunctions; JSObjectInitializeCallback initialize; JSObjectFinalizeCallback finalize; JSObjectHasPropertyCallback hasProperty; JSObjectGetPropertyCallback getProperty; JSObjectSetPropertyCallback setProperty; JSObjectDeletePropertyCallback deleteProperty; JSObjectGetPropertyNamesCallback getPropertyNames; JSObjectCallAsFunctionCallback callAsFunction; JSObjectCallAsConstructorCallback callAsConstructor; JSObjectHasInstanceCallback hasInstance; JSObjectConvertToTypeCallback convertToType; } JSClassDefinition;
versionThe version number of this structure. The current version is 0.
attributesA logically ORed set of JSClassAttributes to give to the class.
classNameA null-terminated UTF8 string containing the class's name.
parentClassA JSClass to set as the class's parent class. Pass NULL use the default object class.
staticValuesA JSStaticValue array containing the class's statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
staticFunctionsA JSStaticFunction array containing the class's statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
initializeThe callback invoked when an object is first created. Use this callback to initialize the object.
finalizeThe callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup.
hasPropertyThe callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value is expensive.
getPropertyThe callback invoked when getting a property's value.
setPropertyThe callback invoked when setting a property's value.
deletePropertyThe callback invoked when deleting a property.
getPropertyNamesThe callback invoked when collecting the names of an object's properties.
callAsFunctionThe callback invoked when an object is called as a function.
hasInstanceThe callback invoked when an object is used as the target of an 'instanceof' expression.
callAsConstructorThe callback invoked when an object is used as a constructor in a 'new' expression.
convertToTypeThe callback invoked when converting an object to a particular JavaScript type.
The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.
If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
JSStaticValue StaticValueArray[] = { { "X", GetX, SetX, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } };
Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.
A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
JSObjectCallAsConstructorCallback |
The callback invoked when an object is used as a constructor in a 'new' expression.
typedef JSObjectRef ( *JSObjectCallAsConstructorCallback) ( JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
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.
A JSObject that is the constructor's return value.
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.
JSObjectCallAsFunctionCallback |
The callback invoked when an object is called as a function.
typedef JSValueRef ( *JSObjectCallAsFunctionCallback) ( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
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.
A JSValue that is the function's return value.
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.
JSObjectConvertToTypeCallback |
The callback invoked when converting an object to a particular JavaScript type.
typedef JSValueRef ( *JSObjectConvertToTypeCallback) ( JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef *exception);
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.
The objects's converted value, or NULL if the object was not converted.
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.
JSObjectDeletePropertyCallback |
The callback invoked when deleting a property.
typedef bool ( *JSObjectDeletePropertyCallback) ( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
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.
true if propertyName was successfully deleted, otherwise false.
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).
JSObjectFinalizeCallback |
The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
typedef void ( *JSObjectFinalizeCallback) ( JSObjectRef object);
objectThe JSObject being finalized.
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.
JSObjectGetPropertyCallback |
The callback invoked when getting a property's value.
typedef JSValueRef ( *JSObjectGetPropertyCallback) ( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception);
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.
The property's value if object has the property, otherwise NULL.
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.
JSObjectGetPropertyNamesCallback |
The callback invoked when collecting the names of an object's properties.
typedef void ( *JSObjectGetPropertyNamesCallback) ( JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
ctxThe execution context to use.
objectThe JSObject whose property names are being collected.
accumulatorA JavaScript property name accumulator in which to accumulate the names of object's properties.
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.
JSObjectHasInstanceCallback |
hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
typedef bool ( *JSObjectHasInstanceCallback) ( JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef *exception);
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.
true if possibleInstance is an instance of constructor, otherwise false.
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.
JSObjectHasPropertyCallback |
The callback invoked when determining whether an object has a property.
typedef bool ( *JSObjectHasPropertyCallback) ( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
ctxThe execution context to use.
objectThe JSObject to search for the property.
propertyNameA JSString containing the name of the property look up.
true if object has the property, otherwise false.
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.
JSObjectInitializeCallback |
The callback invoked when an object is first created.
typedef void ( *JSObjectInitializeCallback) ( JSContextRef ctx, JSObjectRef object);
ctxThe execution context to use.
objectThe JSObject being created.
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.
JSObjectSetPropertyCallback |
The callback invoked when setting a property's value.
typedef bool ( *JSObjectSetPropertyCallback) ( JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef *exception);
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.
true if the property was set, otherwise false.
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).
JSPropertyAttributes |
A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
typedef unsigned JSPropertyAttributes;
JSStaticFunction |
This structure describes a statically declared function property.
typedef struct { const char* const name; JSObjectCallAsFunctionCallback callAsFunction; JSPropertyAttributes attributes; } JSStaticFunction;
nameA null-terminated UTF8 string containing the property's name.
callAsFunctionA JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
JSStaticValue |
This structure describes a statically declared value property.
typedef struct { const char* const name; JSObjectGetPropertyCallback getProperty; JSObjectSetPropertyCallback setProperty; JSPropertyAttributes attributes; } JSStaticValue;
nameA null-terminated UTF8 string containing the property's name.
getPropertyA JSObjectGetPropertyCallback to invoke when getting the property's value.
setPropertyA JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
attributesA logically ORed set of JSPropertyAttributes to give to the property.
JSClassAttribute |
enum { kJSClassAttributeNone = 0, kJSClassAttributeNoAutomaticPrototype = 1 << 1 };
kJSClassAttributeNoneSpecifies that a class has no special attributes.
kJSClassAttributeNoAutomaticPrototypeSpecifies that a class should not automatically generate a shared prototype for its instance objects. Use kJSClassAttributeNoAutomaticPrototype in combination with JSObjectSetPrototype to manage prototypes manually.
JSPropertyAttribute |
enum { kJSPropertyAttributeNone = 0, kJSPropertyAttributeReadOnly = 1 << 1, kJSPropertyAttributeDontEnum = 1 << 2, kJSPropertyAttributeDontDelete = 1 << 3 };
kJSPropertyAttributeNoneSpecifies that a property has no special attributes.
kJSPropertyAttributeReadOnlySpecifies that a property is read-only.
kJSPropertyAttributeDontEnumSpecifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
kJSPropertyAttributeDontDeleteSpecifies that the delete operation should fail on a property.
Last Updated: 2009-08-12