Changeset 15468 in webkit for trunk/JavaScriptCore/API/testapi.c


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