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/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   
Note: See TracChangeset for help on using the changeset viewer.