Changeset 15376 in webkit for trunk/JavaScriptCore/API/JSObjectRef.h
- Timestamp:
- Jul 12, 2006, 1:12:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSObjectRef.h
r15328 r15376 31 31 #include <JavaScriptCore/JSValueRef.h> 32 32 33 #include <stdbool.h> 34 #include <stddef.h> // for size_t 35 33 36 #ifdef __cplusplus 34 37 extern "C" { … … 56 59 57 60 /*! 58 @typedef JS InitializeCallback61 @typedef JSObjectInitializeCallback 59 62 @abstract The callback invoked when an object is first created. 60 63 @param context The execution context to use. … … 66 69 */ 67 70 typedef void 68 (*JS InitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception);69 70 /*! 71 @typedef JS FinalizeCallback71 (*JSObjectInitializeCallback) (JSContextRef context, JSObjectRef object, JSValueRef* exception); 72 73 /*! 74 @typedef JSObjectFinalizeCallback 72 75 @abstract The callback invoked when an object is finalized (prepared for garbage collection). 73 76 @param object The JSObject being finalized. … … 77 80 */ 78 81 typedef void 79 (*JS FinalizeCallback) (JSObjectRef object);80 81 /*! 82 @typedef JS HasPropertyCallback82 (*JSObjectFinalizeCallback) (JSObjectRef object); 83 84 /*! 85 @typedef JSObjectHasPropertyCallback 83 86 @abstract The callback invoked when determining whether an object has a given property. 84 87 @param context The current execution context. 85 88 @param object The JSObject to search for the property. 86 @param propertyName A JS InternalString containing the name of the property look up.89 @param propertyName A JSString containing the name of the property look up. 87 90 @param exception A pointer to a JSValueRef in which to return an exception, if any. 88 91 @result true if object has the property, otherwise false. 89 92 @discussion If you named your function HasProperty, you would declare it like this: 90 93 91 bool HasProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception); 92 93 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 calls. 94 bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 95 96 If this function returns false, the hasProperty request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain. 97 98 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. 94 99 */ 95 100 typedef bool 96 (*JS HasPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);97 98 /*! 99 @typedef JS GetPropertyCallback101 (*JSObjectHasPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 102 103 /*! 104 @typedef JSObjectGetPropertyCallback 100 105 @abstract The callback invoked when getting a property from an object. 101 106 @param context The current execution context. 102 107 @param object The JSObject to search for the property. 103 @param propertyName A JSInternalString containing the name of the property to get. 104 @param returnValue A pointer to a JSValue in which to store the property's value. 105 @param exception A pointer to a JSValueRef in which to return an exception, if any. 106 @result true if object has the property in question, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 108 @param propertyName A JSString containing the name of the property to get. 109 @param exception A pointer to a JSValueRef in which to return an exception, if any. 110 @result The property's value if object has the property, otherwise NULL. 107 111 @discussion If you named your function GetProperty, you would declare it like this: 108 112 109 bool GetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception); 110 111 If this function returns false, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain. 113 JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 114 115 If this function returns NULL, the get request forwards to object's static property table, then its parent class chain (which includes the default object class), then its prototype chain. 116 */ 117 typedef JSValueRef 118 (*JSObjectGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 119 120 /*! 121 @typedef JSObjectSetPropertyCallback 122 @abstract The callback invoked when setting the value of a given property. 123 @param context The current execution context. 124 @param object The JSObject on which to set the property's value. 125 @param propertyName A JSString containing the name of the property to set. 126 @param value A JSValue to use as the property's value. 127 @param exception A pointer to a JSValueRef in which to return an exception, if any. 128 @result true if the property was set, otherwise false. 129 @discussion If you named your function SetProperty, you would declare it like this: 130 131 bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); 132 133 If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class). 112 134 */ 113 135 typedef bool 114 (*JSGetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* returnValue, JSValueRef* exception); 115 116 /*! 117 @typedef JSSetPropertyCallback 118 @abstract The callback invoked when setting the value of a given property. 119 @param context The current execution context. 120 @param object The JSObject on which to set the property's value. 121 @param propertyName A JSInternalString containing the name of the property to set. 122 @param value A JSValue to use as the property's value. 123 @param exception A pointer to a JSValueRef in which to return an exception, if any. 124 @result true if the property was successfully set, otherwise false. 125 @discussion If you named your function SetProperty, you would declare it like this: 126 127 bool SetProperty(JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception); 128 129 If this function returns false, the set request forwards to object's static property table, then its parent class chain (which includes the default object class). 130 */ 131 typedef bool 132 (*JSSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef value, JSValueRef* exception); 133 134 /*! 135 @typedef JSDeletePropertyCallback 136 (*JSObjectSetPropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); 137 138 /*! 139 @typedef JSObjectDeletePropertyCallback 136 140 @abstract The callback invoked when deleting a given property. 137 141 @param context The current execution context. 138 142 @param object The JSObject in which to delete the property. 139 @param propertyName A JS InternalString containing the name of the property to delete.143 @param propertyName A JSString containing the name of the property to delete. 140 144 @param exception A pointer to a JSValueRef in which to return an exception, if any. 141 145 @result true if propertyName was successfully deleted, otherwise false. 142 146 @discussion If you named your function DeleteProperty, you would declare it like this: 143 147 144 bool DeleteProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef* exception);148 bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 145 149 146 150 If this function returns false, the delete request forwards to object's static property table, then its parent class chain (which includes the default object class). 147 151 */ 148 152 typedef bool 149 (*JS DeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSInternalStringRef propertyName, JSValueRef* exception);150 151 /*! 152 @typedef JS GetPropertyListCallback153 (*JSObjectDeletePropertyCallback) (JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 154 155 /*! 156 @typedef JSObjectAddPropertiesToListCallback 153 157 @abstract The callback invoked when adding an object's properties to a property list. 154 158 @param context The current execution context. … … 158 162 @discussion If you named your function GetPropertyList, you would declare it like this: 159 163 160 void GetPropertyList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);164 void AddPropertiesToList(JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception); 161 165 162 166 Use JSPropertyListAdd to add properties to propertyList. … … 165 169 */ 166 170 typedef void 167 (*JS GetPropertyListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception);168 169 /*! 170 @typedef JS CallAsFunctionCallback171 (*JSObjectAddPropertiesToListCallback) (JSContextRef context, JSObjectRef object, JSPropertyListRef propertyList, JSValueRef* exception); 172 173 /*! 174 @typedef JSObjectCallAsFunctionCallback 171 175 @abstract The callback invoked when an object is called as a function. 172 176 @param context The current execution context. … … 186 190 */ 187 191 typedef JSValueRef 188 (*JS CallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception);189 190 /*! 191 @typedef JS CallAsConstructorCallback192 (*JSObjectCallAsFunctionCallback) (JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, JSValueRef argv[], JSValueRef* exception); 193 194 /*! 195 @typedef JSObjectCallAsConstructorCallback 192 196 @abstract The callback invoked when an object is used as a constructor in a 'new' statement. 193 197 @param context The current execution context. … … 206 210 */ 207 211 typedef JSObjectRef 208 (*JS CallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception);209 210 /*! 211 @typedef JS ConvertToTypeCallback212 (*JSObjectCallAsConstructorCallback) (JSContextRef context, JSObjectRef constructor, size_t argc, JSValueRef argv[], JSValueRef* exception); 213 214 /*! 215 @typedef JSObjectConvertToTypeCallback 212 216 @abstract The callback invoked when converting an object to a particular JavaScript type. 213 217 @param context The current execution context. 214 218 @param object The JSObject to convert. 215 @param typeCode A JSTypeCode specifying the JavaScript type to convert to. 216 @param returnValue A pointer to a JSValue in which to store the converted value. 217 @param exception A pointer to a JSValueRef in which to return an exception, if any. 218 @result true if the value was converted, otherwise false. If this function returns true, returnValue is assumed to contain a valid JSValue. 219 @param type A JSType specifying the JavaScript type to convert to. 220 @param exception A pointer to a JSValueRef in which to return an exception, if any. 221 @result The objects's converted value, or NULL if the object was not converted. 219 222 @discussion If you named your function ConvertToType, you would declare it like this: 220 223 221 bool ConvertToType(JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);224 JSValueRef ConvertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception); 222 225 223 226 If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class). 224 227 */ 225 typedef bool226 (*JS ConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSTypeCode typeCode, JSValueRef* returnValue, JSValueRef* exception);228 typedef JSValueRef 229 (*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception); 227 230 228 231 /*! … … 242 245 */ 243 246 typedef struct { 244 int version; // current (and only) version is 0245 JS InitializeCallbackinitialize;246 JS FinalizeCallbackfinalize;247 JS HasPropertyCallbackhasProperty;248 JS GetPropertyCallbackgetProperty;249 JS SetPropertyCallbacksetProperty;250 JS DeletePropertyCallbackdeleteProperty;251 JS GetPropertyListCallback getPropertyList;252 JS CallAsFunctionCallbackcallAsFunction;253 JS CallAsConstructorCallbackcallAsConstructor;254 JS ConvertToTypeCallbackconvertToType;247 int version; // current (and only) version is 0 248 JSObjectInitializeCallback initialize; 249 JSObjectFinalizeCallback finalize; 250 JSObjectHasPropertyCallback hasProperty; 251 JSObjectGetPropertyCallback getProperty; 252 JSObjectSetPropertyCallback setProperty; 253 JSObjectDeletePropertyCallback deleteProperty; 254 JSObjectAddPropertiesToListCallback addPropertiesToList; 255 JSObjectCallAsFunctionCallback callAsFunction; 256 JSObjectCallAsConstructorCallback callAsConstructor; 257 JSObjectConvertToTypeCallback convertToType; 255 258 } JSObjectCallbacks; 256 259 … … 270 273 @abstract This structure describes a static value property. 271 274 @field name A null-terminated UTF8 string containing the property's name. 272 @field getProperty A JS GetPropertyCallback to invoke when getting the property's value.273 @field setProperty A JS SetPropertyCallback to invoke when setting the property's value.275 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value. 276 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. 274 277 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 275 278 */ 276 279 typedef struct { 277 280 const char* const name; // FIXME: convert UTF8 278 JS GetPropertyCallback getProperty;279 JS SetPropertyCallback setProperty;281 JSObjectGetPropertyCallback getProperty; 282 JSObjectSetPropertyCallback setProperty; 280 283 JSPropertyAttributes attributes; 281 284 } JSStaticValue; … … 285 288 @abstract This structure describes a static function property. 286 289 @field name A null-terminated UTF8 string containing the property's name. 287 @field callAsFunction A JS CallAsFunctionCallback to invoke when the property is called as a function.290 @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function. 288 291 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 289 292 */ 290 293 typedef struct { 291 294 const char* const name; // FIXME: convert UTF8 292 JS CallAsFunctionCallback callAsFunction;295 JSObjectCallAsFunctionCallback callAsFunction; 293 296 JSPropertyAttributes attributes; 294 297 } JSStaticFunction; … … 296 299 /*! 297 300 @function 298 @abstract Creates a JavaScript class suitable for use with JSObjectMake . Ownership follows the create rule.301 @abstract Creates a JavaScript class suitable for use with JSObjectMake 299 302 @param staticValues A JSStaticValue array representing the class's static value properties. Pass NULL to specify no static value properties. The array must be terminated by a JSStaticValue whose name field is NULL. 300 303 @param staticFunctions A JSStaticFunction array representing the class's static function properties. Pass NULL to specify no static function properties. The array must be terminated by a JSStaticFunction whose name field is NULL. 301 304 @param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior. 302 305 @param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class. 306 @result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule. 303 307 @discussion The simplest and most efficient way to add custom properties to a class is by specifying static values and functions. Standard JavaScript practice calls for functions to be placed in prototype objects, so that they can be shared among objects. 304 308 */ … … 332 336 @abstract Convenience method for creating a JavaScript function with a given callback as its implementation. 333 337 @param context The execution context to use. 334 @param callAsFunction The JS CallAsFunctionCallback to invoke when the function is called.338 @param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called. 335 339 @result A JSObject that is an anonymous function. The object's prototype will be the default function prototype. 336 340 */ 337 JSObjectRef JS FunctionMake(JSContextRef context, JSCallAsFunctionCallback callAsFunction);341 JSObjectRef JSObjectMakeFunction(JSContextRef context, JSObjectCallAsFunctionCallback callAsFunction); 338 342 /*! 339 343 @function 340 344 @abstract Convenience method for creating a JavaScript constructor with a given callback as its implementation. 341 345 @param context The execution context to use. 342 @param callAsConstructor The JS CallAsConstructorCallback to invoke when the constructor is used in a 'new' statement.346 @param callAsConstructor The JSObjectCallAsConstructorCallback to invoke when the constructor is used in a 'new' statement. 343 347 @result A JSObject that is a constructor. The object's prototype will be the default object prototype. 344 348 */ 345 JSObjectRef JS ConstructorMake(JSContextRef context, JSCallAsConstructorCallback callAsConstructor);349 JSObjectRef JSObjectMakeConstructor(JSContextRef context, JSObjectCallAsConstructorCallback callAsConstructor); 346 350 347 351 /*! … … 349 353 @abstract Creates a function with a given script as its body. 350 354 @param context The execution context to use. 351 @param body A JS InternalString containing the script to use as the function's body.352 @param sourceURL A JS InternalString 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.355 @param body A JSString containing the script to use as the function's body. 356 @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. 353 357 @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. 354 358 @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. … … 356 360 @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution. 357 361 */ 358 JSObjectRef JS FunctionMakeWithBody(JSContextRef context, JSInternalStringRef body, JSInternalStringRef sourceURL, int startingLineNumber, JSValueRef* exception);362 JSObjectRef JSObjectMakeFunctionWithBody(JSContextRef context, JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 359 363 360 364 /*! … … 363 367 @param context The execution context to use. 364 368 @param object The object whose description you want to get. 365 @result A JS InternalString containing the object's description. This is usually the object's class name.366 */ 367 JS InternalStringRef JSObjectGetDescription(JSObjectRef object);369 @result A JSString containing the object's description. This is usually the object's class name. 370 */ 371 JSStringRef JSObjectGetDescription(JSObjectRef object); 368 372 369 373 /*! … … 386 390 @abstract Tests whether an object has a certain property. 387 391 @param object The JSObject to test. 388 @param propertyName A JS InternalString containing the property's name.392 @param propertyName A JSString containing the property's name. 389 393 @result true if the object has a property whose name matches propertyName, otherwise false. 390 394 */ 391 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);395 bool JSObjectHasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 392 396 /*! 393 397 @function … … 395 399 @param context The execution context to use. 396 400 @param object The JSObject whose property you want to get. 397 @param propertyName A JS InternalString containing the property's name.398 @result The property's value , or NULL if the object does not have a property whose name matches propertyName.399 */ 400 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);401 @param propertyName A JSString containing the property's name. 402 @result The property's value if object has the property, otherwise NULL. 403 */ 404 JSValueRef JSObjectGetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 401 405 /*! 402 406 @function … … 404 408 @param context The execution context to use. 405 409 @param object The JSObject whose property you want to set. 406 @param propertyName A JS InternalString containing the property's name.410 @param propertyName A JSString containing the property's name. 407 411 @param value A JSValue to use as the property's value. 408 412 @param attributes A logically ORed set of JSPropertyAttributes to give to the property. 409 413 @result true if the set operation succeeds, otherwise false (for example, if the object already has a property of the given name with the kJSPropertyAttributeReadOnly attribute set). 410 414 */ 411 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes);415 bool JSObjectSetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes); 412 416 /*! 413 417 @function … … 415 419 @param context The execution context to use. 416 420 @param object The JSObject whose property you want to delete. 417 @param propertyName A JS InternalString containing the property's name.421 @param propertyName A JSString containing the property's name. 418 422 @result true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set). 419 423 */ 420 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JS InternalStringRef propertyName);424 bool JSObjectDeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 421 425 422 426 /*! … … 424 428 @abstract Gets a pointer to private data from an object. 425 429 @param object A JSObject whose private data you want to get. 426 @result A void* that points to the object's private data, or NULL if the object has no private data.427 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JS FunctionMake, and JSConstructorMake.430 @result A void* that points to the object's private data, if the object has private data, otherwise NULL. 431 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 428 432 */ 429 433 void* JSObjectGetPrivate(JSObjectRef object); … … 434 438 @param data A void* that points to the object's private data. 435 439 @result true if the set operation succeeds, otherwise false. 436 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JS FunctionMake, and JSConstructorMake.440 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on custom objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 437 441 */ 438 442 bool JSObjectSetPrivate(JSObjectRef object, void* data); … … 481 485 @param context The execution context to use. 482 486 @param object The object whose properties you want to enumerate. 483 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the create rule.487 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule. 484 488 */ 485 489 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSContextRef context, JSObjectRef object); … … 501 505 @abstract Gets a property enumerator's next property. 502 506 @param enumerator The JSPropertyEnumerator whose next property you want to get. 503 @result A JS InternalString containing the property's name, or NULL if all properties have been enumerated.504 */ 505 JS InternalStringRef JSPropertyEnumeratorGetNext(JSPropertyEnumeratorRef enumerator);507 @result A JSString containing the property's name, or NULL if all properties have been enumerated. 508 */ 509 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator); 506 510 507 511 /*! 508 512 @function 509 513 @abstract Adds a property to a property list. 510 @discussion Use this method inside a JS GetPropertyListCallback to add a custom property to an object's property list.514 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a custom property to an object's property list. 511 515 @param propertyList The JSPropertyList to which you want to add a property. 512 516 @param thisObject The JSObject to which the property belongs. 513 @param propertyName A JS InternalString specifying the property's name.514 */ 515 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JS InternalStringRef propertyName);517 @param propertyName A JSString specifying the property's name. 518 */ 519 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName); 516 520 517 521 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.