Ignore:
Timestamp:
Jul 16, 2006, 2:06:28 PM (19 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.