Changeset 10744 in webkit for trunk/JavaScriptCore/kjs


Ignore:
Timestamp:
Oct 5, 2005, 1:05:44 AM (20 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Eric.

  • fixed <rdar://problem/4260481> Remove Reference type from JavaScriptCore

Also fixed some bugs with for..in enumeration while I was at it. object
properties now come before prototype properties and duplicates
between object and prototype are listed only once.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/IdentifierSequencedSet.cpp: Added. (KJS::IdentifierSequencedSet::IdentifierSequencedSet): (KJS::IdentifierSequencedSet::deallocateVector): (KJS::IdentifierSequencedSet::~IdentifierSequencedSet): (KJS::IdentifierSequencedSet::insert):
  • kjs/IdentifierSequencedSet.h: Added. (KJS::IdentifierSequencedSetIterator::IdentifierSequencedSetIterator): (KJS::IdentifierSequencedSetIterator::operator*): (KJS::IdentifierSequencedSetIterator::operator->): (KJS::IdentifierSequencedSetIterator::operator++): (KJS::IdentifierSequencedSetIterator::operator==): (KJS::IdentifierSequencedSetIterator::operator!=): (KJS::IdentifierSequencedSet::begin): (KJS::IdentifierSequencedSet::end): (KJS::IdentifierSequencedSet::size):
  • kjs/array_instance.h:
  • kjs/array_object.cpp: (ArrayInstanceImp::getPropertyNames): (ArrayInstanceImp::setLength): (ArrayInstanceImp::pushUndefinedObjectsToEnd):
  • kjs/nodes.cpp: (ForInNode::execute):
  • kjs/nodes.h:
  • kjs/object.cpp: (KJS::ObjectImp::getPropertyNames):
  • kjs/object.h:
  • kjs/property_map.cpp: (KJS::PropertyMap::getEnumerablePropertyNames): (KJS::PropertyMap::getSparseArrayPropertyNames):
  • kjs/property_map.h:
  • kjs/protect.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/ustring.h: (KJS::UString::impl):
  • kxmlcore/HashSet.h:

LayoutTests:

Reviewed by Eric.

  • test case for some fixes I made to for..in enumeration. object properties now come before prototype properties and duplicates between object and prototype are listed only once.
  • fast/js/for-in-expected.txt: Added.
  • fast/js/for-in.html: Added.
Location:
trunk/JavaScriptCore/kjs
Files:
2 added
5 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_instance.h

    r10084 r10744  
    4040    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
    4141    virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
    42     virtual ReferenceList propList(ExecState *exec, bool recursive);
     42    virtual void getPropertyNames(ExecState *exec, IdentifierSequencedSet& propertyNames);
    4343
    4444    virtual void mark();
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r10701 r10744  
    2929#include "object.h"
    3030#include "operations.h"
    31 #include "reference_list.h"
    3231#include "types.h"
    3332#include "value.h"
     33#include "IdentifierSequencedSet.h"
    3434
    3535#include "array_object.lut.h"
     
    186186}
    187187
    188 ReferenceList ArrayInstanceImp::propList(ExecState *exec, bool recursive)
    189 {
    190   ReferenceList properties = ObjectImp::propList(exec,recursive);
    191 
     188void ArrayInstanceImp::getPropertyNames(ExecState *exec, IdentifierSequencedSet& propertyNames)
     189{
    192190  // avoid fetching this every time through the loop
    193191  ValueImp *undefined = jsUndefined();
     
    195193  for (unsigned i = 0; i < storageLength; ++i) {
    196194    ValueImp *imp = storage[i];
    197     if (imp && imp != undefined) {
    198       properties.append(Reference(this, i));
    199     }
    200   }
    201   return properties;
     195    if (imp && imp != undefined)
     196      propertyNames.insert(Identifier::from(i));
     197  }
     198
     199  ObjectImp::getPropertyNames(exec, propertyNames);
    202200}
    203201
     
    231229
    232230  if (newLength < length) {
    233     ReferenceList sparseProperties;
    234    
    235     _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this);
    236    
    237     ReferenceListIterator it = sparseProperties.begin();
    238     while (it != sparseProperties.end()) {
    239       Reference ref = it++;
     231    IdentifierSequencedSet sparseProperties;
     232   
     233    _prop.getSparseArrayPropertyNames(sparseProperties);
     234
     235    IdentifierSequencedSetIterator end = sparseProperties.end();
     236   
     237    for (IdentifierSequencedSetIterator it = sparseProperties.begin(); it != end; ++it) {
     238      Identifier name = *it;
    240239      bool ok;
    241       unsigned index = ref.getPropertyName(exec).toArrayIndex(&ok);
    242       if (ok && index > newLength) {
    243         ref.deleteValue(exec);
    244       }
     240      unsigned index = name.toArrayIndex(&ok);
     241      if (ok && index > newLength)
     242        deleteProperty(exec, name);
    245243    }
    246244  }
     
    349347    }
    350348   
    351     ReferenceList sparseProperties;
    352     _prop.addSparseArrayPropertiesToReferenceList(sparseProperties, this);
    353     unsigned newLength = o + sparseProperties.length();
    354 
    355     if (newLength > storageLength) {
     349    IdentifierSequencedSet sparseProperties;
     350    _prop.getSparseArrayPropertyNames(sparseProperties);
     351    unsigned newLength = o + sparseProperties.size();
     352
     353    if (newLength > storageLength)
    356354      resizeStorage(newLength);
    357     }
    358 
    359     ReferenceListIterator it = sparseProperties.begin();
    360     while (it != sparseProperties.end()) {
    361       Reference ref = it++;
    362       storage[o] = ref.getValue(exec);
    363       ObjectImp::deleteProperty(exec, ref.getPropertyName(exec));
     355
     356    IdentifierSequencedSetIterator end = sparseProperties.end();
     357    for (IdentifierSequencedSetIterator it = sparseProperties.begin(); it != end; ++it) {
     358      Identifier name = *it;
     359      storage[o] = get(exec, name);
     360      ObjectImp::deleteProperty(exec, name);
    364361      o++;
    365362    }
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r10701 r10744  
    4444#include "operations.h"
    4545#include "ustring.h"
    46 #include "reference_list.h"
     46#include "IdentifierSequencedSet.h"
    4747
    4848using namespace KJS;
     
    17811781  ObjectImp *v;
    17821782  Completion c;
    1783   ReferenceList propList;
     1783  IdentifierSequencedSet propertyNames;
    17841784
    17851785  if (varDecl) {
     
    18001800  KJS_CHECKEXCEPTION
    18011801  v = e->toObject(exec);
    1802   propList = v->propList(exec);
    1803 
    1804   ReferenceListIterator propIt = propList.begin();
    1805 
    1806   while (propIt != propList.end()) {
    1807     Identifier name = propIt->getPropertyName(exec);
    1808     if (!v->hasProperty(exec, name)) {
    1809       propIt++;
     1802  v->getPropertyNames(exec, propertyNames);
     1803
     1804  IdentifierSequencedSetIterator end = propertyNames.end();
     1805  for (IdentifierSequencedSetIterator it = propertyNames.begin(); it != end; ++it) {
     1806    const Identifier &name = *it;
     1807    if (!v->hasProperty(exec, name))
    18101808      continue;
    1811     }
    18121809
    18131810    ValueImp *str = jsString(name.ustring());
     
    18711868      }
    18721869    }
    1873 
    1874     propIt++;
    18751870  }
    18761871
  • trunk/JavaScriptCore/kjs/nodes.h

    r10701 r10744  
    3535  class PropertyNode;
    3636  class PropertyValueNode;
    37   class Reference;
    3837  class RegExp;
    3938  class SourceElementsNode;
  • trunk/JavaScriptCore/kjs/object.cpp

    r10728 r10744  
    2929#include "interpreter.h"
    3030#include "lookup.h"
    31 #include "reference_list.h"
     31#include "IdentifierSequencedSet.h"
    3232
    3333#include <assert.h>
     
    375375}
    376376
    377 ReferenceList ObjectImp::propList(ExecState *exec, bool recursive)
    378 {
    379   ReferenceList list;
    380   if (_proto->isObject() && recursive)
    381     list = static_cast<ObjectImp*>(_proto)->propList(exec,recursive);
    382 
    383   _prop.addEnumerablesToReferenceList(list, this);
     377void ObjectImp::getPropertyNames(ExecState *exec, IdentifierSequencedSet &propertyNames)
     378{
     379  _prop.getEnumerablePropertyNames(propertyNames);
    384380
    385381  // Add properties from the static hashtable of properties
     
    390386      const HashEntry *e = info->propHashTable->entries;
    391387      for (int i = 0; i < size; ++i, ++e) {
    392         if ( e->s && !(e->attr & DontEnum) )
    393           list.append(Reference(this, e->s)); /// ######### check for duplicates with the propertymap
     388        if (e->s && !(e->attr & DontEnum))
     389          propertyNames.insert(e->s);
    394390      }
    395391    }
     
    397393  }
    398394
    399   return list;
     395  if (_proto->isObject())
     396    static_cast<ObjectImp*>(_proto)->getPropertyNames(exec, propertyNames);
    400397}
    401398
  • trunk/JavaScriptCore/kjs/object.h

    r10207 r10744  
    4848  class HashEntry;
    4949  class ListImp;
     50  class IdentifierSequencedSet;
    5051
    5152  // ECMA 262-3 8.6.1
     
    423424     *
    424425     * @param exec The current execution state
    425      * @param recursive Whether or not properties in the object's prototype
    426      * chain should be
    427      * included in the list.
    428      * @return A List of References to properties of the object.
     426     * @param propertyNames A list of property names to be filled in by this call
    429427     **/
    430     virtual ReferenceList propList(ExecState *exec, bool recursive = true);
     428    virtual void getPropertyNames(ExecState *exec, IdentifierSequencedSet& propertyNames);
    431429
    432430    /**
  • trunk/JavaScriptCore/kjs/property_map.cpp

    r10701 r10744  
    2626#include "object.h"
    2727#include "protect.h"
    28 #include "reference_list.h"
     28#include "IdentifierSequencedSet.h"
    2929
    3030#include <algorithm>
     
    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.
     
    567567}
    568568
    569 void PropertyMap::addEnumerablesToReferenceList(ReferenceList &list, ObjectImp *base) const
     569void PropertyMap::getEnumerablePropertyNames(IdentifierSequencedSet& propertyNames) const
    570570{
    571571    if (!_table) {
     
    573573        UString::Rep *key = _singleEntry.key;
    574574        if (key && !(_singleEntry.attributes & DontEnum))
    575             list.append(Reference(base, Identifier(key)));
     575            propertyNames.insert(Identifier(key));
    576576#endif
    577577        return;
     
    599599    qsort(sortedEnumerables, p - sortedEnumerables, sizeof(sortedEnumerables[0]), comparePropertyMapEntryIndices);
    600600
    601     // Put the keys of the sorted entries into the reference list.
     601    // Put the keys of the sorted entries into the list.
    602602    Entry **q = sortedEnumerables;
    603     while (q != p)
    604         list.append(Reference(base, Identifier((*q++)->key)));
     603    while (q != p) {
     604        propertyNames.insert(Identifier(q[0]->key));
     605        ++q;
     606    }
    605607
    606608    // Deallocate the buffer.
     
    609611}
    610612
    611 void PropertyMap::addSparseArrayPropertiesToReferenceList(ReferenceList &list, ObjectImp *base) const
     613void PropertyMap::getSparseArrayPropertyNames(IdentifierSequencedSet& propertyNames) const
    612614{
    613615    if (!_table) {
     
    619621            k.toUInt32(&fitsInUInt32);
    620622            if (fitsInUInt32)
    621                 list.append(Reference(base, Identifier(key)));
     623                propertyNames.insert(Identifier(key));
    622624        }
    623625#endif
     
    634636            k.toUInt32(&fitsInUInt32);
    635637            if (fitsInUInt32)
    636                 list.append(Reference(base, Identifier(key)));
     638                propertyNames.insert(Identifier(key));
    637639        }
    638640    }
  • trunk/JavaScriptCore/kjs/property_map.h

    r10180 r10744  
    2828namespace KJS {
    2929
     30    class IdentifierSequencedSet;
    3031    class ObjectImp;
    31     class ReferenceList;
    3232    class ValueImp;
    3333   
     
    8282
    8383        void mark() const;
    84         void addEnumerablesToReferenceList(ReferenceList &, ObjectImp *) const;
    85         void addSparseArrayPropertiesToReferenceList(ReferenceList &, ObjectImp *) const;
     84        void getEnumerablePropertyNames(IdentifierSequencedSet&) const;
     85        void getSparseArrayPropertyNames(IdentifierSequencedSet&) const;
    8686
    8787        void save(SavedProperties &) const;
  • trunk/JavaScriptCore/kjs/protect.h

    r10563 r10744  
    2525#define _KJS_PROTECT_H_
    2626
    27 #include "reference.h"
    2827#include "value.h"
    2928#include "protected_values.h"
  • trunk/JavaScriptCore/kjs/ustring.h

    r10701 r10744  
    241241
    242242  public:
     243    typedef Rep Impl;
     244
    243245    /**
    244246     * Constructs a null string.
     
    462464    static void globalClear();
    463465#endif
     466
     467    Impl *impl() const { return rep; }
    464468  private:
    465469    UString(Rep *r) { attach(r); }
Note: See TracChangeset for help on using the changeset viewer.