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