Changeset 15462 in webkit for trunk/JavaScriptCore/API/JSObjectRef.h
- Timestamp:
- Jul 15, 2006, 6:28:25 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSObjectRef.h
r15444 r15462 84 84 /*! 85 85 @typedef JSObjectHasPropertyCallback 86 @abstract The callback invoked when determining whether an object has a givenproperty.86 @abstract The callback invoked when determining whether an object has a property. 87 87 @param context The current execution context. 88 88 @param object The JSObject to search for the property. … … 93 93 bool HasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName); 94 94 95 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.95 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. 96 96 97 97 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. … … 104 104 /*! 105 105 @typedef JSObjectGetPropertyCallback 106 @abstract The callback invoked when getting a property from an object.106 @abstract The callback invoked when getting a property's value. 107 107 @param context The current execution context. 108 108 @param object The JSObject to search for the property. … … 114 114 JSValueRef GetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 115 115 116 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 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. 117 117 */ 118 118 typedef JSValueRef … … 121 121 /*! 122 122 @typedef JSObjectSetPropertyCallback 123 @abstract The callback invoked when setting the value of a given property.123 @abstract The callback invoked when setting a property's value. 124 124 @param context The current execution context. 125 125 @param object The JSObject on which to set the property's value. … … 132 132 bool SetProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); 133 133 134 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).134 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). 135 135 */ 136 136 typedef bool … … 139 139 /*! 140 140 @typedef JSObjectDeletePropertyCallback 141 @abstract The callback invoked when deleting a givenproperty.141 @abstract The callback invoked when deleting a property. 142 142 @param context The current execution context. 143 143 @param object The JSObject in which to delete the property. … … 149 149 bool DeleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 150 150 151 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).151 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). 152 152 */ 153 153 typedef bool … … 252 252 (*JSObjectConvertToTypeCallback) (JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception); 253 253 254 /*! 255 @struct JSObjectCallbacks 256 @abstract This structure contains optional callbacks for supplementing default object behavior. Any callback field can be NULL. 254 /*! 255 @struct JSStaticValue 256 @abstract This structure describes a statically declared value property. 257 @field name A null-terminated UTF8 string containing the property's name. 258 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value. 259 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. 260 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 261 */ 262 typedef struct { 263 const char* const name; // FIXME: convert UTF8 264 JSObjectGetPropertyCallback getProperty; 265 JSObjectSetPropertyCallback setProperty; 266 JSPropertyAttributes attributes; 267 } JSStaticValue; 268 269 /*! 270 @struct JSStaticFunction 271 @abstract This structure describes a statically declared function property. 272 @field name A null-terminated UTF8 string containing the property's name. 273 @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function. 274 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 275 */ 276 typedef struct { 277 const char* const name; // FIXME: convert UTF8 278 JSObjectCallAsFunctionCallback callAsFunction; 279 JSPropertyAttributes attributes; 280 } JSStaticFunction; 281 282 /*! 283 @struct JSClassDefinition 284 @abstract This structure contains properties and callbacks that define a type of object. All fields are optional. Any field may be NULL. 257 285 @field version The version number of this structure. The current version is 0. 258 @field initialize The callback invoked when an object is first created. Use this callback in conjunction with JSObjectSetPrivate to initialize private data in your object. 259 @field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for your object, and perform other cleanup. 260 @field hasProperty The callback invoked when determining whether an object has a given property. If this field is NULL, getProperty will be 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 would be expensive. 261 @field getProperty The callback invoked when getting the value of a given property. 262 @field setProperty The callback invoked when setting the value of a given property. 263 @field deleteProperty The callback invoked when deleting a given property. 286 @field className A null-terminated UTF8 string containing the class's name. 287 @field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class. 288 @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. 289 @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. 290 @field initialize The callback invoked when an object is first created. Use this callback to initialize the object. 291 @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. 292 @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. 293 @field getProperty The callback invoked when getting a property's value. 294 @field setProperty The callback invoked when setting a property's value. 295 @field deleteProperty The callback invoked when deleting a property. 264 296 @field addPropertiesToList The callback invoked when adding an object's properties to a property list. 265 297 @field callAsFunction The callback invoked when an object is called as a function. … … 267 299 @field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression. 268 300 @field convertToType The callback invoked when converting an object to a particular JavaScript type. 301 @discussion The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like get, set, and enumerate. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time. 302 303 If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this: 304 305 JSStaticValue StaticValueArray[] = { 306 { "X", GetX, SetX, kJSPropertyAttributeNone }, 307 { 0, 0, 0, 0 } 308 }; 309 310 Standard JavaScript practice calls for storing functions in prototype objects, so derived objects can share them. Therefore, it is common for prototype classes to have function properties but no value properties, and for object classes to have value properties but no function properties. 311 312 A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute. 269 313 */ 270 314 typedef struct { 271 315 int version; // current (and only) version is 0 316 317 const char* className; 318 JSClassRef parentClass; 319 320 JSStaticValue* staticValues; 321 JSStaticFunction* staticFunctions; 322 272 323 JSObjectInitializeCallback initialize; 273 324 JSObjectFinalizeCallback finalize; … … 281 332 JSObjectHasInstanceCallback hasInstance; 282 333 JSObjectConvertToTypeCallback convertToType; 283 } JSObjectCallbacks; 284 285 /*! 286 @const kJSObjectCallbacksNone 287 @abstract A JSObjectCallbacks structure of the current version, filled with NULL callbacks. 288 @discussion Use this constant as a convenience when creating callback structures. For example, to create a callback structure that has only a finalize method: 289 290 JSObjectCallbacks callbacks = kJSObjectCallbacksNone; 291 292 callbacks.finalize = Finalize; 293 */ 294 extern const JSObjectCallbacks kJSObjectCallbacksNone; 295 296 /*! 297 @struct JSStaticValue 298 @abstract This structure describes a static value property. 299 @field name A null-terminated UTF8 string containing the property's name. 300 @field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value. 301 @field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. 302 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 303 */ 304 typedef struct { 305 const char* const name; // FIXME: convert UTF8 306 JSObjectGetPropertyCallback getProperty; 307 JSObjectSetPropertyCallback setProperty; 308 JSPropertyAttributes attributes; 309 } JSStaticValue; 310 311 /*! 312 @struct JSStaticFunction 313 @abstract This structure describes a static function property. 314 @field name A null-terminated UTF8 string containing the property's name. 315 @field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function. 316 @field attributes A logically ORed set of JSPropertyAttributes to give to the property. 317 */ 318 typedef struct { 319 const char* const name; // FIXME: convert UTF8 320 JSObjectCallAsFunctionCallback callAsFunction; 321 JSPropertyAttributes attributes; 322 } JSStaticFunction; 323 324 /*! 325 @function 326 @abstract Creates a JavaScript class suitable for use with JSObjectMake 327 @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. 328 @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. 329 @param callbacks A pointer to a JSObjectCallbacks structure holding custom callbacks for supplementing default object behavior. Pass NULL to specify no custom behavior. 330 @param parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class. 331 @result A JSClass with the given properties, callbacks, and parent class. Ownership follows the Create Rule. 332 @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. 333 */ 334 JSClassRef JSClassCreate(JSStaticValue* staticValues, JSStaticFunction* staticFunctions, const JSObjectCallbacks* callbacks, JSClassRef parentClass); 334 } JSClassDefinition; 335 336 /*! 337 @const kJSClassDefinitionNull 338 @abstract A JSClassDefinition structure of the current version, filled with NULL pointers. 339 @discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method: 340 341 JSClassDefinition definition = kJSClassDefinitionNull; 342 343 definition.finalize = Finalize; 344 */ 345 extern const JSClassDefinition kJSClassDefinitionNull; 346 347 /*! 348 @function 349 @abstract Creates a JavaScript class suitable for use with JSObjectMake. 350 @param definition A JSClassDefinition that defines the class. 351 @result A JSClass with the given definition's name, properties, callbacks, and parent class. Ownership follows the Create Rule. 352 */ 353 JSClassRef JSClassCreate(JSClassDefinition* definition); 354 335 355 /*! 336 356 @function … … 404 424 /*! 405 425 @function 406 @abstract Tests whether an object has a certain property.426 @abstract Tests whether an object has a given property. 407 427 @param object The JSObject to test. 408 428 @param propertyName A JSString containing the property's name. … … 473 493 @param object A JSObject whose private data you want to get. 474 494 @result A void* that points to the object's private data, if the object has private data, otherwise NULL. 475 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on customobjects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.495 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 476 496 */ 477 497 void* JSObjectGetPrivate(JSObjectRef object); … … 483 503 @param data A void* that points to the object's private data. 484 504 @result true if the set operation succeeds, otherwise false. 485 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on customobjects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor.505 @discussion JSObjectGetPrivate and JSObjectSetPrivate only work on objects created by JSObjectMake, JSObjectMakeFunction, and JSObjectMakeConstructor. 486 506 */ 487 507 bool JSObjectSetPrivate(JSObjectRef object, void* data); … … 556 576 @function 557 577 @abstract Adds a property to a property list. 558 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a customproperty to an object's property list.578 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a property to an object's property list. 559 579 @param propertyList The JSPropertyList to which you want to add a property. 560 580 @param thisObject The JSObject to which the property belongs.
Note:
See TracChangeset
for help on using the changeset viewer.