⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 155365 in webkit


Ignore:
Timestamp:
Sep 9, 2013, 11:21:06 AM (13 years ago)
Author:
Lucas Forschler
Message:

Merge fix for <rdar://problem/14909253>

Location:
branches/safari-534.59-branch/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-534.59-branch/Source/JavaScriptCore/ChangeLog

    r145851 r155365  
     12013-09-09  Lucas Forschler  <lforschler@apple.com>
     2
     3        Merge fix for <rdar:/problem/14909253>
     4   
     5    2013-09-09  Filip Pizlo  <fpizlo@apple.com>
     6   
     7            * runtime/ArrayPrototype.cpp:
     8            (JSC::arrayProtoFuncSort):
     9            * runtime/JSArray.cpp:
     10            (JSC::JSArray::sortNumeric):
     11            (JSC::JSArray::sort):
     12            (JSC::JSArray::compactForSorting):
     13            * runtime/JSArray.h:
     14            (JSC::JSArray::hasSparseMap):
     15
    1162013-03-14  Lucas Forschler  <lforschler@apple.com>
    217
  • branches/safari-534.59-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

    r103575 r155365  
    539539    CallType callType = getCallData(function, callData);
    540540
    541     if (thisObj->classInfo() == &JSArray::s_info) {
     541    if (thisObj->classInfo() == &JSArray::s_info && !asArray(thisObj)->hasSparseMap()) {
    542542        if (isNumericCompareFunction(exec, callType, callData))
    543543            asArray(thisObj)->sortNumeric(exec, function, callType, callData);
  • branches/safari-534.59-branch/Source/JavaScriptCore/runtime/JSArray.cpp

    r115107 r155365  
    965965
    966966    unsigned lengthNotIncludingUndefined = compactForSorting();
    967     if (storage->m_sparseValueMap) {
    968         throwOutOfMemoryError(exec);
    969         return;
    970     }
     967   
     968    ASSERT(!storage->m_sparseValueMap);
    971969
    972970    if (!lengthNotIncludingUndefined)
     
    998996
    999997    unsigned lengthNotIncludingUndefined = compactForSorting();
    1000     if (storage->m_sparseValueMap) {
    1001         throwOutOfMemoryError(exec);
    1002         return;
    1003     }
     998    ASSERT(!storage->m_sparseValueMap);
    1004999
    10051000    if (!lengthNotIncludingUndefined)
     
    11551150
    11561151    unsigned usedVectorLength = min(storage->m_length, m_vectorLength);
    1157     unsigned nodeCount = usedVectorLength + (storage->m_sparseValueMap ? storage->m_sparseValueMap->size() : 0);
     1152    unsigned nodeCount = usedVectorLength;
    11581153
    11591154    if (!nodeCount)
     
    11831178    // Iterate over the array, ignoring missing values, counting undefined ones, and inserting all other ones into the tree.
    11841179    for (; numDefined < usedVectorLength; ++numDefined) {
     1180        if (numDefined >= m_vectorLength)
     1181            break;
    11851182        JSValue v = storage->m_vector[numDefined].get();
    11861183        if (!v || v.isUndefined())
     
    11901187    }
    11911188    for (unsigned i = numDefined; i < usedVectorLength; ++i) {
     1189        if (i >= m_vectorLength)
     1190            break;
    11921191        JSValue v = storage->m_vector[i].get();
    11931192        if (v) {
     
    12041203    unsigned newUsedVectorLength = numDefined + numUndefined;
    12051204
    1206     if (SparseArrayValueMap* map = storage->m_sparseValueMap) {
    1207         newUsedVectorLength += map->size();
    1208         if (newUsedVectorLength > m_vectorLength) {
    1209             // Check that it is possible to allocate an array large enough to hold all the entries.
    1210             if ((newUsedVectorLength > MAX_STORAGE_VECTOR_LENGTH) || !increaseVectorLength(newUsedVectorLength)) {
    1211                 throwOutOfMemoryError(exec);
    1212                 return;
    1213             }
    1214         }
    1215        
    1216         storage = m_storage;
    1217 
    1218         SparseArrayValueMap::iterator end = map->end();
    1219         for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it) {
    1220             tree.abstractor().m_nodes[numDefined].value = it->second.get();
    1221             tree.insert(numDefined);
    1222             ++numDefined;
    1223         }
    1224 
    1225         delete map;
    1226         storage->m_sparseValueMap = 0;
    1227     }
    1228 
    1229     ASSERT(tree.abstractor().m_nodes.size() >= numDefined);
    1230 
    1231     // FIXME: If the compare function changed the length of the array, the following might be
    1232     // modifying the vector incorrectly.
    1233 
     1205    ASSERT(!storage->m_sparseValueMap);
     1206   
     1207    // The array size may have changed.  Figure out the new bounds.
     1208    unsigned newestUsedVectorLength = min(m_storage->m_length, m_vectorLength);
     1209   
     1210    unsigned elementsToExtractThreshold = min(min(newestUsedVectorLength, numDefined), static_cast<unsigned>(tree.abstractor().m_nodes.size()));
     1211    unsigned undefinedElementsThreshold = min(newestUsedVectorLength, newUsedVectorLength);
     1212    unsigned clearElementsThreshold = min(newestUsedVectorLength, usedVectorLength);     
     1213   
    12341214    // Copy the values back into m_storage.
    12351215    AVLTree<AVLTreeAbstractorForArrayCompare, 44>::Iterator iter;
    12361216    iter.start_iter_least(tree);
    12371217    JSGlobalData& globalData = exec->globalData();
    1238     for (unsigned i = 0; i < numDefined; ++i) {
     1218    for (unsigned i = 0; i < elementsToExtractThreshold; ++i) {
    12391219        storage->m_vector[i].set(globalData, this, tree.abstractor().m_nodes[*iter].value);
    12401220        ++iter;
     
    12421222
    12431223    // Put undefined values back in.
    1244     for (unsigned i = numDefined; i < newUsedVectorLength; ++i)
     1224    for (unsigned i = elementsToExtractThreshold; i < undefinedElementsThreshold; ++i)
    12451225        storage->m_vector[i].setUndefined();
    12461226
    12471227    // Ensure that unused values in the vector are zeroed out.
    1248     for (unsigned i = newUsedVectorLength; i < usedVectorLength; ++i)
     1228    for (unsigned i = undefinedElementsThreshold; i < clearElementsThreshold; ++i)
    12491229        storage->m_vector[i].clear();
    12501230
     
    13191299    unsigned newUsedVectorLength = numDefined + numUndefined;
    13201300
    1321     if (SparseArrayValueMap* map = storage->m_sparseValueMap) {
    1322         newUsedVectorLength += map->size();
    1323         if (newUsedVectorLength > m_vectorLength) {
    1324             // Check that it is possible to allocate an array large enough to hold all the entries - if not,
    1325             // exception is thrown by caller.
    1326             if ((newUsedVectorLength > MAX_STORAGE_VECTOR_LENGTH) || !increaseVectorLength(newUsedVectorLength))
    1327                 return 0;
    1328 
    1329             storage = m_storage;
    1330         }
    1331 
    1332         SparseArrayValueMap::iterator end = map->end();
    1333         for (SparseArrayValueMap::iterator it = map->begin(); it != end; ++it)
    1334             storage->m_vector[numDefined++].setWithoutWriteBarrier(it->second.get());
    1335 
    1336         delete map;
    1337         storage->m_sparseValueMap = 0;
    1338     }
     1301    ASSERT(!storage->m_sparseValueMap);
    13391302
    13401303    for (unsigned i = numDefined; i < newUsedVectorLength; ++i)
  • branches/safari-534.59-branch/Source/JavaScriptCore/runtime/JSArray.h

    r103575 r155365  
    174174
    175175        static void visitChildren(JSCell*, SlotVisitor&);
     176       
     177        bool hasSparseMap()
     178        {
     179            return !!m_storage->m_sparseValueMap;
     180        }
    176181
    177182    protected:
Note: See TracChangeset for help on using the changeset viewer.