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 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 class DictionaryElementsAccessor | 1412 class DictionaryElementsAccessor |
1413 : public ElementsAccessorBase<DictionaryElementsAccessor, | 1413 : public ElementsAccessorBase<DictionaryElementsAccessor, |
1414 ElementsKindTraits<DICTIONARY_ELEMENTS> > { | 1414 ElementsKindTraits<DICTIONARY_ELEMENTS> > { |
1415 public: | 1415 public: |
1416 explicit DictionaryElementsAccessor(const char* name) | 1416 explicit DictionaryElementsAccessor(const char* name) |
1417 : ElementsAccessorBase<DictionaryElementsAccessor, | 1417 : ElementsAccessorBase<DictionaryElementsAccessor, |
1418 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} | 1418 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} |
1419 | 1419 |
1420 // Adjusts the length of the dictionary backing store and returns the new | 1420 // Adjusts the length of the dictionary backing store and returns the new |
1421 // length according to ES5 section 15.4.5.2 behavior. | 1421 // length according to ES5 section 15.4.5.2 behavior. |
1422 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( | 1422 static Handle<Object> SetLengthWithoutNormalize( |
1423 FixedArrayBase* store, | 1423 Handle<FixedArrayBase> store, |
1424 JSArray* array, | 1424 Handle<JSArray> array, |
1425 Object* length_object, | 1425 Handle<Object> length_object, |
1426 uint32_t length) { | 1426 uint32_t length) { |
1427 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); | 1427 Handle<SeededNumberDictionary> dict = |
1428 Heap* heap = array->GetHeap(); | 1428 Handle<SeededNumberDictionary>::cast(store); |
| 1429 Isolate* isolate = array->GetIsolate(); |
1429 int capacity = dict->Capacity(); | 1430 int capacity = dict->Capacity(); |
1430 uint32_t new_length = length; | 1431 uint32_t new_length = length; |
1431 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); | 1432 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); |
1432 if (new_length < old_length) { | 1433 if (new_length < old_length) { |
1433 // Find last non-deletable element in range of elements to be | 1434 // Find last non-deletable element in range of elements to be |
1434 // deleted and adjust range accordingly. | 1435 // deleted and adjust range accordingly. |
1435 for (int i = 0; i < capacity; i++) { | 1436 for (int i = 0; i < capacity; i++) { |
| 1437 DisallowHeapAllocation no_gc; |
1436 Object* key = dict->KeyAt(i); | 1438 Object* key = dict->KeyAt(i); |
1437 if (key->IsNumber()) { | 1439 if (key->IsNumber()) { |
1438 uint32_t number = static_cast<uint32_t>(key->Number()); | 1440 uint32_t number = static_cast<uint32_t>(key->Number()); |
1439 if (new_length <= number && number < old_length) { | 1441 if (new_length <= number && number < old_length) { |
1440 PropertyDetails details = dict->DetailsAt(i); | 1442 PropertyDetails details = dict->DetailsAt(i); |
1441 if (details.IsDontDelete()) new_length = number + 1; | 1443 if (details.IsDontDelete()) new_length = number + 1; |
1442 } | 1444 } |
1443 } | 1445 } |
1444 } | 1446 } |
1445 if (new_length != length) { | 1447 if (new_length != length) { |
1446 MaybeObject* maybe_object = heap->NumberFromUint32(new_length); | 1448 length_object = isolate->factory()->NewNumberFromUint(new_length); |
1447 if (!maybe_object->To(&length_object)) return maybe_object; | |
1448 } | 1449 } |
1449 } | 1450 } |
1450 | 1451 |
1451 if (new_length == 0) { | 1452 if (new_length == 0) { |
1452 // If the length of a slow array is reset to zero, we clear | 1453 // If the length of a slow array is reset to zero, we clear |
1453 // the array and flush backing storage. This has the added | 1454 // the array and flush backing storage. This has the added |
1454 // benefit that the array returns to fast mode. | 1455 // benefit that the array returns to fast mode. |
1455 Object* obj; | 1456 JSObject::ResetElements(array); |
1456 MaybeObject* maybe_obj = array->ResetElements(); | |
1457 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
1458 } else { | 1457 } else { |
| 1458 DisallowHeapAllocation no_gc; |
1459 // Remove elements that should be deleted. | 1459 // Remove elements that should be deleted. |
1460 int removed_entries = 0; | 1460 int removed_entries = 0; |
1461 Object* the_hole_value = heap->the_hole_value(); | 1461 Object* the_hole_value = isolate->heap()->the_hole_value(); |
1462 for (int i = 0; i < capacity; i++) { | 1462 for (int i = 0; i < capacity; i++) { |
1463 Object* key = dict->KeyAt(i); | 1463 Object* key = dict->KeyAt(i); |
1464 if (key->IsNumber()) { | 1464 if (key->IsNumber()) { |
1465 uint32_t number = static_cast<uint32_t>(key->Number()); | 1465 uint32_t number = static_cast<uint32_t>(key->Number()); |
1466 if (new_length <= number && number < old_length) { | 1466 if (new_length <= number && number < old_length) { |
1467 dict->SetEntry(i, the_hole_value, the_hole_value); | 1467 dict->SetEntry(i, the_hole_value, the_hole_value); |
1468 removed_entries++; | 1468 removed_entries++; |
1469 } | 1469 } |
1470 } | 1470 } |
1471 } | 1471 } |
1472 | 1472 |
1473 // Update the number of elements. | 1473 // Update the number of elements. |
1474 dict->ElementsRemoved(removed_entries); | 1474 dict->ElementsRemoved(removed_entries); |
1475 } | 1475 } |
1476 return length_object; | 1476 return length_object; |
1477 } | 1477 } |
1478 | 1478 |
1479 // TODO(ishell): Temporary wrapper until handlified. | |
1480 MUST_USE_RESULT static Handle<Object> SetLengthWithoutNormalize( | |
1481 Handle<FixedArrayBase> store, | |
1482 Handle<JSArray> array, | |
1483 Handle<Object> length_object, | |
1484 uint32_t length) { | |
1485 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
1486 SetLengthWithoutNormalize( | |
1487 *store, *array, *length_object, length), | |
1488 Object); | |
1489 } | |
1490 | |
1491 MUST_USE_RESULT static MaybeObject* DeleteCommon( | 1479 MUST_USE_RESULT static MaybeObject* DeleteCommon( |
1492 JSObject* obj, | 1480 JSObject* obj, |
1493 uint32_t key, | 1481 uint32_t key, |
1494 JSReceiver::DeleteMode mode) { | 1482 JSReceiver::DeleteMode mode) { |
1495 Isolate* isolate = obj->GetIsolate(); | 1483 Isolate* isolate = obj->GetIsolate(); |
1496 Heap* heap = isolate->heap(); | 1484 Heap* heap = isolate->heap(); |
1497 FixedArray* backing_store = FixedArray::cast(obj->elements()); | 1485 FixedArray* backing_store = FixedArray::cast(obj->elements()); |
1498 bool is_arguments = | 1486 bool is_arguments = |
1499 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); | 1487 (obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS); |
1500 if (is_arguments) { | 1488 if (is_arguments) { |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2020 UNREACHABLE(); | 2008 UNREACHABLE(); |
2021 break; | 2009 break; |
2022 } | 2010 } |
2023 | 2011 |
2024 array->set_elements(*elms); | 2012 array->set_elements(*elms); |
2025 array->set_length(Smi::FromInt(number_of_elements)); | 2013 array->set_length(Smi::FromInt(number_of_elements)); |
2026 return array; | 2014 return array; |
2027 } | 2015 } |
2028 | 2016 |
2029 } } // namespace v8::internal | 2017 } } // namespace v8::internal |
OLD | NEW |