Ignore:
Timestamp:
Jul 13, 2003, 2:40:45 PM (22 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • do some improvements Maciej suggested while reviewing the array index change
  • kjs/array_object.cpp: (getArrayIndex): Return a flag to say whether the index was value separately, to avoid in-band signalling. (ArrayInstanceImp::get): Update for new getArrayIndex parameters. (ArrayInstanceImp::put): Ditto. (ArrayInstanceImp::hasProperty): Ditto. (ArrayInstanceImp::setLength): Ditto.
  • kjs/ustring.cpp: (UString::toStrictUInt32): Check for overflow in a way that avoids doing a divide every time through the loop. But note that it adds an extra branch to the loop. I wonder which is worse.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/array_object.cpp

    r4630 r4639  
    7373// Rule from ECMA 15.2 about what an array index is.
    7474// Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.
    75 
    76 const unsigned maxUInt32 = 0xFFFFFFFFU;
    77 const unsigned notArrayIndex = maxUInt32;
    78 
    79 unsigned getArrayIndex(const Identifier &propertyName)
     75bool getArrayIndex(const Identifier &propertyName, unsigned &index)
    8076{
    8177  bool ok;
    82   unsigned index = propertyName.toStrictUInt32(&ok);
    83   if (!ok || index >= maxUInt32)
    84     return notArrayIndex;
    85   return index;
     78  unsigned i = propertyName.toStrictUInt32(&ok);
     79  if (!ok || i >= 0xFFFFFFFFU)
     80    return false;
     81  index = i;
     82  return true;
    8683}
    8784
     
    9188    return Number(length);
    9289
    93   unsigned index = getArrayIndex(propertyName);
    94   if (index != notArrayIndex) {
     90  unsigned index;
     91  if (getArrayIndex(propertyName, index)) {
    9592    if (index >= length)
    9693      return Undefined();
     
    124121  }
    125122 
    126   unsigned index = getArrayIndex(propertyName);
    127   if (index != notArrayIndex) {
     123  unsigned index;
     124  if (getArrayIndex(propertyName, index)) {
    128125    put(exec, index, value, attr);
    129126    return;
     
    157154    return true;
    158155 
    159   unsigned index = getArrayIndex(propertyName);
    160   if (index != notArrayIndex) {
     156  unsigned index;
     157  if (getArrayIndex(propertyName, index)) {
    161158    if (index >= length)
    162159      return false;
     
    265262    while (it != sparseProperties.end()) {
    266263      Reference ref = it++;
    267       unsigned index = getArrayIndex(ref.getPropertyName(exec));
    268       if (index != notArrayIndex && index > newLength) {
     264      unsigned index;
     265      if (getArrayIndex(ref.getPropertyName(exec), index) && index > newLength) {
    269266        ref.deleteValue(exec);
    270267      }
Note: See TracChangeset for help on using the changeset viewer.