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