Changeset 15468 in webkit for trunk/JavaScriptCore/API
- Timestamp:
- Jul 16, 2006, 2:06:28 PM (19 years ago)
- Location:
- trunk/JavaScriptCore/API
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/APICast.h
r15437 r15468 35 35 class JSValue; 36 36 class JSObject; 37 class ReferenceList;37 class PropertyNameArray; 38 38 } 39 39 … … 65 65 } 66 66 67 inline KJS:: ReferenceList* toJS(JSPropertyListRef l)67 inline KJS::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a) 68 68 { 69 return reinterpret_cast<KJS:: ReferenceList*>(l);69 return reinterpret_cast<KJS::PropertyNameArray*>(a); 70 70 } 71 71 … … 95 95 } 96 96 97 inline JSPropertyListRef toRef(KJS::ReferenceList* l)98 {99 return reinterpret_cast<JSPropertyListRef>(l);100 }101 102 97 inline JSContextRef toRef(KJS::ExecState* e) 103 98 { … … 105 100 } 106 101 102 inline JSPropertyNameAccumulatorRef toRef(KJS::PropertyNameArray* l) 103 { 104 return reinterpret_cast<JSPropertyNameAccumulatorRef>(l); 105 } 106 107 107 #endif // APICast_h -
trunk/JavaScriptCore/API/JSBase.h
r15437 r15468 44 44 typedef struct __JSClass* JSClassRef; 45 45 46 /*! @typedef JSProperty ListRef A JavaScript property list. Used for listing the properties in an object so they can be enumerated. */47 typedef struct __JSProperty List* JSPropertyListRef;46 /*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */ 47 typedef struct __JSPropertyNameArray* JSPropertyNameArrayRef; 48 48 49 /*! @typedef JSProperty EnumeratorRef A JavaScript property enumerator. Used for enumerating the properties in an object. */50 typedef struct __JSProperty Enumerator* JSPropertyEnumeratorRef;49 /*! @typedef JSPropertyNameAccumulatorRef A data type used to collect a JavaScript object's property names. */ 50 typedef struct __JSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; 51 51 52 52 -
trunk/JavaScriptCore/API/JSCallbackObject.cpp
r15462 r15468 31 31 #include "JSObjectRef.h" 32 32 #include "internal.h" 33 #include "reference.h" 34 #include "reference_list.h" 33 #include "PropertyNameArray.h" 35 34 36 35 namespace KJS { … … 291 290 } 292 291 293 void JSCallbackObject::getPropertyList(ReferenceList& propertyList, bool recursive) 294 { 295 JSObjectRef thisRef = toRef(this); 296 297 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 298 if (JSObjectAddPropertiesToListCallback addPropertiesToList = jsClass->addPropertiesToList) 299 addPropertiesToList(thisRef, toRef(&propertyList)); 292 void JSCallbackObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames) 293 { 294 JSContextRef execRef = toRef(exec); 295 JSObjectRef thisRef = toRef(this); 296 297 for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) { 298 if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) 299 getPropertyNames(execRef, thisRef, toRef(&propertyNames)); 300 300 301 301 if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) { … … 306 306 StaticValueEntry* entry = it->second; 307 307 if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum)) 308 property List.append(Reference(this, Identifier(name)));308 propertyNames.add(Identifier(name)); 309 309 } 310 310 } … … 317 317 StaticFunctionEntry* entry = it->second; 318 318 if (!(entry->attributes & kJSPropertyAttributeDontEnum)) 319 property List.append(Reference(this, Identifier(name)));320 } 321 } 322 } 323 324 JSObject::getProperty List(propertyList, recursive);319 propertyNames.add(Identifier(name)); 320 } 321 } 322 } 323 324 JSObject::getPropertyNames(exec, propertyNames); 325 325 } 326 326 -
trunk/JavaScriptCore/API/JSCallbackObject.h
r15443 r15468 61 61 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args); 62 62 63 virtual void getProperty List(ReferenceList& propertyList, bool recursive);63 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 64 64 65 65 virtual double toNumber(ExecState*) const; -
trunk/JavaScriptCore/API/JSClassRef.cpp
r15462 r15468 45 45 , setProperty(definition->setProperty) 46 46 , deleteProperty(definition->deleteProperty) 47 , addPropertiesToList(definition->addPropertiesToList)47 , getPropertyNames(definition->getPropertyNames) 48 48 , callAsFunction(definition->callAsFunction) 49 49 , callAsConstructor(definition->callAsConstructor) -
trunk/JavaScriptCore/API/JSClassRef.h
r15462 r15468 74 74 JSObjectSetPropertyCallback setProperty; 75 75 JSObjectDeletePropertyCallback deleteProperty; 76 JSObject AddPropertiesToListCallback addPropertiesToList;76 JSObjectGetPropertyNamesCallback getPropertyNames; 77 77 JSObjectCallAsFunctionCallback callAsFunction; 78 78 JSObjectCallAsConstructorCallback callAsConstructor; -
trunk/JavaScriptCore/API/JSObjectRef.cpp
r15465 r15468 38 38 #include "internal.h" 39 39 #include "object.h" 40 #include " reference_list.h"40 #include "PropertyNameArray.h" 41 41 42 42 using namespace KJS; … … 307 307 } 308 308 309 struct __JSProperty Enumerator310 { 311 __JSProperty Enumerator() : refCount(0), iterator(list.end())309 struct __JSPropertyNameArray 310 { 311 __JSPropertyNameArray() : refCount(0) 312 312 { 313 313 } 314 314 315 315 unsigned refCount; 316 ReferenceList list; 317 ReferenceListIterator iterator; 316 PropertyNameArray array; 318 317 }; 319 318 320 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSObjectRef object) 321 { 322 JSLock lock; 323 JSObject* jsObject = toJS(object); 324 325 JSPropertyEnumeratorRef enumerator = new __JSPropertyEnumerator(); 326 jsObject->getPropertyList(enumerator->list); 327 enumerator->iterator = enumerator->list.begin(); 328 329 return JSPropertyEnumeratorRetain(enumerator); 330 } 331 332 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator) 333 { 334 ReferenceListIterator& iterator = enumerator->iterator; 335 if (iterator != enumerator->list.end()) { 336 JSStringRef result = toRef(iterator->getPropertyName().ustring().rep()); 337 iterator++; 338 return result; 339 } 340 return 0; 341 } 342 343 JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator) 344 { 345 ++enumerator->refCount; 346 return enumerator; 347 } 348 349 void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator) 350 { 351 if (--enumerator->refCount == 0) 352 delete enumerator; 353 } 354 355 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName) 356 { 357 JSLock lock; 358 ReferenceList* jsPropertyList = toJS(propertyList); 359 JSObject* jsObject = toJS(thisObject); 319 JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object) 320 { 321 JSLock lock; 322 JSObject* jsObject = toJS(object); 323 ExecState* exec = toJS(context); 324 325 JSPropertyNameArrayRef propertyNames = new __JSPropertyNameArray(); 326 jsObject->getPropertyNames(exec, propertyNames->array); 327 328 return JSPropertyNameArrayRetain(propertyNames); 329 } 330 331 JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array) 332 { 333 ++array->refCount; 334 return array; 335 } 336 337 void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array) 338 { 339 if (--array->refCount == 0) 340 delete array; 341 } 342 343 size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array) 344 { 345 return array->array.size(); 346 } 347 348 JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index) 349 { 350 return toRef(array->array[index].ustring().rep()); 351 } 352 353 void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName) 354 { 355 JSLock lock; 356 PropertyNameArray* propertyNames = toJS(array); 360 357 UString::Rep* rep = toJS(propertyName); 361 358 362 jsPropertyList->append(Reference(jsObject, Identifier(rep)));363 } 359 propertyNames->add(Identifier(rep)); 360 } -
trunk/JavaScriptCore/API/JSObjectRef.h
r15464 r15468 155 155 156 156 /*! 157 @typedef JSObjectAddPropertiesToListCallback 158 @abstract The callback invoked when adding an object's properties to a property list. 159 @param object The JSObject whose properties need to be added to propertyList. 160 @param propertyList A JavaScript property list that will be used to enumerate object's properties. 161 @discussion If you named your function GetPropertyList, you would declare it like this: 162 163 void AddPropertiesToList(JSObjectRef object, JSPropertyListRef propertyList); 164 165 Use JSPropertyListAdd to add properties to propertyList. 166 167 Property lists are used by JSPropertyEnumerators and JavaScript for...in loops. 157 @typedef JSObjectGetPropertyNamesCallback 158 @abstract The callback invoked to get the names of an object's properties. 159 @param context The current execution context. 160 @param object The JSObject whose property names need to be appended to propertyNames. 161 @param accumulator A JavaScript property name accumulator, to which the object should add the names of its properties. 162 @discussion If you named your function GetPropertyNames, you would declare it like this: 163 164 void GetPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator); 165 166 Use JSPropertyNameAccumulatorAddName to add property names to accumulator. 167 168 Property lists are used by JSPropertyEnumerators and JavaScript for...in loops. 169 170 It's only necessary to add names of properties that you handle 171 specially in your own get / set callbacks. Static property names, 172 names of standard JS properties, and properties from the prototype 173 will be added automatically. 168 174 */ 169 175 typedef void 170 (*JSObject AddPropertiesToListCallback) (JSObjectRef object, JSPropertyListRef propertyList);176 (*JSObjectGetPropertyNamesCallback) (JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames); 171 177 172 178 /*! … … 327 333 JSObjectSetPropertyCallback setProperty; 328 334 JSObjectDeletePropertyCallback deleteProperty; 329 JSObject AddPropertiesToListCallback addPropertiesToList;335 JSObjectGetPropertyNamesCallback getPropertyNames; 330 336 JSObjectCallAsFunctionCallback callAsFunction; 331 337 JSObjectCallAsConstructorCallback callAsConstructor; … … 486 492 @param propertyIndex The property's name as a number 487 493 @param value A JSValue to use as the property's value. 488 @param attributes A logically ORed set of JSPropertyAttributes to give to the property.489 494 @discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays. 490 495 */ 491 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value , JSPropertyAttributes attributes);496 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value); 492 497 493 498 /*! … … 550 555 /*! 551 556 @function 552 @abstract Creates an enumerator for an object's properties. 553 @param object The object whose properties you want to enumerate. 554 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule. 555 */ 556 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSObjectRef object); 557 /*! 558 @function 559 @abstract Retains a property enumerator. 560 @param enumerator The JSPropertyEnumerator to retain. 561 @result A JSPropertyEnumerator that is the same as enumerator. 562 */ 563 JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator); 564 /*! 565 @function 566 @abstract Releases a property enumerator. 567 @param enumerator The JSPropertyEnumerator to release. 568 */ 569 void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator); 570 /*! 571 @function 572 @abstract Gets a property enumerator's next property. 573 @param enumerator The JSPropertyEnumerator whose next property you want to get. 574 @result A JSString containing the property's name, or NULL if all properties have been enumerated. 575 */ 576 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator); 577 578 /*! 579 @function 580 @abstract Adds a property to a property list. 581 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a property to an object's property list. 582 @param propertyList The JSPropertyList to which you want to add a property. 583 @param thisObject The JSObject to which the property belongs. 584 @param propertyName A JSString specifying the property's name. 585 */ 586 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName); 557 @abstract Get the names of all enumerable properties of an object. 558 @param context The execution context to use. 559 @param object The object from which to get property names. 560 @result A JSPropertyNameArray containing the names of all the object's enumerable properties. 561 */ 562 JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object); 563 564 /*! 565 @function 566 @abstract Retains a JavaScript property name array. 567 @param array The JSPropertyNameArray to retain. 568 @result A JSPropertyNameArray that is the same as array. 569 */ 570 JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array); 571 572 /*! 573 @function 574 @abstract Releases a JavaScript property name array. 575 @param array The JSPropetyNameArray to release. 576 */ 577 void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array); 578 579 /*! 580 @function 581 @abstract Get the number of items in a JavaScript property name array. 582 @param array The array from which to retrieve the count. 583 @result The count of items in the array. 584 */ 585 size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array); 586 587 /*! 588 @function 589 @abstract Get a single item from a JavaScript property name array. 590 @param array The array from which to retrieve a property name. 591 @param index The index of the property name to retrieve. 592 @result A JSStringRef containing the name of the property. 593 */ 594 JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index); 595 596 /*! 597 @function 598 @abstract Add a property name - useful while getting the property names for an object. 599 @param accumulator The accumulator object to which to add the property. 600 @param propertyName The new property to add. 601 */ 602 void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName); 587 603 588 604 #ifdef __cplusplus -
trunk/JavaScriptCore/API/testapi.c
r15465 r15468 170 170 } 171 171 172 static void MyObject_ addPropertiesToList(JSObjectRef object, JSPropertyListRef propertyList)172 static void MyObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames) 173 173 { 174 174 UNUSED_PARAM(context); … … 177 177 178 178 propertyName = JSStringCreateWithUTF8CString("alwaysOne"); 179 JSProperty ListAdd(propertyList, object, propertyName);179 JSPropertyNameAccumulatorAddName(propertyNames, propertyName); 180 180 JSStringRelease(propertyName); 181 181 182 182 propertyName = JSStringCreateWithUTF8CString("myPropertyName"); 183 JSProperty ListAdd(propertyList, object, propertyName);183 JSPropertyNameAccumulatorAddName(propertyNames, propertyName); 184 184 JSStringRelease(propertyName); 185 185 } … … 258 258 MyObject_setProperty, 259 259 MyObject_deleteProperty, 260 MyObject_ addPropertiesToList,260 MyObject_getPropertyNames, 261 261 MyObject_callAsFunction, 262 262 MyObject_callAsConstructor, … … 589 589 JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone, NULL); 590 590 JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(1), kJSPropertyAttributeDontEnum, NULL); 591 JSPropertyEnumeratorRef enumerator = JSObjectCreatePropertyEnumerator(o); 592 int count = 0; 593 while (JSPropertyEnumeratorGetNextName(enumerator)) 594 ++count; 595 JSPropertyEnumeratorRelease(enumerator); 591 JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o); 592 size_t expectedCount = JSPropertyNameArrayGetCount(nameArray); 593 size_t count; 594 for (count = 0; count < expectedCount; ++count) 595 JSPropertyNameArrayGetNameAtIndex(nameArray, count); 596 JSPropertyNameArrayRelease(nameArray); 596 597 assert(count == 1); // jsCFString should not be enumerated 597 598
Note:
See TracChangeset
for help on using the changeset viewer.