Show
Ignore:
Timestamp:
08/18/08 11:14:49 (5 months ago)
Author:
odole
Message:

merge with webkit revision 35814

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/JavaScriptCore/kjs/JSArray.cpp

    r436 r440  
    3535 
    3636namespace KJS { 
     37 
     38ASSERT_CLASS_FITS_IN_CELL(JSArray); 
    3739 
    3840// Overview of JSArray 
     
    129131    unsigned initialCapacity = min(initialLength, MIN_SPARSE_ARRAY_INDEX); 
    130132 
    131     m_length = initialLength
     133    m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity)))
    132134    m_fastAccessCutoff = 0; 
    133     m_storage = static_cast<ArrayStorage*>(fastZeroedMalloc(storageSize(initialCapacity))); 
    134135    m_storage->m_vectorLength = initialCapacity; 
     136    m_storage->m_length = initialLength; 
    135137 
    136138    Heap::heap(this)->reportExtraMemoryCost(initialCapacity * sizeof(JSValue*)); 
     
    144146    unsigned length = list.size(); 
    145147 
    146     m_length = length; 
    147148    m_fastAccessCutoff = length; 
    148149 
     
    152153    storage->m_numValuesInVector = length; 
    153154    storage->m_sparseValueMap = 0; 
     155    storage->m_length = length; 
    154156 
    155157    size_t i = 0; 
     
    174176} 
    175177 
    176 JSValue* JSArray::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot) 
    177 { 
    178     return jsNumber(exec, static_cast<JSArray*>(slot.slotBase())->m_length); 
    179 } 
    180  
    181178bool JSArray::getOwnPropertySlot(ExecState* exec, unsigned i, PropertySlot& slot) 
    182179{ 
    183180    ArrayStorage* storage = m_storage; 
    184181 
    185     if (i >= m_length) { 
     182    if (i >= storage->m_length) { 
    186183        if (i > MAX_ARRAY_INDEX) 
    187184            return getOwnPropertySlot(exec, Identifier::from(exec, i), slot); 
     
    211208{ 
    212209    if (propertyName == exec->propertyNames().length) { 
    213         slot.setCustom(this, lengthGetter); 
     210        slot.setValue(jsNumber(exec, length())); 
    214211        return true; 
    215212    } 
     
    250247    checkConsistency(); 
    251248 
    252     unsigned length = m_length; 
     249    unsigned length = m_storage->m_length; 
    253250    if (i >= length && i <= MAX_ARRAY_INDEX) { 
    254251        length = i + 1; 
    255         m_length = length; 
     252        m_storage->m_length = length; 
    256253    } 
    257254 
     
    264261        } 
    265262        valueSlot = value; 
    266         if (++m_storage->m_numValuesInVector == m_length) 
    267             m_fastAccessCutoff = m_length; 
     263        if (++m_storage->m_numValuesInVector == m_storage->m_length) 
     264            m_fastAccessCutoff = m_storage->m_length; 
    268265        checkConsistency(); 
    269266        return; 
     
    419416    ArrayStorage* storage = m_storage; 
    420417 
    421     unsigned usedVectorLength = min(m_length, storage->m_vectorLength); 
     418    unsigned usedVectorLength = min(storage->m_length, storage->m_vectorLength); 
    422419    for (unsigned i = 0; i < usedVectorLength; ++i) { 
    423420        if (storage->m_vector[i]) 
     
    465462    ArrayStorage* storage = m_storage; 
    466463 
    467     unsigned length = m_length; 
     464    unsigned length = m_storage->m_length; 
    468465 
    469466    if (newLength < length) { 
     
    493490    } 
    494491 
    495     m_length = newLength; 
     492    m_storage->m_length = newLength; 
    496493 
    497494    checkConsistency(); 
     
    504501    ArrayStorage* storage = m_storage; 
    505502 
    506     unsigned usedVectorLength = min(m_length, storage->m_vectorLength); 
     503    unsigned usedVectorLength = min(storage->m_length, storage->m_vectorLength); 
    507504    for (unsigned i = 0; i < usedVectorLength; ++i) { 
    508505        JSValue* value = storage->m_vector[i]; 
     
    667664    // The maximum tree depth is compiled in - but the caller is clearly up to no good 
    668665    // if a larger array is passed. 
    669     ASSERT(m_length <= static_cast<unsigned>(std::numeric_limits<int>::max())); 
    670     if (m_length > static_cast<unsigned>(std::numeric_limits<int>::max())) 
    671         return; 
    672  
    673     if (!m_length) 
    674         return; 
    675  
    676     unsigned usedVectorLength = min(m_length, m_storage->m_vectorLength); 
     666    ASSERT(m_storage->m_length <= static_cast<unsigned>(std::numeric_limits<int>::max())); 
     667    if (m_storage->m_length > static_cast<unsigned>(std::numeric_limits<int>::max())) 
     668        return; 
     669 
     670    if (!m_storage->m_length) 
     671        return; 
     672 
     673    unsigned usedVectorLength = min(m_storage->m_length, m_storage->m_vectorLength); 
    677674 
    678675    AVLTree<AVLTreeAbstractorForArrayCompare, 44> tree; // Depth 44 is enough for 2^31 items 
     
    771768    ArrayStorage* storage = m_storage; 
    772769 
    773     unsigned usedVectorLength = min(m_length, storage->m_vectorLength); 
     770    unsigned usedVectorLength = min(m_storage->m_length, storage->m_vectorLength); 
    774771 
    775772    unsigned numDefined = 0; 
     
    841838        ASSERT(!m_storage->m_sparseValueMap); 
    842839 
    843     ASSERT(m_fastAccessCutoff <= m_length); 
     840    ASSERT(m_fastAccessCutoff <= m_storage->m_length); 
    844841    ASSERT(m_fastAccessCutoff <= m_storage->m_numValuesInVector); 
    845842 
     
    847844    for (unsigned i = 0; i < m_storage->m_vectorLength; ++i) { 
    848845        if (JSValue* value = m_storage->m_vector[i]) { 
    849             ASSERT(i < m_length); 
     846            ASSERT(i < m_storage->m_length); 
    850847            if (type != DestructorConsistencyCheck) 
    851848                value->type(); // Likely to crash if the object was deallocated. 
     
    863860        for (SparseArrayValueMap::iterator it = m_storage->m_sparseValueMap->begin(); it != end; ++it) { 
    864861            unsigned index = it->first; 
    865             ASSERT(index < m_length); 
     862            ASSERT(index < m_storage->m_length); 
    866863            ASSERT(index >= m_storage->m_vectorLength); 
    867864            ASSERT(index <= MAX_ARRAY_INDEX);