| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/elements.h" | 5 #include "src/elements.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/factory.h" | 9 #include "src/factory.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 | 1446 |
| 1447 static void DeleteAtEnd(Handle<JSObject> obj, | 1447 static void DeleteAtEnd(Handle<JSObject> obj, |
| 1448 Handle<BackingStore> backing_store, uint32_t entry) { | 1448 Handle<BackingStore> backing_store, uint32_t entry) { |
| 1449 uint32_t length = static_cast<uint32_t>(backing_store->length()); | 1449 uint32_t length = static_cast<uint32_t>(backing_store->length()); |
| 1450 Heap* heap = obj->GetHeap(); | 1450 Heap* heap = obj->GetHeap(); |
| 1451 for (; entry > 0; entry--) { | 1451 for (; entry > 0; entry--) { |
| 1452 if (!backing_store->is_the_hole(entry - 1)) break; | 1452 if (!backing_store->is_the_hole(entry - 1)) break; |
| 1453 } | 1453 } |
| 1454 if (entry == 0) { | 1454 if (entry == 0) { |
| 1455 FixedArray* empty = heap->empty_fixed_array(); | 1455 FixedArray* empty = heap->empty_fixed_array(); |
| 1456 if (obj->HasFastArgumentsElements()) { | 1456 if (FastElementsAccessorSubclass::kind() == |
| 1457 FAST_SLOPPY_ARGUMENTS_ELEMENTS) { |
| 1457 FixedArray::cast(obj->elements())->set(1, empty); | 1458 FixedArray::cast(obj->elements())->set(1, empty); |
| 1458 } else { | 1459 } else { |
| 1459 obj->set_elements(empty); | 1460 obj->set_elements(empty); |
| 1460 } | 1461 } |
| 1461 return; | 1462 return; |
| 1462 } | 1463 } |
| 1463 | 1464 |
| 1464 heap->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(*backing_store, | 1465 heap->RightTrimFixedArray<Heap::CONCURRENT_TO_SWEEPER>(*backing_store, |
| 1465 length - entry); | 1466 length - entry); |
| 1466 } | 1467 } |
| (...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2561 : public SloppyArgumentsElementsAccessor< | 2562 : public SloppyArgumentsElementsAccessor< |
| 2562 FastSloppyArgumentsElementsAccessor, FastHoleyObjectElementsAccessor, | 2563 FastSloppyArgumentsElementsAccessor, FastHoleyObjectElementsAccessor, |
| 2563 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> > { | 2564 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> > { |
| 2564 public: | 2565 public: |
| 2565 explicit FastSloppyArgumentsElementsAccessor(const char* name) | 2566 explicit FastSloppyArgumentsElementsAccessor(const char* name) |
| 2566 : SloppyArgumentsElementsAccessor< | 2567 : SloppyArgumentsElementsAccessor< |
| 2567 FastSloppyArgumentsElementsAccessor, | 2568 FastSloppyArgumentsElementsAccessor, |
| 2568 FastHoleyObjectElementsAccessor, | 2569 FastHoleyObjectElementsAccessor, |
| 2569 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} | 2570 ElementsKindTraits<FAST_SLOPPY_ARGUMENTS_ELEMENTS> >(name) {} |
| 2570 | 2571 |
| 2572 static Handle<FixedArray> GetArguments(Isolate* isolate, |
| 2573 FixedArrayBase* backing_store) { |
| 2574 FixedArray* parameter_map = FixedArray::cast(backing_store); |
| 2575 return Handle<FixedArray>(FixedArray::cast(parameter_map->get(1)), isolate); |
| 2576 } |
| 2577 |
| 2578 static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, uint32_t start, |
| 2579 uint32_t end) { |
| 2580 Isolate* isolate = receiver->GetIsolate(); |
| 2581 uint32_t result_len = end < start ? 0u : end - start; |
| 2582 Handle<JSArray> result_array = isolate->factory()->NewJSArray( |
| 2583 FAST_HOLEY_ELEMENTS, result_len, result_len); |
| 2584 DisallowHeapAllocation no_gc; |
| 2585 FixedArray* elements = FixedArray::cast(result_array->elements()); |
| 2586 FixedArray* parameters = FixedArray::cast(receiver->elements()); |
| 2587 uint32_t insertion_index = 0; |
| 2588 for (uint32_t i = start; i < end; i++) { |
| 2589 uint32_t entry = |
| 2590 GetEntryForIndexImpl(*receiver, parameters, i, ALL_PROPERTIES); |
| 2591 if (entry != kMaxUInt32 && HasEntryImpl(parameters, entry)) { |
| 2592 elements->set(insertion_index, *GetImpl(parameters, entry)); |
| 2593 } else { |
| 2594 elements->set_the_hole(insertion_index); |
| 2595 } |
| 2596 insertion_index++; |
| 2597 } |
| 2598 return result_array; |
| 2599 } |
| 2600 |
| 2571 static Handle<SeededNumberDictionary> NormalizeImpl( | 2601 static Handle<SeededNumberDictionary> NormalizeImpl( |
| 2572 Handle<JSObject> object, Handle<FixedArrayBase> elements) { | 2602 Handle<JSObject> object, Handle<FixedArrayBase> elements) { |
| 2573 FixedArray* parameter_map = FixedArray::cast(*elements); | 2603 Handle<FixedArray> arguments = |
| 2574 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); | 2604 GetArguments(elements->GetIsolate(), *elements); |
| 2575 return FastHoleyObjectElementsAccessor::NormalizeImpl(object, arguments); | 2605 return FastHoleyObjectElementsAccessor::NormalizeImpl(object, arguments); |
| 2576 } | 2606 } |
| 2577 | 2607 |
| 2578 static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) { | 2608 static void DeleteFromArguments(Handle<JSObject> obj, uint32_t entry) { |
| 2579 FixedArray* parameter_map = FixedArray::cast(obj->elements()); | 2609 Handle<FixedArray> arguments = |
| 2580 Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1))); | 2610 GetArguments(obj->GetIsolate(), obj->elements()); |
| 2581 FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments); | 2611 FastHoleyObjectElementsAccessor::DeleteCommon(obj, entry, arguments); |
| 2582 } | 2612 } |
| 2583 | 2613 |
| 2584 static void AddImpl(Handle<JSObject> object, uint32_t index, | 2614 static void AddImpl(Handle<JSObject> object, uint32_t index, |
| 2585 Handle<Object> value, PropertyAttributes attributes, | 2615 Handle<Object> value, PropertyAttributes attributes, |
| 2586 uint32_t new_capacity) { | 2616 uint32_t new_capacity) { |
| 2587 DCHECK_EQ(NONE, attributes); | 2617 DCHECK_EQ(NONE, attributes); |
| 2588 Handle<FixedArray> parameter_map(FixedArray::cast(object->elements())); | 2618 Handle<FixedArray> parameter_map(FixedArray::cast(object->elements())); |
| 2589 Handle<FixedArrayBase> old_elements( | 2619 Handle<FixedArrayBase> old_elements( |
| 2590 FixedArrayBase::cast(parameter_map->get(1))); | 2620 FixedArrayBase::cast(parameter_map->get(1))); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3037 insertion_index += len; | 3067 insertion_index += len; |
| 3038 } | 3068 } |
| 3039 | 3069 |
| 3040 DCHECK_EQ(insertion_index, result_len); | 3070 DCHECK_EQ(insertion_index, result_len); |
| 3041 return result_array; | 3071 return result_array; |
| 3042 } | 3072 } |
| 3043 | 3073 |
| 3044 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 3074 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
| 3045 } // namespace internal | 3075 } // namespace internal |
| 3046 } // namespace v8 | 3076 } // namespace v8 |
| OLD | NEW |