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.h

    r15464 r15468  
    155155 
    156156/*!  
    157 @typedef JSObjectAddPropertiesToListCallback 
    158 @abstract The callback invoked when adding an object's properties to a property list. 
    159 @param object The JSObject whose properties need to be added to propertyList. 
    160 @param propertyList A JavaScript property list that will be used to enumerate object's properties. 
    161 @discussion If you named your function GetPropertyList, you would declare it like this: 
    162  
    163 void AddPropertiesToList(JSObjectRef object, JSPropertyListRef propertyList); 
    164  
    165 Use JSPropertyListAdd to add properties to propertyList. 
    166  
    167 Property lists are used by JSPropertyEnumerators and JavaScript for...in loops. 
     157@typedef JSObjectGetPropertyNamesCallback 
     158@abstract The callback invoked to get the names of an object's properties. 
     159@param context The current execution context. 
     160@param object The JSObject whose property names need to be appended to propertyNames. 
     161@param accumulator A JavaScript property name accumulator, to which the object should add the names of its properties. 
     162@discussion If you named your function GetPropertyNames, you would declare it like this: 
     163 
     164void GetPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef accumulator); 
     165 
     166Use JSPropertyNameAccumulatorAddName to add property names to accumulator. 
     167 
     168Property lists are used by JSPropertyEnumerators and JavaScript for...in loops.  
     169 
     170It's only necessary to add names of properties that you handle 
     171specially in your own get / set callbacks. Static property names, 
     172names of standard JS properties, and properties from the prototype 
     173will be added automatically. 
    168174*/ 
    169175typedef void 
    170 (*JSObjectAddPropertiesToListCallback) (JSObjectRef object, JSPropertyListRef propertyList); 
     176(*JSObjectGetPropertyNamesCallback) (JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames); 
    171177 
    172178/*!  
     
    327333    JSObjectSetPropertyCallback         setProperty; 
    328334    JSObjectDeletePropertyCallback      deleteProperty; 
    329     JSObjectAddPropertiesToListCallback addPropertiesToList; 
     335    JSObjectGetPropertyNamesCallback    getPropertyNames; 
    330336    JSObjectCallAsFunctionCallback      callAsFunction; 
    331337    JSObjectCallAsConstructorCallback   callAsConstructor; 
     
    486492@param propertyIndex The property's name as a number 
    487493@param value A JSValue to use as the property's value. 
    488 @param attributes A logically ORed set of JSPropertyAttributes to give to the property. 
    489494@discussion This is equivalent to setting a property by a string name containing the number, but allows faster access to JS arrays. 
    490495*/ 
    491 void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSPropertyAttributes attributes); 
     496void JSObjectSetPropertyAtIndex(JSContextRef context, JSObjectRef object, unsigned propertyIndex, JSValueRef value); 
    492497 
    493498/*! 
     
    550555/*! 
    551556@function 
    552 @abstract Creates an enumerator for an object's properties. 
    553 @param object The object whose properties you want to enumerate. 
    554 @result A JSPropertyEnumerator with a list of object's properties. Ownership follows the Create Rule. 
    555 */ 
    556 JSPropertyEnumeratorRef JSObjectCreatePropertyEnumerator(JSObjectRef object); 
    557 /*! 
    558 @function 
    559 @abstract Retains a property enumerator. 
    560 @param enumerator The JSPropertyEnumerator to retain. 
    561 @result A JSPropertyEnumerator that is the same as enumerator. 
    562 */ 
    563 JSPropertyEnumeratorRef JSPropertyEnumeratorRetain(JSPropertyEnumeratorRef enumerator); 
    564 /*! 
    565 @function 
    566 @abstract Releases a property enumerator. 
    567 @param enumerator The JSPropertyEnumerator to release. 
    568 */ 
    569 void JSPropertyEnumeratorRelease(JSPropertyEnumeratorRef enumerator); 
    570 /*! 
    571 @function 
    572 @abstract Gets a property enumerator's next property. 
    573 @param enumerator The JSPropertyEnumerator whose next property you want to get. 
    574 @result A JSString containing the property's name, or NULL if all properties have been enumerated. 
    575 */ 
    576 JSStringRef JSPropertyEnumeratorGetNextName(JSPropertyEnumeratorRef enumerator); 
    577  
    578 /*! 
    579 @function 
    580 @abstract Adds a property to a property list. 
    581 @discussion Use this method inside a JSObjectAddPropertiesToListCallback to add a property to an object's property list. 
    582 @param propertyList The JSPropertyList to which you want to add a property. 
    583 @param thisObject The JSObject to which the property belongs. 
    584 @param propertyName A JSString specifying the property's name. 
    585 */ 
    586 void JSPropertyListAdd(JSPropertyListRef propertyList, JSObjectRef thisObject, JSStringRef propertyName); 
     557@abstract Get the names of all enumerable properties of an object. 
     558@param context The execution context to use. 
     559@param object The object from which to get property names.  
     560@result A JSPropertyNameArray containing the names of all the object's enumerable properties. 
     561*/ 
     562JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef context, JSObjectRef object); 
     563 
     564/*! 
     565@function 
     566@abstract         Retains a JavaScript property name array. 
     567@param array      The JSPropertyNameArray to retain. 
     568@result           A JSPropertyNameArray that is the same as array. 
     569*/ 
     570JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array); 
     571 
     572/*! 
     573@function 
     574@abstract         Releases a JavaScript property name array. 
     575@param array      The JSPropetyNameArray to release. 
     576*/ 
     577void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array); 
     578 
     579/*! 
     580@function 
     581@abstract      Get the number of items in a JavaScript property name array. 
     582@param array   The array from which to retrieve the count. 
     583@result        The count of items in the array. 
     584*/ 
     585size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array); 
     586 
     587/*! 
     588@function 
     589@abstract      Get a single item from a JavaScript property name array. 
     590@param array   The array from which to retrieve a property name. 
     591@param index   The index of the property name to retrieve. 
     592@result        A JSStringRef containing the name of the property. 
     593*/ 
     594JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index); 
     595 
     596/*! 
     597@function 
     598@abstract           Add a property name - useful while getting the property names for an object. 
     599@param accumulator  The accumulator object to which to add the property. 
     600@param propertyName The new property to add. 
     601*/ 
     602void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName); 
    587603 
    588604#ifdef __cplusplus