Show
Ignore:
Timestamp:
07/16/06 14:06:28 (2 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.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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}