| 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 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 class DictionaryElementsAccessor | 1453 class DictionaryElementsAccessor |
| 1454 : public ElementsAccessorBase<DictionaryElementsAccessor, | 1454 : public ElementsAccessorBase<DictionaryElementsAccessor, |
| 1455 ElementsKindTraits<DICTIONARY_ELEMENTS> > { | 1455 ElementsKindTraits<DICTIONARY_ELEMENTS> > { |
| 1456 public: | 1456 public: |
| 1457 explicit DictionaryElementsAccessor(const char* name) | 1457 explicit DictionaryElementsAccessor(const char* name) |
| 1458 : ElementsAccessorBase<DictionaryElementsAccessor, | 1458 : ElementsAccessorBase<DictionaryElementsAccessor, |
| 1459 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} | 1459 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} |
| 1460 | 1460 |
| 1461 // Adjusts the length of the dictionary backing store and returns the new | 1461 // Adjusts the length of the dictionary backing store and returns the new |
| 1462 // length according to ES5 section 15.4.5.2 behavior. | 1462 // length according to ES5 section 15.4.5.2 behavior. |
| 1463 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( | 1463 MUST_USE_RESULT static Handle<Object> SetLengthWithoutNormalize( |
| 1464 FixedArrayBase* store, | 1464 Handle<FixedArrayBase> store, |
| 1465 JSArray* array, | 1465 Handle<JSArray> array, |
| 1466 Object* length_object, | 1466 Handle<Object> length_object, |
| 1467 uint32_t length) { | 1467 uint32_t length) { |
| 1468 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); | 1468 Handle<SeededNumberDictionary> dict = |
| 1469 Heap* heap = array->GetHeap(); | 1469 Handle<SeededNumberDictionary>::cast(store); |
| 1470 Isolate* isolate = array->GetIsolate(); |
| 1470 int capacity = dict->Capacity(); | 1471 int capacity = dict->Capacity(); |
| 1471 uint32_t new_length = length; | 1472 uint32_t new_length = length; |
| 1472 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); | 1473 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); |
| 1473 if (new_length < old_length) { | 1474 if (new_length < old_length) { |
| 1474 // Find last non-deletable element in range of elements to be | 1475 // Find last non-deletable element in range of elements to be |
| 1475 // deleted and adjust range accordingly. | 1476 // deleted and adjust range accordingly. |
| 1476 for (int i = 0; i < capacity; i++) { | 1477 for (int i = 0; i < capacity; i++) { |
| 1478 DisallowHeapAllocation no_gc; |
| 1477 Object* key = dict->KeyAt(i); | 1479 Object* key = dict->KeyAt(i); |
| 1478 if (key->IsNumber()) { | 1480 if (key->IsNumber()) { |
| 1479 uint32_t number = static_cast<uint32_t>(key->Number()); | 1481 uint32_t number = static_cast<uint32_t>(key->Number()); |
| 1480 if (new_length <= number && number < old_length) { | 1482 if (new_length <= number && number < old_length) { |
| 1481 PropertyDetails details = dict->DetailsAt(i); | 1483 PropertyDetails details = dict->DetailsAt(i); |
| 1482 if (details.IsDontDelete()) new_length = number + 1; | 1484 if (details.IsDontDelete()) new_length = number + 1; |
| 1483 } | 1485 } |
| 1484 } | 1486 } |
| 1485 } | 1487 } |
| 1486 if (new_length != length) { | 1488 if (new_length != length) { |
| 1487 MaybeObject* maybe_object = heap->NumberFromUint32(new_length); | 1489 isolate->factory()->NewNumberFromUint(new_length); |
| 1488 if (!maybe_object->To(&length_object)) return maybe_object; | |
| 1489 } | 1490 } |
| 1490 } | 1491 } |
| 1491 | 1492 |
| 1492 if (new_length == 0) { | 1493 if (new_length == 0) { |
| 1493 // If the length of a slow array is reset to zero, we clear | 1494 // If the length of a slow array is reset to zero, we clear |
| 1494 // the array and flush backing storage. This has the added | 1495 // the array and flush backing storage. This has the added |
| 1495 // benefit that the array returns to fast mode. | 1496 // benefit that the array returns to fast mode. |
| 1496 Object* obj; | 1497 JSObject::ResetElements(array); |
| 1497 MaybeObject* maybe_obj = array->ResetElements(); | |
| 1498 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
| 1499 } else { | 1498 } else { |
| 1499 DisallowHeapAllocation no_gc; |
| 1500 // Remove elements that should be deleted. | 1500 // Remove elements that should be deleted. |
| 1501 int removed_entries = 0; | 1501 int removed_entries = 0; |
| 1502 Object* the_hole_value = heap->the_hole_value(); | 1502 Object* the_hole_value = isolate->heap()->the_hole_value(); |
| 1503 for (int i = 0; i < capacity; i++) { | 1503 for (int i = 0; i < capacity; i++) { |
| 1504 Object* key = dict->KeyAt(i); | 1504 Object* key = dict->KeyAt(i); |
| 1505 if (key->IsNumber()) { | 1505 if (key->IsNumber()) { |
| 1506 uint32_t number = static_cast<uint32_t>(key->Number()); | 1506 uint32_t number = static_cast<uint32_t>(key->Number()); |
| 1507 if (new_length <= number && number < old_length) { | 1507 if (new_length <= number && number < old_length) { |
| 1508 dict->SetEntry(i, the_hole_value, the_hole_value); | 1508 dict->SetEntry(i, the_hole_value, the_hole_value); |
| 1509 removed_entries++; | 1509 removed_entries++; |
| 1510 } | 1510 } |
| 1511 } | 1511 } |
| 1512 } | 1512 } |
| 1513 | 1513 |
| 1514 // Update the number of elements. | 1514 // Update the number of elements. |
| 1515 dict->ElementsRemoved(removed_entries); | 1515 dict->ElementsRemoved(removed_entries); |
| 1516 } | 1516 } |
| 1517 return length_object; | 1517 return length_object; |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 // TODO(ishell): Temporary wrapper until handlified. | |
| 1521 MUST_USE_RESULT static Handle<Object> SetLengthWithoutNormalize( | |
| 1522 Handle<FixedArrayBase> store, | |
| 1523 Handle<JSArray> array, | |
| 1524 Handle<Object> length_object, | |
| 1525 uint32_t length) { | |
| 1526 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 1527 SetLengthWithoutNormalize( | |
| 1528 *store, *array, *length_object, length), | |
| 1529 Object); | |
| 1530 } | |
| 1531 | |
| 1532 MUST_USE_RESULT static MaybeObject* DeleteCommon( | 1520 MUST_USE_RESULT static MaybeObject* DeleteCommon( |
| 1533 JSObject* obj, | 1521 JSObject* obj, |
| 1534 uint32_t key, | 1522 uint32_t key, |
| 1535 JSReceiver::DeleteMode mode) { | 1523 JSReceiver::DeleteMode mode) { |
| 1536 Isolate* isolate = obj->GetIsolate(); | 1524 Isolate* isolate = obj->GetIsolate(); |
| 1537 Heap* heap = isolate->heap(); | 1525 Heap* heap = isolate->heap(); |
| 1538 FixedArray* backing_store = FixedArray::cast(obj->elements()); | 1526 FixedArray* backing_store = FixedArray::cast(obj->elements()); |
| 1539 bool is_arguments = | 1527 bool is_arguments = |
| 1540 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); | 1528 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); |
| 1541 if (is_arguments) { | 1529 if (is_arguments) { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 UNREACHABLE(); | 2053 UNREACHABLE(); |
| 2066 break; | 2054 break; |
| 2067 } | 2055 } |
| 2068 | 2056 |
| 2069 array->set_elements(*elms); | 2057 array->set_elements(*elms); |
| 2070 array->set_length(Smi::FromInt(number_of_elements)); | 2058 array->set_length(Smi::FromInt(number_of_elements)); |
| 2071 return array; | 2059 return array; |
| 2072 } | 2060 } |
| 2073 | 2061 |
| 2074 } } // namespace v8::internal | 2062 } } // namespace v8::internal |
| OLD | NEW |