| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 : ElementsAccessorBase<DictionaryElementsAccessor, | 1261 : ElementsAccessorBase<DictionaryElementsAccessor, |
| 1262 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} | 1262 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} |
| 1263 | 1263 |
| 1264 // Adjusts the length of the dictionary backing store and returns the new | 1264 // Adjusts the length of the dictionary backing store and returns the new |
| 1265 // length according to ES5 section 15.4.5.2 behavior. | 1265 // length according to ES5 section 15.4.5.2 behavior. |
| 1266 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( | 1266 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( |
| 1267 SeededNumberDictionary* dict, | 1267 SeededNumberDictionary* dict, |
| 1268 JSArray* array, | 1268 JSArray* array, |
| 1269 Object* length_object, | 1269 Object* length_object, |
| 1270 uint32_t length) { | 1270 uint32_t length) { |
| 1271 Heap* heap = array->GetHeap(); | 1271 if (length == 0) { |
| 1272 int capacity = dict->Capacity(); | |
| 1273 uint32_t new_length = length; | |
| 1274 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); | |
| 1275 if (new_length < old_length) { | |
| 1276 // Find last non-deletable element in range of elements to be | |
| 1277 // deleted and adjust range accordingly. | |
| 1278 for (int i = 0; i < capacity; i++) { | |
| 1279 Object* key = dict->KeyAt(i); | |
| 1280 if (key->IsNumber()) { | |
| 1281 uint32_t number = static_cast<uint32_t>(key->Number()); | |
| 1282 if (new_length <= number && number < old_length) { | |
| 1283 PropertyDetails details = dict->DetailsAt(i); | |
| 1284 if (details.IsDontDelete()) new_length = number + 1; | |
| 1285 } | |
| 1286 } | |
| 1287 } | |
| 1288 if (new_length != length) { | |
| 1289 MaybeObject* maybe_object = heap->NumberFromUint32(new_length); | |
| 1290 if (!maybe_object->To(&length_object)) return maybe_object; | |
| 1291 } | |
| 1292 } | |
| 1293 | |
| 1294 if (new_length == 0) { | |
| 1295 // If the length of a slow array is reset to zero, we clear | 1272 // If the length of a slow array is reset to zero, we clear |
| 1296 // the array and flush backing storage. This has the added | 1273 // the array and flush backing storage. This has the added |
| 1297 // benefit that the array returns to fast mode. | 1274 // benefit that the array returns to fast mode. |
| 1298 Object* obj; | 1275 Object* obj; |
| 1299 MaybeObject* maybe_obj = array->ResetElements(); | 1276 MaybeObject* maybe_obj = array->ResetElements(); |
| 1300 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1277 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 1301 } else { | 1278 } else { |
| 1302 // Remove elements that should be deleted. | 1279 uint32_t new_length = length; |
| 1303 int removed_entries = 0; | 1280 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); |
| 1304 Object* the_hole_value = heap->the_hole_value(); | 1281 if (new_length < old_length) { |
| 1305 for (int i = 0; i < capacity; i++) { | 1282 // Find last non-deletable element in range of elements to be |
| 1306 Object* key = dict->KeyAt(i); | 1283 // deleted and adjust range accordingly. |
| 1307 if (key->IsNumber()) { | 1284 Heap* heap = array->GetHeap(); |
| 1308 uint32_t number = static_cast<uint32_t>(key->Number()); | 1285 int capacity = dict->Capacity(); |
| 1309 if (new_length <= number && number < old_length) { | 1286 for (int i = 0; i < capacity; i++) { |
| 1310 dict->SetEntry(i, the_hole_value, the_hole_value); | 1287 Object* key = dict->KeyAt(i); |
| 1311 removed_entries++; | 1288 if (key->IsNumber()) { |
| 1289 uint32_t number = static_cast<uint32_t>(key->Number()); |
| 1290 if (new_length <= number && number < old_length) { |
| 1291 PropertyDetails details = dict->DetailsAt(i); |
| 1292 if (details.IsDontDelete()) new_length = number + 1; |
| 1293 } |
| 1312 } | 1294 } |
| 1313 } | 1295 } |
| 1296 if (new_length != length) { |
| 1297 MaybeObject* maybe_object = heap->NumberFromUint32(new_length); |
| 1298 if (!maybe_object->To(&length_object)) return maybe_object; |
| 1299 } |
| 1300 |
| 1301 // Remove elements that should be deleted. |
| 1302 int removed_entries = 0; |
| 1303 Object* the_hole_value = heap->the_hole_value(); |
| 1304 for (int i = 0; i < capacity; i++) { |
| 1305 Object* key = dict->KeyAt(i); |
| 1306 if (key->IsNumber()) { |
| 1307 uint32_t number = static_cast<uint32_t>(key->Number()); |
| 1308 if (new_length <= number && number < old_length) { |
| 1309 dict->SetEntry(i, the_hole_value, the_hole_value); |
| 1310 removed_entries++; |
| 1311 } |
| 1312 } |
| 1313 } |
| 1314 |
| 1315 // Update the number of elements. |
| 1316 dict->ElementsRemoved(removed_entries); |
| 1314 } | 1317 } |
| 1315 | |
| 1316 // Update the number of elements. | |
| 1317 dict->ElementsRemoved(removed_entries); | |
| 1318 } | 1318 } |
| 1319 return length_object; | 1319 return length_object; |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 MUST_USE_RESULT static MaybeObject* DeleteCommon( | 1322 MUST_USE_RESULT static MaybeObject* DeleteCommon( |
| 1323 JSObject* obj, | 1323 JSObject* obj, |
| 1324 uint32_t key, | 1324 uint32_t key, |
| 1325 JSReceiver::DeleteMode mode) { | 1325 JSReceiver::DeleteMode mode) { |
| 1326 Isolate* isolate = obj->GetIsolate(); | 1326 Isolate* isolate = obj->GetIsolate(); |
| 1327 Heap* heap = isolate->heap(); | 1327 Heap* heap = isolate->heap(); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 1681 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
| 1682 new_backing_store->set(0, length); | 1682 new_backing_store->set(0, length); |
| 1683 { MaybeObject* result = array->SetContent(new_backing_store); | 1683 { MaybeObject* result = array->SetContent(new_backing_store); |
| 1684 if (result->IsFailure()) return result; | 1684 if (result->IsFailure()) return result; |
| 1685 } | 1685 } |
| 1686 return array; | 1686 return array; |
| 1687 } | 1687 } |
| 1688 | 1688 |
| 1689 | 1689 |
| 1690 } } // namespace v8::internal | 1690 } } // namespace v8::internal |
| OLD | NEW |