Changeset 15468 in webkit


Ignore:
Timestamp:
Jul 16, 2006 2:06:28 PM (18 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Darin.


  • switch property lists to be vector+set of Identifiers instead of list of References


This has the following benefits:


  • no duplicates in property lists
  • simplifies API calls
  • probably more efficient, since linked list is gone
  • entirely removed Reference, ReferenceList and ProtectedReference types from the API
  • kjs/PropertyNameArray.cpp: Added. (KJS::PropertyNameArray::add): Check set, if not already there, add to vector.
  • kjs/PropertyNameArray.h: Added. (KJS::PropertyNameArray::PropertyNameArray): Newly added type, combines a set and a vector to make a unique but ordered list of identifiers. (KJS::PropertyNameArray::begin): ditto (KJS::PropertyNameArray::end): ditto (KJS::PropertyNameArray::size): ditto (KJS::PropertyNameArray::operator[]): ditto
  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstance::getPropertyNames): renamed from getPropertyList, updated for PropertyNameArray (ArrayInstance::setLength): updated for PropertyNameArray (ArrayInstance::pushUndefinedObjectsToEnd): ditto
  • kjs/nodes.cpp: (ForInNode::execute): updated for PropertyNameArray
  • kjs/nodes.h:
  • kjs/object.cpp: (KJS::JSObject::getPropertyNames): renamed from getPropertyList, updated for PropertyNameArray
  • kjs/object.h:
  • kjs/property_map.cpp: (KJS::PropertyMap::getEnumerablePropertyNames): updated for PropertyNameArray (KJS::PropertyMap::getSparseArrayPropertyNames): ditto
  • kjs/property_map.h:
  • kjs/protected_reference.h: Removed.
  • kjs/reference.cpp: Removed.
  • kjs/reference.h: Removed.
  • kjs/reference_list.cpp: Removed.
  • kjs/reference_list.h: Removed.
  • kjs/scope_chain.cpp: (KJS::ScopeChain::print): Use PropertyNamesArray instead of ReferenceList.
  • kjs/string_object.cpp: (StringInstance::getPropertyNames): Updated for new approach.
  • kjs/string_object.h:
  • kjs/ustring.h:
  • API/APICast.h: (toJS): Added overload for PropertyNameAccumulatorRef / PropertyNameArray* (toRef): ditto
  • API/JSBase.h:
  • API/JSCallbackObject.cpp: (KJS::JSCallbackObject::getPropertyNames): Fixed for new API.
  • API/JSCallbackObject.h:
  • API/JSObjectRef.cpp: (JSPropertyNameArray::JSPropertyNameArray): Type used for a publicly vended JSPropertyNameArrayRef. (JSObjectCopyPropertyNames): New API call - renamed / refactored from JSObjectCreatePropertyList (JSPropertyNameArrayRetain): new retain call for JSPropertyNameArray. (JSPropertyNameArrayRelease): new release call for - " -. (JSPropertyNameArrayGetCount): Instead of having to use a stateful enumerator you can now get the count and items in any order. (JSPropertyNameArrayGetNameAtIndex): See above. (JSPropertyNameAccumulatorAddName): What you add properties to is now an opaque accumulator object.
  • API/JSObjectRef.h: Prototyped new functions, removed old ones
  • JavaScriptCore.exp: Updated exported symbols.
  • JavaScriptCore.xcodeproj/project.pbxproj: Added new files, removed old.
  • API/testapi.c: (MyObject_getPropertyNames): Renamed / fixed callback to fit new paradigm. (main): Updated for new API.

JavaScriptGlue:

Reviewed by Darin.

  • switch property lists to be vector+set of Identifiers instead of list of References


  • JSUtils.cpp: (KJSValueToCFTypeInternal): updated for JSC SPI changes
  • JSValueWrapper.cpp: (JSValueWrapper::JSObjectCopyPropertyNames): ditto
  • UserObjectImp.cpp: (UserObjectImp::getPropertyNames): ditto
  • UserObjectImp.h:

LayoutTests:

Reviewed by Darin.


  • new test case and updated results for property list changes
  • fast/js/for-in-avoid-duplicates-expected.txt: Added.
  • fast/js/for-in-avoid-duplicates.html: Added.
  • fast/js/kde/Array-expected.txt:
  • fast/js/resources/for-in-avoid-duplicates.js: Added.
Location:
trunk
Files:
5 added
5 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/APICast.h

    r15437 r15468  
    3535    class JSValue;
    3636    class JSObject;
    37     class ReferenceList;
     37    class PropertyNameArray;
    3838}
    3939
     
    6565}
    6666
    67 inline KJS::ReferenceList* toJS(JSPropertyListRef l)
     67inline KJS::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
    6868{
    69     return reinterpret_cast<KJS::ReferenceList*>(l);
     69    return reinterpret_cast<KJS::PropertyNameArray*>(a);
    7070}
    7171
     
    9595}
    9696
    97 inline JSPropertyListRef toRef(KJS::ReferenceList* l)
    98 {
    99     return reinterpret_cast<JSPropertyListRef>(l);
    100 }
    101 
    10297inline JSContextRef toRef(KJS::ExecState* e)
    10398{
     
    105100}
    106101
     102inline JSPropertyNameAccumulatorRef toRef(KJS::PropertyNameArray* l)
     103{
     104    return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
     105}
     106
    107107#endif // APICast_h
  • trunk/JavaScriptCore/API/JSBase.h

    r15437 r15468  
    4444typedef struct __JSClass* JSClassRef;
    4545
    46 /*! @typedef JSPropertyListRef A JavaScript property list. Used for listing the properties in an object so they can be enumerated. */
    47 typedef struct __JSPropertyList* JSPropertyListRef;
     46/*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */
     47typedef struct __JSPropertyNameArray* JSPropertyNameArrayRef;
    4848
    49 /*! @typedef JSPropertyEnumeratorRef A JavaScript property enumerator. Used for enumerating the properties in an object. */
    50 typedef struct __JSPropertyEnumerator* JSPropertyEnumeratorRef;
     49/*! @typedef JSPropertyNameAccumulatorRef A data type used to collect a JavaScript object's property names. */
     50typedef struct __JSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
    5151
    5252
  • trunk/JavaScriptCore/API/JSCallbackObject.cpp

    r15462 r15468  
    3131#include "JSObjectRef.h"
    3232#include "internal.h"
    33 #include "reference.h"
    34 #include "reference_list.h"
     33#include "PropertyNameArray.h"
    3534
    3635namespace KJS {
     
    291290}
    292291
    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));
     292void 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));
    300300
    301301        if (__JSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
     
    306306                StaticValueEntry* entry = it->second;
    307307                if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))
    308                     propertyList.append(Reference(this, Identifier(name)));
     308                    propertyNames.add(Identifier(name));
    309309            }
    310310        }
     
    317317                StaticFunctionEntry* entry = it->second;
    318318                if (!(entry->attributes & kJSPropertyAttributeDontEnum))
    319                     propertyList.append(Reference(this, Identifier(name)));
    320             }
    321         }
    322     }
    323 
    324     JSObject::getPropertyList(propertyList, recursive);
     319                    propertyNames.add(Identifier(name));
     320            }
     321        }
     322    }
     323
     324    JSObject::getPropertyNames(exec, propertyNames);
    325325}
    326326
  • trunk/JavaScriptCore/API/JSCallbackObject.h

    r15443 r15468  
    6161    virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args);
    6262
    63     virtual void getPropertyList(ReferenceList& propertyList, bool recursive);
     63    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    6464
    6565    virtual double toNumber(ExecState*) const;
  • trunk/JavaScriptCore/API/JSClassRef.cpp

    r15462 r15468  
    4545    , setProperty(definition->setProperty)
    4646    , deleteProperty(definition->deleteProperty)
    47     , addPropertiesToList(definition->addPropertiesToList)
     47    , getPropertyNames(definition->getPropertyNames)
    4848    , callAsFunction(definition->callAsFunction)
    4949    , callAsConstructor(definition->callAsConstructor)
  • trunk/JavaScriptCore/API/JSClassRef.h

    r15462 r15468  
    7474    JSObjectSetPropertyCallback setProperty;
    7575    JSObjectDeletePropertyCallback deleteProperty;
    76     JSObjectAddPropertiesToListCallback addPropertiesToList;
     76    JSObjectGetPropertyNamesCallback getPropertyNames;
    7777    JSObjectCallAsFunctionCallback callAsFunction;
    7878    JSObjectCallAsConstructorCallback callAsConstructor;
  • trunk/JavaScriptCore/API/JSObjectRef.cpp

    r15465 r15468  
    3838#include "internal.h"
    3939#include "object.h"
    40 #include "reference_list.h"
     40#include "PropertyNameArray.h"
    4141
    4242using namespace KJS;
     
    307307}
    308308
    309 struct __JSPropertyEnumerator
    310 {
    311     __JSPropertyEnumerator() : refCount(0), iterator(list.end())
     309struct __JSPropertyNameArray
     310{
     311    __JSPropertyNameArray() : refCount(0)
    312312    {
    313313    }
    314314   
    315315    unsigned refCount;
    316     ReferenceList list;
    317     ReferenceListIterator iterator;
     316    PropertyNameArray array;
    318317};
    319318
    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);
     319JSPropertyNameArrayRef 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
     331JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array)
     332{
     333    ++array->refCount;
     334    return array;
     335}
     336
     337void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
     338{
     339    if (--array->refCount == 0)
     340        delete array;
     341}
     342
     343size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
     344{
     345    return array->array.size();
     346}
     347
     348JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
     349{
     350    return toRef(array->array[index].ustring().rep());
     351}
     352
     353void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName)
     354{
     355    JSLock lock;
     356    PropertyNameArray* propertyNames = toJS(array);
    360357    UString::Rep* rep = toJS(propertyName);
    361358   
    362     jsPropertyList->append(Reference(jsObject, Identifier(rep)));
    363 }
     359    propertyNames->add(Identifier(rep));
     360}
  • trunk/JavaScriptCore/API/JSObjectRef.h

    r15464 r15468  
    155155
    156156/*!
    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
     164void GetPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator);
     165
     166Use JSPropertyNameAccumulatorAddName to add property names to accumulator.
     167
     168Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.
     169
     170It's only necessary to add names of properties that you handle
     171specially in your own get / set callbacks. Static property names,
     172names of standard JS properties, and properties from the prototype
     173will be added automatically.
    168174*/
    169175typedef void
    170 (*JSObjectAddPropertiesToListCallback) (JSObjectRef object, JSPropertyListRef propertyList);
     176(*JSObjectGetPropertyNamesCallback) (JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
    171177
    172178/*!
     
    327333    JSObjectSetPropertyCallback         setProperty;
    328334    JSObjectDeletePropertyCallback      deleteProperty;
    329     JSObjectAddPropertiesToListCallback addPropertiesToList;
     335    JSObjectGetPropertyNamesCallback    getPropertyNames;
    330336    JSObjectCallAsFunctionCallback      callAsFunction;
    331337    JSObjectCallAsConstructorCallback   callAsConstructor;
     
    486492@param propertyIndex The property's name as a number
    487493@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.
    489494@discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays.
    490495*/
    491 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSPropertyAttributes attributes);
     496void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value);
    492497
    493498/*!
     
    550555/*!
    551556@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*/
     562JSPropertyNameArrayRef 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*/
     570JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array);
     571
     572/*!
     573@function
     574@abstract         Releases a JavaScript property name array.
     575@param array      The JSPropetyNameArray to release.
     576*/
     577void 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*/
     585size_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*/
     594JSStringRef 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*/
     602void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
    587603
    588604#ifdef __cplusplus
  • trunk/JavaScriptCore/API/testapi.c

    r15465 r15468  
    170170}
    171171
    172 static void MyObject_addPropertiesToList(JSObjectRef object, JSPropertyListRef propertyList)
     172static void MyObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
    173173{
    174174    UNUSED_PARAM(context);
     
    177177   
    178178    propertyName = JSStringCreateWithUTF8CString("alwaysOne");
    179     JSPropertyListAdd(propertyList, object, propertyName);
     179    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
    180180    JSStringRelease(propertyName);
    181181   
    182182    propertyName = JSStringCreateWithUTF8CString("myPropertyName");
    183     JSPropertyListAdd(propertyList, object, propertyName);
     183    JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
    184184    JSStringRelease(propertyName);
    185185}
     
    258258    MyObject_setProperty,
    259259    MyObject_deleteProperty,
    260     MyObject_addPropertiesToList,
     260    MyObject_getPropertyNames,
    261261    MyObject_callAsFunction,
    262262    MyObject_callAsConstructor,
     
    589589    JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(1), kJSPropertyAttributeNone, NULL);
    590590    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);
    596597    assert(count == 1); // jsCFString should not be enumerated
    597598
  • trunk/JavaScriptCore/ChangeLog

    r15465 r15468  
     12006-07-15  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by Darin.
     4       
     5        - switch property lists to be vector+set of Identifiers instead of list of References
     6       
     7        This has the following benefits:
     8       
     9        - no duplicates in property lists
     10        - simplifies API calls
     11        - probably more efficient, since linked list is gone
     12        - entirely removed Reference, ReferenceList and ProtectedReference types from the API
     13
     14        * kjs/PropertyNameArray.cpp: Added.
     15        (KJS::PropertyNameArray::add): Check set, if not already there, add to
     16        vector.
     17        * kjs/PropertyNameArray.h: Added.
     18        (KJS::PropertyNameArray::PropertyNameArray): Newly added type, combines
     19        a set and a vector to make a unique but ordered list of identifiers.
     20        (KJS::PropertyNameArray::begin): ditto
     21        (KJS::PropertyNameArray::end): ditto
     22        (KJS::PropertyNameArray::size): ditto
     23        (KJS::PropertyNameArray::operator[]): ditto
     24        * kjs/array_instance.h:
     25        * kjs/array_object.cpp:
     26        (ArrayInstance::getPropertyNames): renamed from getPropertyList, updated
     27        for PropertyNameArray
     28        (ArrayInstance::setLength): updated for PropertyNameArray
     29        (ArrayInstance::pushUndefinedObjectsToEnd): ditto
     30        * kjs/nodes.cpp:
     31        (ForInNode::execute): updated for PropertyNameArray
     32        * kjs/nodes.h:
     33        * kjs/object.cpp:
     34        (KJS::JSObject::getPropertyNames): renamed from getPropertyList, updated
     35        for PropertyNameArray
     36        * kjs/object.h:
     37        * kjs/property_map.cpp:
     38        (KJS::PropertyMap::getEnumerablePropertyNames): updated for PropertyNameArray
     39        (KJS::PropertyMap::getSparseArrayPropertyNames): ditto
     40        * kjs/property_map.h:
     41        * kjs/protected_reference.h: Removed.
     42        * kjs/reference.cpp: Removed.
     43        * kjs/reference.h: Removed.
     44        * kjs/reference_list.cpp: Removed.
     45        * kjs/reference_list.h: Removed.
     46        * kjs/scope_chain.cpp:
     47        (KJS::ScopeChain::print): Use PropertyNamesArray instead of ReferenceList.
     48        * kjs/string_object.cpp:
     49        (StringInstance::getPropertyNames): Updated for new approach.
     50        * kjs/string_object.h:
     51        * kjs/ustring.h:
     52        * API/APICast.h:
     53        (toJS): Added overload for PropertyNameAccumulatorRef / PropertyNameArray*
     54        (toRef): ditto
     55        * API/JSBase.h:
     56        * API/JSCallbackObject.cpp:
     57        (KJS::JSCallbackObject::getPropertyNames): Fixed for new API.
     58        * API/JSCallbackObject.h:
     59        * API/JSObjectRef.cpp:
     60        (__JSPropertyNameArray::__JSPropertyNameArray): Type used for a publicly vended
     61        JSPropertyNameArrayRef.
     62        (JSObjectCopyPropertyNames): New API call - renamed / refactored from
     63        JSObjectCreatePropertyList
     64        (JSPropertyNameArrayRetain): new retain call for JSPropertyNameArray.
     65        (JSPropertyNameArrayRelease): new release call for - " -.
     66        (JSPropertyNameArrayGetCount): Instead of having to use a stateful enumerator you
     67        can now get the count and items in any order.
     68        (JSPropertyNameArrayGetNameAtIndex): See above.
     69        (JSPropertyNameAccumulatorAddName): What you add properties to is now an opaque
     70        accumulator object.
     71        * API/JSObjectRef.h: Prototyped new functions, removed old ones
     72        * JavaScriptCore.exp: Updated exported symbols.
     73        * JavaScriptCore.xcodeproj/project.pbxproj: Added new files, removed old.
     74        * API/testapi.c:
     75        (MyObject_getPropertyNames): Renamed / fixed callback to fit new paradigm.
     76        (main): Updated for new API.
     77
    1782006-07-15  Darin Adler  <darin@apple.com>
    279
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r15462 r15468  
    1414_JSObjectCallAsConstructor
    1515_JSObjectCallAsFunction
    16 _JSObjectCreatePropertyEnumerator
     16_JSObjectCopyPropertyNames
    1717_JSObjectDeleteProperty
    1818_JSObjectGetPrivate
    1919_JSObjectGetProperty
     20_JSObjectGetPropertyAtIndex
    2021_JSObjectGetPrototype
    2122_JSObjectHasProperty
     
    2829_JSObjectSetPrivate
    2930_JSObjectSetProperty
     31_JSObjectSetPropertyAtIndex
    3032_JSObjectSetPrototype
    31 _JSPropertyEnumeratorGetNextName
    32 _JSPropertyEnumeratorRelease
    33 _JSPropertyEnumeratorRetain
    34 _JSPropertyListAdd
     33_JSPropertyNameAccumulatorAddName
     34_JSPropertyNameArrayGetCount
     35_JSPropertyNameArrayGetNameAtIndex
     36_JSPropertyNameArrayRelease
     37_JSPropertyNameArrayRetain
    3538_JSStringCopyCFString
    3639_JSStringCreateWithCFString
     
    139142__ZN3KJS12PropertySlot15undefinedGetterEPNS_9ExecStateEPNS_8JSObjectERKNS_10IdentifierERKS0_
    140143__ZN3KJS12jsNumberCellEd
    141 __ZN3KJS13ReferenceList6appendERKNS_9ReferenceE
    142 __ZN3KJS13ReferenceListC1Ev
    143 __ZN3KJS13ReferenceListD1Ev
    144144__ZN3KJS13SavedBuiltinsC1Ev
    145145__ZN3KJS13SavedBuiltinsD1Ev
     
    147147__ZN3KJS15SavedPropertiesD1Ev
    148148__ZN3KJS16RuntimeObjectImpC1EPNS_8Bindings8InstanceE
     149__ZN3KJS17PropertyNameArray3addERKNS_10IdentifierE
    149150__ZN3KJS18lengthPropertyNameE
    150151__ZN3KJS19InternalFunctionImp11hasInstanceEPNS_9ExecStateEPNS_7JSValueE
     
    152153__ZN3KJS19InternalFunctionImpC2EPNS_17FunctionPrototypeERKNS_10IdentifierE
    153154__ZN3KJS19messagePropertyNameE
    154 __ZN3KJS21ReferenceListIteratorppEi
    155155__ZN3KJS21prototypePropertyNameE
    156156__ZN3KJS4List6appendEPNS_7JSValueE
     
    187187__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE
    188188__ZN3KJS8JSObject14deletePropertyEPNS_9ExecStateEj
    189 __ZN3KJS8JSObject15getPropertyListERNS_13ReferenceListEb
     189__ZN3KJS8JSObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE
    190190__ZN3KJS8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
    191191__ZN3KJS8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPPNS_7JSValueE
     
    207207__ZN3KJS9Collector7protectEPNS_7JSValueE
    208208__ZN3KJS9Collector9unprotectEPNS_7JSValueE
    209 __ZN3KJS9ReferenceC1EPNS_8JSObjectERKNS_10IdentifierE
    210209__ZN3KJSeqERKNS_7UStringEPKc
    211210__ZN3WTF10fastCallocEmm
     
    222221__ZNK3KJS11PropertyMap4saveERNS_15SavedPropertiesE
    223222__ZNK3KJS12DateInstance7getTimeERdRi
    224 __ZNK3KJS13ReferenceList3endEv
    225 __ZNK3KJS13ReferenceList5beginEv
    226223__ZNK3KJS19InternalFunctionImp14implementsCallEv
    227224__ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv
    228 __ZNK3KJS21ReferenceListIteratorneERKS0_
    229 __ZNK3KJS21ReferenceListIteratorptEv
    230225__ZNK3KJS4List2atEi
    231226__ZNK3KJS4List8copyTailEv
     
    258253__ZNK3KJS8JSObject9toBooleanEPNS_9ExecStateE
    259254__ZNK3KJS9ExecState18lexicalInterpreterEv
    260 __ZNK3KJS9Reference15getPropertyNameEv
    261255__ZTVN3KJS19InternalFunctionImpE
    262256__ZTVN3KJS8JSObjectE
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r15428 r15468  
    7878                14F137590A3A727E00F26F90 /* Context.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F137580A3A727E00F26F90 /* Context.cpp */; };
    7979                14F137830A3A765B00F26F90 /* context.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F137820A3A765B00F26F90 /* context.h */; settings = {ATTRIBUTES = (Private, ); }; };
    80                 652C107F08DA7B1E0020887D /* protected_reference.h in Headers */ = {isa = PBXBuildFile; fileRef = 652C107E08DA7B1E0020887D /* protected_reference.h */; };
     80                65400C110A69BAF200509887 /* PropertyNameArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65400C0F0A69BAF200509887 /* PropertyNameArray.cpp */; };
     81                65400C120A69BAF200509887 /* PropertyNameArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 65400C100A69BAF200509887 /* PropertyNameArray.h */; settings = {ATTRIBUTES = (Private, ); }; };
    8182                6541BD7208E80A17002CBEE7 /* TCPageMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 6541BD6E08E80A17002CBEE7 /* TCPageMap.h */; };
    8283                6541BD7308E80A17002CBEE7 /* TCSpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 6541BD6F08E80A17002CBEE7 /* TCSpinLock.h */; };
     
    146147                932F5B600822A1C700736975 /* config.h in Headers */ = {isa = PBXBuildFile; fileRef = F68EBB8C0255D4C601FF60F7 /* config.h */; settings = {ATTRIBUTES = (Private, ); }; };
    147148                932F5B610822A1C700736975 /* JavaScriptCorePrefix.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C290E60284F98E018635CA /* JavaScriptCorePrefix.h */; };
    148                 932F5B630822A1C700736975 /* reference_list.h in Headers */ = {isa = PBXBuildFile; fileRef = F54F0800030CD22001B5C2EB /* reference_list.h */; settings = {ATTRIBUTES = (Private, ); }; };
    149                 932F5B640822A1C700736975 /* reference.h in Headers */ = {isa = PBXBuildFile; fileRef = F5341391030CEEB1018BE7F3 /* reference.h */; settings = {ATTRIBUTES = (Private, ); }; };
    150149                932F5B650822A1C700736975 /* completion.h in Headers */ = {isa = PBXBuildFile; fileRef = F5BB2BC5030F772101FCFE1D /* completion.h */; settings = {ATTRIBUTES = (Private, ); }; };
    151150                932F5B660822A1C700736975 /* identifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A349A038AE7C6008635CE /* identifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    209208                932F5BA90822A1C700736975 /* value.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F692A8870255597D01FF60F7 /* value.cpp */; };
    210209                932F5BAB0822A1C700736975 /* nodes2string.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5FFE656026B47A6018635CA /* nodes2string.cpp */; };
    211                 932F5BAC0822A1C700736975 /* reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5341390030CEEB1018BE7F3 /* reference.cpp */; settings = {ATTRIBUTES = (Private, ); }; };
    212                 932F5BAD0822A1C700736975 /* reference_list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F5341394030CF5F8018BE7F3 /* reference_list.cpp */; settings = {ATTRIBUTES = (Private, ); }; };
    213210                932F5BAE0822A1C700736975 /* identifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933A349D038AE80F008635CE /* identifier.cpp */; };
    214211                932F5BAF0822A1C700736975 /* scope_chain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9374D3A8038D9D74008635CE /* scope_chain.cpp */; };
     
    426423                651F6412039D5B5F0078395C /* dtoa.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dtoa.cpp; sourceTree = "<group>"; tabWidth = 8; };
    427424                651F6413039D5B5F0078395C /* dtoa.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = dtoa.h; sourceTree = "<group>"; tabWidth = 8; };
    428                 652C107E08DA7B1E0020887D /* protected_reference.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = protected_reference.h; sourceTree = "<group>"; tabWidth = 8; };
     425                65400C0F0A69BAF200509887 /* PropertyNameArray.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PropertyNameArray.cpp; sourceTree = "<group>"; };
     426                65400C100A69BAF200509887 /* PropertyNameArray.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PropertyNameArray.h; sourceTree = "<group>"; };
    429427                6541720E039E08B90058BFEB /* dftables.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = dftables.c; path = pcre/dftables.c; sourceTree = "<group>"; tabWidth = 8; };
    430428                6541720F039E08B90058BFEB /* pcre.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = pcre.h; path = pcre/pcre.h; sourceTree = "<group>"; tabWidth = 8; };
     
    519517                E195679409E7CF1200B89D13 /* Unicode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unicode.h; sourceTree = "<group>"; };
    520518                E195679509E7CF1200B89D13 /* UnicodeCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnicodeCategory.h; sourceTree = "<group>"; };
    521                 F5341390030CEEB1018BE7F3 /* reference.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reference.cpp; sourceTree = "<group>"; tabWidth = 8; };
    522                 F5341391030CEEB1018BE7F3 /* reference.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = reference.h; sourceTree = "<group>"; tabWidth = 8; };
    523                 F5341394030CF5F8018BE7F3 /* reference_list.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reference_list.cpp; sourceTree = "<group>"; tabWidth = 8; };
    524                 F54F0800030CD22001B5C2EB /* reference_list.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = reference_list.h; sourceTree = "<group>"; tabWidth = 8; };
    525519                F5BB2BC5030F772101FCFE1D /* completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = completion.h; sourceTree = "<group>"; tabWidth = 8; };
    526520                F5C290E60284F98E018635CA /* JavaScriptCorePrefix.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = JavaScriptCorePrefix.h; path = ../JavaScriptCorePrefix.h; sourceTree = "<group>"; tabWidth = 8; };
     
    838832                        isa = PBXGroup;
    839833                        children = (
     834                                65400C0F0A69BAF200509887 /* PropertyNameArray.cpp */,
     835                                65400C100A69BAF200509887 /* PropertyNameArray.h */,
    840836                                938772E5038BFE19008635CE /* array_instance.h */,
    841837                                F692A84D0255597D01FF60F7 /* array_object.cpp */,
     
    903899                                65621E6C089E859700760F35 /* property_slot.h */,
    904900                                65C02FBB0637462A003E7EE6 /* protect.h */,
    905                                 652C107E08DA7B1E0020887D /* protected_reference.h */,
    906                                 F5341390030CEEB1018BE7F3 /* reference.cpp */,
    907                                 F5341391030CEEB1018BE7F3 /* reference.h */,
    908                                 F5341394030CF5F8018BE7F3 /* reference_list.cpp */,
    909                                 F54F0800030CD22001B5C2EB /* reference_list.h */,
    910901                                F692A87D0255597D01FF60F7 /* regexp.cpp */,
    911902                                F692A87E0255597D01FF60F7 /* regexp.h */,
     
    10301021                                932F5B600822A1C700736975 /* config.h in Headers */,
    10311022                                932F5B610822A1C700736975 /* JavaScriptCorePrefix.h in Headers */,
    1032                                 932F5B630822A1C700736975 /* reference_list.h in Headers */,
    1033                                 932F5B640822A1C700736975 /* reference.h in Headers */,
    10341023                                932F5B650822A1C700736975 /* completion.h in Headers */,
    10351024                                932F5B660822A1C700736975 /* identifier.h in Headers */,
     
    10741063                                93E26BFE08B151D400F85226 /* ucpinternal.h in Headers */,
    10751064                                93E26C1308B1523D00F85226 /* ucptable.c in Headers */,
    1076                                 652C107F08DA7B1E0020887D /* protected_reference.h in Headers */,
    10771065                                65E217BD08E7EECC0023E5F6 /* Assertions.h in Headers */,
    10781066                                65E217C008E7EECC0023E5F6 /* FastMalloc.h in Headers */,
     
    11301118                                1440F8AE0A508D200005F061 /* JSCallbackConstructor.h in Headers */,
    11311119                                1440FCE30A51E46B0005F061 /* JSClassRef.h in Headers */,
     1120                                65400C120A69BAF200509887 /* PropertyNameArray.h in Headers */,
    11321121                        );
    11331122                        runOnlyForDeploymentPostprocessing = 0;
     
    13571346                                932F5BA90822A1C700736975 /* value.cpp in Sources */,
    13581347                                932F5BAB0822A1C700736975 /* nodes2string.cpp in Sources */,
    1359                                 932F5BAC0822A1C700736975 /* reference.cpp in Sources */,
    1360                                 932F5BAD0822A1C700736975 /* reference_list.cpp in Sources */,
    13611348                                932F5BAE0822A1C700736975 /* identifier.cpp in Sources */,
    13621349                                932F5BAF0822A1C700736975 /* scope_chain.cpp in Sources */,
     
    14171404                                1440FCE40A51E46B0005F061 /* JSClassRef.cpp in Sources */,
    14181405                                1421359B0A677F4F00A8195E /* JSBase.cpp in Sources */,
     1406                                65400C110A69BAF200509887 /* PropertyNameArray.cpp in Sources */,
    14191407                        );
    14201408                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/kjs/array_instance.h

    r15385 r15468  
    4040    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    4141    virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
    42     virtual void getPropertyList(ReferenceList& propertyList, bool recursive);
     42    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    4343
    4444    virtual void mark();
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r15385 r15468  
    2929#include "lookup.h"
    3030#include "operations.h"
    31 #include "reference_list.h"
     31#include "PropertyNameArray.h"
    3232#include <wtf/HashSet.h>
    3333#include <stdio.h>
     
    200200}
    201201
    202 void ArrayInstance::getPropertyList(ReferenceList& propertyList, bool recursive)
     202void ArrayInstance::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
    203203{
    204204  // avoid fetching this every time through the loop
    205   JSValue *undefined = jsUndefined();
    206 
    207   //### FIXME: should avoid duplicates with prototype
     205  JSValue* undefined = jsUndefined();
     206 
    208207  for (unsigned i = 0; i < storageLength; ++i) {
    209     JSValue *imp = storage[i];
    210     if (imp && imp != undefined) {
    211       propertyList.append(Reference(this, i));
    212     }
    213   }
    214   return JSObject::getPropertyList(propertyList, recursive);
     208    JSValue* value = storage[i];
     209    if (value && value != undefined)
     210      propertyNames.add(Identifier::from(i));
     211  }
     212 
     213  JSObject::getPropertyNames(exec, propertyNames);
    215214}
    216215
     
    244243
    245244  if (newLength < length) {
    246     ReferenceList sparseProperties;
    247    
    248     _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this);
    249    
    250     ReferenceListIterator it = sparseProperties.begin();
    251     while (it != sparseProperties.end()) {
    252       Reference ref = it++;
     245    PropertyNameArray sparseProperties;
     246   
     247    _prop.getSparseArrayPropertyNames(sparseProperties);
     248   
     249    PropertyNameArrayIterator end = sparseProperties.end();
     250   
     251    for (PropertyNameArrayIterator it = sparseProperties.begin(); it != end; ++it) {
     252      Identifier name = *it;
    253253      bool ok;
    254       unsigned index = ref.getPropertyName().toArrayIndex(&ok);
    255       if (ok && index > newLength) {
    256         ref.deleteValue(exec);
    257       }
     254      unsigned index = name.toArrayIndex(&ok);
     255      if (ok && index > newLength)
     256        deleteProperty(exec, name);
    258257    }
    259258  }
     
    361360        }
    362361    }
    363    
    364     ReferenceList sparseProperties;
    365     _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this);
    366     unsigned newLength = o + sparseProperties.length();
    367 
    368     if (newLength > storageLength) {
    369       resizeStorage(newLength);
    370     }
    371 
    372     ReferenceListIterator it = sparseProperties.begin();
    373     while (it != sparseProperties.end()) {
    374       Reference ref = it++;
    375       storage[o] = ref.getValue(exec);
    376       JSObject::deleteProperty(exec, ref.getPropertyName());
    377       o++;
     362   
     363    PropertyNameArray sparseProperties;
     364    _prop.getSparseArrayPropertyNames(sparseProperties);
     365    unsigned newLength = o + sparseProperties.size();
     366   
     367    if (newLength > storageLength)
     368        resizeStorage(newLength);
     369   
     370    PropertyNameArrayIterator end = sparseProperties.end();
     371    for (PropertyNameArrayIterator it = sparseProperties.begin(); it != end; ++it) {
     372        Identifier name = *it;
     373        storage[o] = get(exec, name);
     374        JSObject::deleteProperty(exec, name);
     375        o++;
    378376    }
    379377   
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r15385 r15468  
    3636#include "lexer.h"
    3737#include "operations.h"
    38 #include "reference_list.h"
     38#include "PropertyNameArray.h"
    3939#include <wtf/HashSet.h>
    4040#include <wtf/HashCountedSet.h>
     
    18601860  JSObject *v;
    18611861  Completion c;
    1862   ReferenceList propertyList;
     1862  PropertyNameArray propertyNames;
    18631863
    18641864  if (varDecl) {
     
    18791879  KJS_CHECKEXCEPTION
    18801880  v = e->toObject(exec);
    1881   v->getPropertyList(propertyList);
    1882 
    1883   ReferenceListIterator propIt = propertyList.begin();
    1884 
    1885   while (propIt != propertyList.end()) {
    1886     Identifier name = propIt->getPropertyName();
    1887     if (!v->hasProperty(exec, name)) {
    1888       propIt++;
    1889       continue;
    1890     }
    1891 
    1892     JSValue *str = jsString(name.ustring());
    1893 
    1894     if (lexpr->isResolveNode()) {
     1881  v->getPropertyNames(exec, propertyNames);
     1882 
     1883  PropertyNameArrayIterator end = propertyNames.end();
     1884  for (PropertyNameArrayIterator it = propertyNames.begin(); it != end; ++it) {
     1885      const Identifier &name = *it;
     1886      if (!v->hasProperty(exec, name))
     1887          continue;
     1888
     1889      JSValue *str = jsString(name.ustring());
     1890
     1891      if (lexpr->isResolveNode()) {
    18951892        const Identifier &ident = static_cast<ResolveNode *>(lexpr.get())->identifier();
    18961893
     
    19511948      }
    19521949    }
    1953 
    1954     propIt++;
    19551950  }
    19561951
  • trunk/JavaScriptCore/kjs/nodes.h

    r14502 r15468  
    3535  class PropertyNameNode;
    3636  class PropertyListNode;
    37   class Reference;
    3837  class RegExp;
    3938  class SourceElementsNode;
  • trunk/JavaScriptCore/kjs/object.cpp

    r15385 r15468  
    3030#include "nodes.h"
    3131#include "operations.h"
    32 #include "reference_list.h"
     32#include "PropertyNameArray.h"
    3333#include <math.h>
    3434
     
    476476}
    477477
    478 void JSObject::getPropertyList(ReferenceList& propertyList, bool recursive)
    479 {
    480   _prop.addEnumerablesToReferenceList(propertyList, this);
     478void JSObject::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
     479{
     480   _prop.getEnumerablePropertyNames(propertyNames);
    481481
    482482  // Add properties from the static hashtable of properties
     
    487487      const HashEntry *e = info->propHashTable->entries;
    488488      for (int i = 0; i < size; ++i, ++e) {
    489         if ( e->s && !(e->attr & DontEnum) )
    490           propertyList.append(Reference(this, e->s)); /// ######### check for duplicates with the propertymap
     489        if (e->s && !(e->attr & DontEnum))
     490          propertyNames.add(e->s);
    491491      }
    492492    }
    493493    info = info->parentClass;
    494494  }
    495   if (_proto->isObject() && recursive)
    496       static_cast<JSObject*>(_proto)->getPropertyList(propertyList, recursive);
     495  if (_proto->isObject())
     496     static_cast<JSObject*>(_proto)->getPropertyNames(exec, propertyNames);
    497497}
    498498
  • trunk/JavaScriptCore/kjs/object.h

    r15385 r15468  
    3939  class ListImp;
    4040  class InternalFunctionImp;
     41  class PropertyNameArray;
    4142
    4243  // ECMA 262-3 8.6.1
     
    441442    void setScope(const ScopeChain &s) { _scope = s; }
    442443
    443     /**
    444      * Returns a List of References to all the properties of the object. Used
    445      * in "for x in y" statements. The list is created new, so it can be freely
    446      * modified without affecting the object's properties. It should be deleted
    447      * by the caller.
    448      *
    449      * Subclasses can override this method in ObjectImpl to provide the
    450      * appearance of
    451      * having extra properties other than those set specifically with put().
    452      *
    453      * @param exec The current execution state
    454      * @param recursive Whether or not properties in the object's prototype
    455      * chain should be
    456      * included in the list.
    457      * @return A List of References to properties of the object.
    458      **/
    459     virtual void getPropertyList(ReferenceList& propertyList, bool recursive = true);
     444    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    460445
    461446    /**
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r14951 r15468  
    2525#include "object.h"
    2626#include "protect.h"
    27 #include "reference_list.h"
     27#include "PropertyNameArray.h"
    2828#include <algorithm>
    2929#include <wtf/FastMalloc.h>
     
    7575
    7676// lastIndexUsed is an ever-increasing index used to identify the order items
    77 // were inserted into the property map. It's vital that addEnumerablesToReferenceList
     77// were inserted into the property map. It's vital that getEnumerablePropertyNames
    7878// return the properties in the order they were added for compatibility with other
    7979// browsers' JavaScript implementations.
     
    584584}
    585585
    586 void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, JSObject *base) const
     586void PropertyMap::getEnumerablePropertyNames(PropertyNameArray& propertyNames) const
    587587{
    588588    if (!_table) {
     
    590590        UString::Rep *key = _singleEntry.key;
    591591        if (key && !(_singleEntry.attributes & DontEnum))
    592             list.append(Reference(base, Identifier(key)));
     592            propertyNames.add(Identifier(key));
    593593#endif
    594594        return;
     
    611611    qsort(sortedEnumerables.data(), p - sortedEnumerables.data(), sizeof(Entry*), comparePropertyMapEntryIndices);
    612612
    613     // Put the keys of the sorted entries into the reference list.
     613    // Put the keys of the sorted entries into the list.
    614614    for (Entry** q = sortedEnumerables.data(); q != p; ++q)
    615         list.append(Reference(base, Identifier((*q)->key)));
    616 }
    617 
    618 void PropertyMap::addSparseArrayPropertiesToReferenceList(ReferenceList &list, JSObject *base) const
     615        propertyNames.add(Identifier(q[0]->key));
     616}
     617
     618void PropertyMap::getSparseArrayPropertyNames(PropertyNameArray& propertyNames) const
    619619{
    620620    if (!_table) {
     
    626626            k.toUInt32(&fitsInUInt32);
    627627            if (fitsInUInt32)
    628                 list.append(Reference(base, Identifier(key)));
     628                propertyNames.add(Identifier(key));
    629629        }
    630630#endif
     
    641641            k.toUInt32(&fitsInUInt32);
    642642            if (fitsInUInt32)
    643                 list.append(Reference(base, Identifier(key)));
     643                propertyNames.add(Identifier(key));
    644644        }
    645645    }
  • trunk/JavaScriptCore/kjs/property_map.h

    r14951 r15468  
    2929namespace KJS {
    3030
     31    class PropertyNameArray;
    3132    class JSObject;
    32     class ReferenceList;
    3333    class JSValue;
    3434   
     
    8181
    8282        void mark() const;
    83         void addEnumerablesToReferenceList(ReferenceList &, JSObject *) const;
    84         void addSparseArrayPropertiesToReferenceList(ReferenceList &, JSObject *) const;
     83        void getEnumerablePropertyNames(PropertyNameArray&) const;
     84        void getSparseArrayPropertyNames(PropertyNameArray&) const;
    8585
    8686        void save(SavedProperties &) const;
  • trunk/JavaScriptCore/kjs/scope_chain.cpp

    r15385 r15468  
    2222#include "config.h"
    2323#include "scope_chain.h"
    24 #include "reference_list.h"
     24#include "PropertyNameArray.h"
     25#include "object.h"
    2526
    2627namespace KJS {
     
    4344    for (ScopeChainIterator scopeIter = begin(); scopeIter != scopeEnd; ++scopeIter) {
    4445        JSObject* o = *scopeIter;
    45         ReferenceList propertyList;
    46         o->getPropertyList(propertyList, false);
    47         ReferenceListIterator propEnd = propertyList.end();
     46        PropertyNameArray propertyNames;
     47        // FIXME: should pass ExecState here!
     48        o->getPropertyNames(0, propertyNames);
     49        PropertyNameArrayIterator propEnd = propertyNames.end();
    4850
    4951        fprintf(stderr, "----- [scope %p] -----\n", o);
    50         for (ReferenceListIterator propIter = propertyList.begin(); propIter != propEnd; propIter++) {
    51             Identifier name = propIter->getPropertyName();
     52        for (PropertyNameArrayIterator propIter = propertyNames.begin(); propIter != propEnd; propIter++) {
     53            Identifier name = *propIter;
    5254            fprintf(stderr, "%s, ", name.ascii());
    5355        }
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r15385 r15468  
    2727#include "error_object.h"
    2828#include "operations.h"
    29 #include "reference_list.h"
     29#include "PropertyNameArray.h"
    3030#include "regexp_object.h"
    3131#include <wtf/unicode/Unicode.h>
     
    9595}
    9696
    97 void StringInstance::getPropertyList(ReferenceList& propertyList, bool recursive)
    98 {
    99   //### FIXME: should avoid duplicates with prototype
     97void StringInstance::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
     98{
    10099  int size = internalValue()->getString().size();
    101100  for (int i = 0; i < size; i++)
    102     propertyList.append(Reference(this, i));
    103   return JSObject::getPropertyList(propertyList, recursive);
     101    propertyNames.add(Identifier(UString(i)));
     102  return JSObject::getPropertyNames(exec, propertyNames);
    104103}
    105104
  • trunk/JavaScriptCore/kjs/string_object.h

    r15385 r15468  
    3232    StringInstance(JSObject *proto, const UString &string);
    3333
    34     virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
    35     virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
    36     virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    37     virtual void getPropertyList(ReferenceList& propertyList, bool recursive);
     34    virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     35    virtual void put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr = None);
     36    virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName);
     37    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    3838
    3939    virtual const ClassInfo *classInfo() const { return &info; }
  • trunk/JavaScriptCore/kjs/ustring.h

    r14951 r15468  
    133133     */
    134134    unsigned char high() const { return ref().uc >> 8; }
     135
    135136  private:
    136137    // not implemented, can only be constructed from UString
     
    216217
    217218  public:
     219
    218220    /**
    219221     * Constructs a null string.
  • trunk/JavaScriptGlue/ChangeLog

    r15440 r15468  
     12006-07-15  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by Darin.
     4
     5        - switch property lists to be vector+set of Identifiers instead of list of References
     6       
     7        * JSUtils.cpp:
     8        (KJSValueToCFTypeInternal): updated for JSC SPI changes
     9        * JSValueWrapper.cpp:
     10        (JSValueWrapper::JSObjectCopyPropertyNames): ditto
     11        * UserObjectImp.cpp:
     12        (UserObjectImp::getPropertyNames): ditto
     13        * UserObjectImp.h:
     14
    115=== Safari-521.17 ===
    216
  • trunk/JavaScriptGlue/JSUtils.cpp

    r15386 r15468  
    3535#include "JSValueWrapper.h"
    3636#include "JSObject.h"
    37 #include <JavaScriptCore/reference_list.h>
     37#include <JavaScriptCore/PropertyNameArray.h>
    3838
    3939struct ObjectImpList {
     
    295295                        JSInterpreter* intrepreter = (JSInterpreter*)exec->dynamicInterpreter();
    296296                        if (intrepreter && (intrepreter->Flags() & kJSFlagConvertAssociativeArray)) {
    297                             ReferenceList propList;
    298                             object->getPropertyList(propList);
    299                             ReferenceListIterator iter = propList.begin();
    300                             ReferenceListIterator end = propList.end();
     297                            PropertyNameArray propNames;
     298                            object->getPropertyNames(exec, propNames);
     299                            PropertyNameArrayIterator iter = propNames.begin();
     300                            PropertyNameArrayIterator end = propNames.end();
    301301                            while(iter != end && isArray)
    302302                            {
    303                                 Identifier propName = iter->getPropertyName();
     303                                Identifier propName = *iter;
    304304                                UString ustr = propName.ustring();
    305305                                const UniChar* uniChars = (const UniChar*)ustr.data();
     
    334334                    {
    335335                        // Not an array, just treat it like a dictionary which contains (property name, property value) pairs
    336                         ReferenceList propList;
    337                         object->getPropertyList(propList);
     336                        PropertyNameArray propNames;
     337                        object->getPropertyNames(exec, propNames);
    338338                        {
    339339                            result = CFDictionaryCreateMutable(0,
     
    343343                            if (result)
    344344                            {
    345                                 ReferenceListIterator iter = propList.begin();
    346                                 ReferenceListIterator end = propList.end();
     345                                PropertyNameArrayIterator iter = propNames.begin();
     346                                PropertyNameArrayIterator end = propNames.end();
    347347                                while(iter != end)
    348348                                {
    349                                     Identifier propName = iter->getPropertyName();
     349                                    Identifier propName = *iter;
    350350                                    if (object->hasProperty(exec, propName))
    351351                                    {
  • trunk/JavaScriptGlue/JSValueWrapper.cpp

    r15437 r15468  
    2929#include "config.h"
    3030#include "JSValueWrapper.h"
    31 #include "JavaScriptCore/reference_list.h"
     31#include <JavaScriptCore/PropertyNameArray.h>
    3232#include <pthread.h>
    3333
     
    119119        ExecState* exec = getThreadGlobalExecState();
    120120        JSObject *object = ptr->GetValue()->toObject(exec);
    121         ReferenceList propList;
    122         object->getPropertyList(propList);
    123         ReferenceListIterator iterator = propList.begin();
    124 
    125         while (iterator != propList.end()) {
    126             Identifier name = iterator->getPropertyName();
     121        PropertyNameArray propNames;
     122        object->getPropertyNames(exec, propNames);
     123        PropertyNameArrayIterator iterator = propNames.begin();
     124
     125        while (iterator != propNames.end()) {
     126            Identifier name = *iterator;
    127127            CFStringRef nameStr = IdentifierToCFString(name);
    128128
  • trunk/JavaScriptGlue/UserObjectImp.cpp

    r15386 r15468  
    2929#include "config.h"
    3030#include "UserObjectImp.h"
    31 #include <JavaScriptCore/reference_list.h>
     31#include <JavaScriptCore/PropertyNameArray.h>
    3232
    3333const ClassInfo UserObjectImp::info = {"UserObject", 0, 0, 0};
     
    123123
    124124
    125 void UserObjectImp::getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive)
     125void UserObjectImp::getPropertyNames(ExecState *exec, PropertyNameArray& propertyNames)
    126126{
    127127    JSUserObject* ptr = GetJSUserObject();
     
    133133            for (i = 0; i < count; i++) {
    134134                CFStringRef propertyName = (CFStringRef)CFArrayGetValueAtIndex(cfPropertyNames, i);
    135                 propertyList.append(Reference(this, CFStringToIdentifier(propertyName)));
     135                propertyNames.add(CFStringToIdentifier(propertyName));
    136136            }
    137137            CFRelease(cfPropertyNames);
    138138        }
    139139    }
    140     JSObject::getPropertyList(propertyList, recursive);
     140    JSObject::getPropertyNames(exec, propertyNames);
    141141}
    142142
  • trunk/JavaScriptGlue/UserObjectImp.h

    r14951 r15468  
    4545    virtual bool implementsCall() const;
    4646
    47     virtual void getPropertyList(ExecState *exec, ReferenceList& propertyList, bool recursive = true);
     47    virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    4848
    4949    virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
  • trunk/LayoutTests/ChangeLog

    r15459 r15468  
     12006-07-16  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Reviewed by Darin.
     4       
     5        - new test case and updated results for property list changes
     6
     7        * fast/js/for-in-avoid-duplicates-expected.txt: Added.
     8        * fast/js/for-in-avoid-duplicates.html: Added.
     9        * fast/js/kde/Array-expected.txt:
     10        * fast/js/resources/for-in-avoid-duplicates.js: Added.
     11
    1122006-07-15  Darin Adler  <darin@apple.com>
    213
  • trunk/LayoutTests/fast/js/kde/Array-expected.txt

    r13294 r15468  
    6666PASS arr.length is maxint
    6767PASS arr[maxint-1] is "test2"
    68 FAIL propnames.length should be 3 (of type number). Was 4 (of type number).
     68PASS propnames.length is 3
    6969PASS propnames[0] is '0'
    7070PASS propnames[1] is '1'
    71 FAIL propnames[2] should be 2 (of type string). Was 1 (of type string).
     71PASS propnames[2] is '2'
    7272PASS successfullyParsed is true
    7373
Note: See TracChangeset for help on using the changeset viewer.