Home | History | Annotate | Download | only in API
      1 /*
      2  * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
      3  * Copyright (C) 2008 Kelvin W Sherlock (ksherlock (at) gmail.com)
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #ifndef JSObjectRef_h
     28 #define JSObjectRef_h
     29 
     30 #include <JavaScriptCore/JSBase.h>
     31 #include <JavaScriptCore/JSValueRef.h>
     32 #include <JavaScriptCore/WebKitAvailability.h>
     33 
     34 #ifndef __cplusplus
     35 #include <stdbool.h>
     36 #endif
     37 #include <stddef.h> /* for size_t */
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif
     42 
     43 /*!
     44 @enum JSPropertyAttribute
     45 @constant kJSPropertyAttributeNone         Specifies that a property has no special attributes.
     46 @constant kJSPropertyAttributeReadOnly     Specifies that a property is read-only.
     47 @constant kJSPropertyAttributeDontEnum     Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
     48 @constant kJSPropertyAttributeDontDelete   Specifies that the delete operation should fail on a property.
     49 */
     50 enum {
     51     kJSPropertyAttributeNone         = 0,
     52     kJSPropertyAttributeReadOnly     = 1 << 1,
     53     kJSPropertyAttributeDontEnum     = 1 << 2,
     54     kJSPropertyAttributeDontDelete   = 1 << 3
     55 };
     56 
     57 /*!
     58 @typedef JSPropertyAttributes
     59 @abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
     60 */
     61 typedef unsigned JSPropertyAttributes;
     62 
     63 /*!
     64 @enum JSClassAttribute
     65 @constant kJSClassAttributeNone Specifies that a class has no special attributes.
     66 @constant kJSClassAttributeNoAutomaticPrototype Specifies that a class should not automatically generate a shared prototype for its instance objects. Use kJSClassAttributeNoAutomaticPrototype in combination with JSObjectSetPrototype to manage prototypes manually.
     67 */
     68 enum {
     69     kJSClassAttributeNone = 0,
     70     kJSClassAttributeNoAutomaticPrototype = 1 << 1
     71 };
     72 
     73 /*!
     74 @typedef JSClassAttributes
     75 @abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
     76 */
     77 typedef unsigned JSClassAttributes;
     78 
     79 /*!
     80 @typedef JSObjectInitializeCallback
     81 @abstract The callback invoked when an object is first created.
     82 @param ctx The execution context to use.
     83 @param object The JSObject being created.
     84 @discussion If you named your function Initialize, you would declare it like this:
     85 
     86 void Initialize(JSContextRef ctx, JSObjectRef object);
     87 
     88 Unlike the other object callbacks, the initialize callback is called on the least
     89 derived class (the parent class) first, and the most derived class last.
     90 */
     91 typedef void
     92 (*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object);
     93 
     94 /*!
     95 @typedef JSObjectFinalizeCallback
     96 @abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
     97 @param object The JSObject being finalized.
     98 @discussion If you named your function Finalize, you would declare it like this:
     99 
    100 void Finalize(JSObjectRef object);
    101 
    102 The finalize callback is called on the most derived class first, and the least
    103 derived class (the parent class) last.
    104 
    105 You must not call any function that may cause a garbage collection or an allocation
    106 of a garbage collected object from within a JSObjectFinalizeCallback. This includes
    107 all functions that have a JSContextRef parameter.
    108 */
    109 typedef void
    110 (*JSObjectFinalizeCallback) (JSObjectRef object);
    111 
    112 /*!
    113 @typedef JSObjectHasPropertyCallback
    114 @abstract The callback invoked when determining whether an object has a property.
    115 @param ctx The execution context to use.
    116 @param object The JSObject to search for the property.
    117 @param propertyName A JSString containing the name of the property look up.
    118 @result true if object has the property, otherwise false.
    119 @discussion If you named your function HasProperty, you would declare it like this:
    120 
    121 bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
    122 
    123 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.
    124 
    125 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.
    126 
    127 If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
    128 */
    129 typedef bool
    130 (*JSObjectHasPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
    131 
    132 /*!
    133 @typedef JSObjectGetPropertyCallback
    134 @abstract The callback invoked when getting a property's value.
    135 @param ctx The execution context to use.
    136 @param object The JSObject to search for the property.
    137 @param propertyName A JSString containing the name of the property to get.
    138 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    139 @result The property's value if object has the property, otherwise NULL.
    140 @discussion If you named your function GetProperty, you would declare it like this:
    141 
    142 JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    143 
    144 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.
    145 */
    146 typedef JSValueRef
    147 (*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    148 
    149 /*!
    150 @typedef JSObjectSetPropertyCallback
    151 @abstract The callback invoked when setting a property's value.
    152 @param ctx The execution context to use.
    153 @param object The JSObject on which to set the property's value.
    154 @param propertyName A JSString containing the name of the property to set.
    155 @param value A JSValue to use as the property's value.
    156 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    157 @result true if the property was set, otherwise false.
    158 @discussion If you named your function SetProperty, you would declare it like this:
    159 
    160 bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
    161 
    162 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).
    163 */
    164 typedef bool
    165 (*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
    166 
    167 /*!
    168 @typedef JSObjectDeletePropertyCallback
    169 @abstract The callback invoked when deleting a property.
    170 @param ctx The execution context to use.
    171 @param object The JSObject in which to delete the property.
    172 @param propertyName A JSString containing the name of the property to delete.
    173 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    174 @result true if propertyName was successfully deleted, otherwise false.
    175 @discussion If you named your function DeleteProperty, you would declare it like this:
    176 
    177 bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    178 
    179 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).
    180 */
    181 typedef bool
    182 (*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    183 
    184 /*!
    185 @typedef JSObjectGetPropertyNamesCallback
    186 @abstract The callback invoked when collecting the names of an object's properties.
    187 @param ctx The execution context to use.
    188 @param object The JSObject whose property names are being collected.
    189 @param accumulator A JavaScript property name accumulator in which to accumulate the names of object's properties.
    190 @discussion If you named your function GetPropertyNames, you would declare it like this:
    191 
    192 void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
    193 
    194 Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
    195 
    196 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.
    197 */
    198 typedef void
    199 (*JSObjectGetPropertyNamesCallback) (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
    200 
    201 /*!
    202 @typedef JSObjectCallAsFunctionCallback
    203 @abstract The callback invoked when an object is called as a function.
    204 @param ctx The execution context to use.
    205 @param function A JSObject that is the function being called.
    206 @param thisObject A JSObject that is the 'this' variable in the function's scope.
    207 @param argumentCount An integer count of the number of arguments in arguments.
    208 @param arguments A JSValue array of the  arguments passed to the function.
    209 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    210 @result A JSValue that is the function's return value.
    211 @discussion If you named your function CallAsFunction, you would declare it like this:
    212 
    213 JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    214 
    215 If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
    216 
    217 If this callback is NULL, calling your object as a function will throw an exception.
    218 */
    219 typedef JSValueRef
    220 (*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    221 
    222 /*!
    223 @typedef JSObjectCallAsConstructorCallback
    224 @abstract The callback invoked when an object is used as a constructor in a 'new' expression.
    225 @param ctx The execution context to use.
    226 @param constructor A JSObject that is the constructor being called.
    227 @param argumentCount An integer count of the number of arguments in arguments.
    228 @param arguments A JSValue array of the  arguments passed to the function.
    229 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    230 @result A JSObject that is the constructor's return value.
    231 @discussion If you named your function CallAsConstructor, you would declare it like this:
    232 
    233 JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    234 
    235 If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
    236 
    237 If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
    238 */
    239 typedef JSObjectRef
    240 (*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    241 
    242 /*!
    243 @typedef JSObjectHasInstanceCallback
    244 @abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
    245 @param ctx The execution context to use.
    246 @param constructor The JSObject that is the target of the 'instanceof' expression.
    247 @param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
    248 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    249 @result true if possibleInstance is an instance of constructor, otherwise false.
    250 @discussion If you named your function HasInstance, you would declare it like this:
    251 
    252 bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
    253 
    254 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.
    255 
    256 If this callback is NULL, 'instanceof' expressions that target your object will return false.
    257 
    258 Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
    259 */
    260 typedef bool
    261 (*JSObjectHasInstanceCallback)  (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
    262 
    263 /*!
    264 @typedef JSObjectConvertToTypeCallback
    265 @abstract The callback invoked when converting an object to a particular JavaScript type.
    266 @param ctx The execution context to use.
    267 @param object The JSObject to convert.
    268 @param type A JSType specifying the JavaScript type to convert to.
    269 @param exception A pointer to a JSValueRef in which to return an exception, if any.
    270 @result The objects's converted value, or NULL if the object was not converted.
    271 @discussion If you named your function ConvertToType, you would declare it like this:
    272 
    273 JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
    274 
    275 If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
    276 
    277 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.
    278 */
    279 typedef JSValueRef
    280 (*JSObjectConvertToTypeCallback) (JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
    281 
    282 /*!
    283 @struct JSStaticValue
    284 @abstract This structure describes a statically declared value property.
    285 @field name A null-terminated UTF8 string containing the property's name.
    286 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
    287 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
    288 @field attributes A logically ORed set of JSPropertyAttributes to give to the property.
    289 */
    290 typedef struct {
    291     const char* const name;
    292     JSObjectGetPropertyCallback getProperty;
    293     JSObjectSetPropertyCallback setProperty;
    294     JSPropertyAttributes attributes;
    295 } JSStaticValue;
    296 
    297 /*!
    298 @struct JSStaticFunction
    299 @abstract This structure describes a statically declared function property.
    300 @field name A null-terminated UTF8 string containing the property's name.
    301 @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
    302 @field attributes A logically ORed set of JSPropertyAttributes to give to the property.
    303 */
    304 typedef struct {
    305     const char* const name;
    306     JSObjectCallAsFunctionCallback callAsFunction;
    307     JSPropertyAttributes attributes;
    308 } JSStaticFunction;
    309 
    310 /*!
    311 @struct JSClassDefinition
    312 @abstract 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.
    313 @field version The version number of this structure. The current version is 0.
    314 @field attributes A logically ORed set of JSClassAttributes to give to the class.
    315 @field className A null-terminated UTF8 string containing the class's name.
    316 @field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
    317 @field staticValues A 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.
    318 @field staticFunctions A 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.
    319 @field initialize The callback invoked when an object is first created. Use this callback to initialize the object.
    320 @field finalize The 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.
    321 @field hasProperty The 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.
    322 @field getProperty The callback invoked when getting a property's value.
    323 @field setProperty The callback invoked when setting a property's value.
    324 @field deleteProperty The callback invoked when deleting a property.
    325 @field getPropertyNames The callback invoked when collecting the names of an object's properties.
    326 @field callAsFunction The callback invoked when an object is called as a function.
    327 @field hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
    328 @field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
    329 @field convertToType The callback invoked when converting an object to a particular JavaScript type.
    330 @discussion 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.
    331 
    332 If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
    333 
    334 JSStaticValue StaticValueArray[] = {
    335     { "X", GetX, SetX, kJSPropertyAttributeNone },
    336     { 0, 0, 0, 0 }
    337 };
    338 
    339 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.
    340 
    341 A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
    342 */
    343 typedef struct {
    344     int                                 version; /* current (and only) version is 0 */
    345     JSClassAttributes                   attributes;
    346 
    347     const char*                         className;
    348     JSClassRef                          parentClass;
    349 
    350     const JSStaticValue*                staticValues;
    351     const JSStaticFunction*             staticFunctions;
    352 
    353     JSObjectInitializeCallback          initialize;
    354     JSObjectFinalizeCallback            finalize;
    355     JSObjectHasPropertyCallback         hasProperty;
    356     JSObjectGetPropertyCallback         getProperty;
    357     JSObjectSetPropertyCallback         setProperty;
    358     JSObjectDeletePropertyCallback      deleteProperty;
    359     JSObjectGetPropertyNamesCallback    getPropertyNames;
    360     JSObjectCallAsFunctionCallback      callAsFunction;
    361     JSObjectCallAsConstructorCallback   callAsConstructor;
    362     JSObjectHasInstanceCallback         hasInstance;
    363     JSObjectConvertToTypeCallback       convertToType;
    364 } JSClassDefinition;
    365 
    366 /*!
    367 @const kJSClassDefinitionEmpty
    368 @abstract A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
    369 @discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
    370 
    371 JSClassDefinition definition = kJSClassDefinitionEmpty;
    372 definition.finalize = Finalize;
    373 */
    374 JS_EXPORT extern const JSClassDefinition kJSClassDefinitionEmpty;
    375 
    376 /*!
    377 @function
    378 @abstract Creates a JavaScript class suitable for use with JSObjectMake.
    379 @param definition A JSClassDefinition that defines the class.
    380 @result A JSClass with the given definition. Ownership follows the Create Rule.
    381 */
    382 JS_EXPORT JSClassRef JSClassCreate(const JSClassDefinition* definition);
    383 
    384 /*!
    385 @function
    386 @abstract Retains a JavaScript class.
    387 @param jsClass The JSClass to retain.
    388 @result A JSClass that is the same as jsClass.
    389 */
    390 JS_EXPORT JSClassRef JSClassRetain(JSClassRef jsClass);
    391 
    392 /*!
    393 @function
    394 @abstract Releases a JavaScript class.
    395 @param jsClass The JSClass to release.
    396 */
    397 JS_EXPORT void JSClassRelease(JSClassRef jsClass);
    398 
    399 /*!
    400 @function
    401 @abstract Creates a JavaScript object.
    402 @param ctx The execution context to use.
    403 @param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
    404 @param data A void* to set as the object's private data. Pass NULL to specify no private data.
    405 @result A JSObject with the given class and private data.
    406 @discussion The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
    407 
    408 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.
    409 */
    410 JS_EXPORT JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);
    411 
    412 /*!
    413 @function
    414 @abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
    415 @param ctx The execution context to use.
    416 @param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
    417 @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
    418 @result A JSObject that is a function. The object's prototype will be the default function prototype.
    419 */
    420 JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
    421 
    422 /*!
    423 @function
    424 @abstract Convenience method for creating a JavaScript constructor.
    425 @param ctx The execution context to use.
    426 @param jsClass A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.
    427 @param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
    428 @result A JSObject that is a constructor. The object's prototype will be the default object prototype.
    429 @discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
    430 */
    431 JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);
    432 
    433 /*!
    434  @function
    435  @abstract Creates a JavaScript Array object.
    436  @param ctx The execution context to use.
    437  @param argumentCount An integer count of the number of arguments in arguments.
    438  @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
    439  @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    440  @result A JSObject that is an Array.
    441  @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
    442  is supplied, this function returns an array with one element.
    443  */
    444 JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
    445 
    446 /*!
    447  @function
    448  @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
    449  @param ctx The execution context to use.
    450  @param argumentCount An integer count of the number of arguments in arguments.
    451  @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
    452  @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    453  @result A JSObject that is a Date.
    454  */
    455 JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
    456 
    457 /*!
    458  @function
    459  @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
    460  @param ctx The execution context to use.
    461  @param argumentCount An integer count of the number of arguments in arguments.
    462  @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
    463  @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    464  @result A JSObject that is a Error.
    465  */
    466 JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
    467 
    468 /*!
    469  @function
    470  @abstract Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
    471  @param ctx The execution context to use.
    472  @param argumentCount An integer count of the number of arguments in arguments.
    473  @param arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
    474  @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    475  @result A JSObject that is a RegExp.
    476  */
    477 JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_IN_WEBKIT_VERSION_4_0;
    478 
    479 /*!
    480 @function
    481 @abstract Creates a function with a given script as its body.
    482 @param ctx The execution context to use.
    483 @param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
    484 @param parameterCount An integer count of the number of parameter names in parameterNames.
    485 @param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
    486 @param body A JSString containing the script to use as the function's body.
    487 @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
    488 @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
    489 @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
    490 @result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
    491 @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
    492 */
    493 JS_EXPORT JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
    494 
    495 /*!
    496 @function
    497 @abstract Gets an object's prototype.
    498 @param ctx  The execution context to use.
    499 @param object A JSObject whose prototype you want to get.
    500 @result A JSValue that is the object's prototype.
    501 */
    502 JS_EXPORT JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object);
    503 
    504 /*!
    505 @function
    506 @abstract Sets an object's prototype.
    507 @param ctx  The execution context to use.
    508 @param object The JSObject whose prototype you want to set.
    509 @param value A JSValue to set as the object's prototype.
    510 */
    511 JS_EXPORT void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value);
    512 
    513 /*!
    514 @function
    515 @abstract Tests whether an object has a given property.
    516 @param object The JSObject to test.
    517 @param propertyName A JSString containing the property's name.
    518 @result true if the object has a property whose name matches propertyName, otherwise false.
    519 */
    520 JS_EXPORT bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
    521 
    522 /*!
    523 @function
    524 @abstract Gets a property from an object.
    525 @param ctx The execution context to use.
    526 @param object The JSObject whose property you want to get.
    527 @param propertyName A JSString containing the property's name.
    528 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    529 @result The property's value if object has the property, otherwise the undefined value.
    530 */
    531 JS_EXPORT JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    532 
    533 /*!
    534 @function
    535 @abstract Sets a property on an object.
    536 @param ctx The execution context to use.
    537 @param object The JSObject whose property you want to set.
    538 @param propertyName A JSString containing the property's name.
    539 @param value A JSValue to use as the property's value.
    540 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    541 @param attributes A logically ORed set of JSPropertyAttributes to give to the property.
    542 */
    543 JS_EXPORT void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
    544 
    545 /*!
    546 @function
    547 @abstract Deletes a property from an object.
    548 @param ctx The execution context to use.
    549 @param object The JSObject whose property you want to delete.
    550 @param propertyName A JSString containing the property's name.
    551 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    552 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
    553 */
    554 JS_EXPORT bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
    555 
    556 /*!
    557 @function
    558 @abstract Gets a property from an object by numeric index.
    559 @param ctx The execution context to use.
    560 @param object The JSObject whose property you want to get.
    561 @param propertyIndex An integer value that is the property's name.
    562 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    563 @result The property's value if object has the property, otherwise the undefined value.
    564 @discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
    565 */
    566 JS_EXPORT JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
    567 
    568 /*!
    569 @function
    570 @abstract Sets a property on an object by numeric index.
    571 @param ctx The execution context to use.
    572 @param object The JSObject whose property you want to set.
    573 @param propertyIndex The property's name as a number.
    574 @param value A JSValue to use as the property's value.
    575 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    576 @discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
    577 */
    578 JS_EXPORT void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
    579 
    580 /*!
    581 @function
    582 @abstract Gets an object's private data.
    583 @param object A JSObject whose private data you want to get.
    584 @result A void* that is the object's private data, if the object has private data, otherwise NULL.
    585 */
    586 JS_EXPORT void* JSObjectGetPrivate(JSObjectRef object);
    587 
    588 /*!
    589 @function
    590 @abstract Sets a pointer to private data on an object.
    591 @param object The JSObject whose private data you want to set.
    592 @param data A void* to set as the object's private data.
    593 @result true if object can store private data, otherwise false.
    594 @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
    595 */
    596 JS_EXPORT bool JSObjectSetPrivate(JSObjectRef object, void* data);
    597 
    598 /*!
    599 @function
    600 @abstract Tests whether an object can be called as a function.
    601 @param ctx  The execution context to use.
    602 @param object The JSObject to test.
    603 @result true if the object can be called as a function, otherwise false.
    604 */
    605 JS_EXPORT bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object);
    606 
    607 /*!
    608 @function
    609 @abstract Calls an object as a function.
    610 @param ctx The execution context to use.
    611 @param object The JSObject to call as a function.
    612 @param thisObject The object to use as "this," or NULL to use the global object as "this."
    613 @param argumentCount An integer count of the number of arguments in arguments.
    614 @param arguments A JSValue array of arguments to pass to the function. Pass NULL if argumentCount is 0.
    615 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    616 @result The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
    617 */
    618 JS_EXPORT JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    619 
    620 /*!
    621 @function
    622 @abstract Tests whether an object can be called as a constructor.
    623 @param ctx  The execution context to use.
    624 @param object The JSObject to test.
    625 @result true if the object can be called as a constructor, otherwise false.
    626 */
    627 JS_EXPORT bool JSObjectIsConstructor(JSContextRef ctx, JSObjectRef object);
    628 
    629 /*!
    630 @function
    631 @abstract Calls an object as a constructor.
    632 @param ctx The execution context to use.
    633 @param object The JSObject to call as a constructor.
    634 @param argumentCount An integer count of the number of arguments in arguments.
    635 @param arguments A JSValue array of arguments to pass to the constructor. Pass NULL if argumentCount is 0.
    636 @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
    637 @result The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
    638 */
    639 JS_EXPORT JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
    640 
    641 /*!
    642 @function
    643 @abstract Gets the names of an object's enumerable properties.
    644 @param ctx The execution context to use.
    645 @param object The object whose property names you want to get.
    646 @result A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
    647 */
    648 JS_EXPORT JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object);
    649 
    650 /*!
    651 @function
    652 @abstract Retains a JavaScript property name array.
    653 @param array The JSPropertyNameArray to retain.
    654 @result A JSPropertyNameArray that is the same as array.
    655 */
    656 JS_EXPORT JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array);
    657 
    658 /*!
    659 @function
    660 @abstract Releases a JavaScript property name array.
    661 @param array The JSPropetyNameArray to release.
    662 */
    663 JS_EXPORT void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array);
    664 
    665 /*!
    666 @function
    667 @abstract Gets a count of the number of items in a JavaScript property name array.
    668 @param array The array from which to retrieve the count.
    669 @result An integer count of the number of names in array.
    670 */
    671 JS_EXPORT size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array);
    672 
    673 /*!
    674 @function
    675 @abstract Gets a property name at a given index in a JavaScript property name array.
    676 @param array The array from which to retrieve the property name.
    677 @param index The index of the property name to retrieve.
    678 @result A JSStringRef containing the property name.
    679 */
    680 JS_EXPORT JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index);
    681 
    682 /*!
    683 @function
    684 @abstract Adds a property name to a JavaScript property name accumulator.
    685 @param accumulator The accumulator object to which to add the property name.
    686 @param propertyName The property name to add.
    687 */
    688 JS_EXPORT void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
    689 
    690 #ifdef __cplusplus
    691 }
    692 #endif
    693 
    694 #endif /* JSObjectRef_h */
    695