Changeset 155365 in webkit
- Timestamp:
- Sep 9, 2013, 11:21:06 AM (13 years ago)
- Location:
- branches/safari-534.59-branch/Source/JavaScriptCore
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
runtime/ArrayPrototype.cpp (modified) (1 diff)
-
runtime/JSArray.cpp (modified) (8 diffs)
-
runtime/JSArray.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/safari-534.59-branch/Source/JavaScriptCore/ChangeLog
r145851 r155365 1 2013-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 1 16 2013-03-14 Lucas Forschler <lforschler@apple.com> 2 17 -
branches/safari-534.59-branch/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r103575 r155365 539 539 CallType callType = getCallData(function, callData); 540 540 541 if (thisObj->classInfo() == &JSArray::s_info ) {541 if (thisObj->classInfo() == &JSArray::s_info && !asArray(thisObj)->hasSparseMap()) { 542 542 if (isNumericCompareFunction(exec, callType, callData)) 543 543 asArray(thisObj)->sortNumeric(exec, function, callType, callData); -
branches/safari-534.59-branch/Source/JavaScriptCore/runtime/JSArray.cpp
r115107 r155365 965 965 966 966 unsigned lengthNotIncludingUndefined = compactForSorting(); 967 if (storage->m_sparseValueMap) { 968 throwOutOfMemoryError(exec); 969 return; 970 } 967 968 ASSERT(!storage->m_sparseValueMap); 971 969 972 970 if (!lengthNotIncludingUndefined) … … 998 996 999 997 unsigned lengthNotIncludingUndefined = compactForSorting(); 1000 if (storage->m_sparseValueMap) { 1001 throwOutOfMemoryError(exec); 1002 return; 1003 } 998 ASSERT(!storage->m_sparseValueMap); 1004 999 1005 1000 if (!lengthNotIncludingUndefined) … … 1155 1150 1156 1151 unsigned usedVectorLength = min(storage->m_length, m_vectorLength); 1157 unsigned nodeCount = usedVectorLength + (storage->m_sparseValueMap ? storage->m_sparseValueMap->size() : 0);1152 unsigned nodeCount = usedVectorLength; 1158 1153 1159 1154 if (!nodeCount) … … 1183 1178 // Iterate over the array, ignoring missing values, counting undefined ones, and inserting all other ones into the tree. 1184 1179 for (; numDefined < usedVectorLength; ++numDefined) { 1180 if (numDefined >= m_vectorLength) 1181 break; 1185 1182 JSValue v = storage->m_vector[numDefined].get(); 1186 1183 if (!v || v.isUndefined()) … … 1190 1187 } 1191 1188 for (unsigned i = numDefined; i < usedVectorLength; ++i) { 1189 if (i >= m_vectorLength) 1190 break; 1192 1191 JSValue v = storage->m_vector[i].get(); 1193 1192 if (v) { … … 1204 1203 unsigned newUsedVectorLength = numDefined + numUndefined; 1205 1204 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 1234 1214 // Copy the values back into m_storage. 1235 1215 AVLTree<AVLTreeAbstractorForArrayCompare, 44>::Iterator iter; 1236 1216 iter.start_iter_least(tree); 1237 1217 JSGlobalData& globalData = exec->globalData(); 1238 for (unsigned i = 0; i < numDefined; ++i) {1218 for (unsigned i = 0; i < elementsToExtractThreshold; ++i) { 1239 1219 storage->m_vector[i].set(globalData, this, tree.abstractor().m_nodes[*iter].value); 1240 1220 ++iter; … … 1242 1222 1243 1223 // Put undefined values back in. 1244 for (unsigned i = numDefined; i < newUsedVectorLength; ++i)1224 for (unsigned i = elementsToExtractThreshold; i < undefinedElementsThreshold; ++i) 1245 1225 storage->m_vector[i].setUndefined(); 1246 1226 1247 1227 // 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) 1249 1229 storage->m_vector[i].clear(); 1250 1230 … … 1319 1299 unsigned newUsedVectorLength = numDefined + numUndefined; 1320 1300 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); 1339 1302 1340 1303 for (unsigned i = numDefined; i < newUsedVectorLength; ++i) -
branches/safari-534.59-branch/Source/JavaScriptCore/runtime/JSArray.h
r103575 r155365 174 174 175 175 static void visitChildren(JSCell*, SlotVisitor&); 176 177 bool hasSparseMap() 178 { 179 return !!m_storage->m_sparseValueMap; 180 } 176 181 177 182 protected:
Note:
See TracChangeset
for help on using the changeset viewer.