}
if (new_length == 0) {
- // If the length of a slow array is reset to zero, we clear
- // the array and flush backing storage. This has the added
- // benefit that the array returns to fast mode.
+ // Flush the backing store.
JSObject::ResetElements(array);
} else {
DisallowHeapAllocation no_gc;
GetHeap()->EmptyFixedTypedArrayForMap(this);
ASSERT(!GetHeap()->InNewSpace(empty_array));
return empty_array;
+ } else if (has_dictionary_elements()) {
+ ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_slow_element_dictionary()));
+ return GetHeap()->empty_slow_element_dictionary();
} else {
UNREACHABLE();
}
void JSObject::ResetElements(Handle<JSObject> object) {
- if (object->map()->is_observed()) {
- // Maintain invariant that observed elements are always in dictionary mode.
- Isolate* isolate = object->GetIsolate();
- Factory* factory = isolate->factory();
- Handle<SeededNumberDictionary> dictionary =
- SeededNumberDictionary::New(isolate, 0);
- if (object->map() == *factory->sloppy_arguments_elements_map()) {
- FixedArray::cast(object->elements())->set(1, *dictionary);
- } else {
- object->set_elements(*dictionary);
- }
- return;
- }
-
- ElementsKind elements_kind = GetInitialFastElementsKind();
- if (!FLAG_smi_only_arrays) {
- elements_kind = FastSmiToObjectElementsKind(elements_kind);
- }
- Handle<Map> map = JSObject::GetElementsTransitionMap(object, elements_kind);
- DisallowHeapAllocation no_gc;
- Handle<FixedArrayBase> elements(map->GetInitialElements());
- JSObject::SetMapAndElements(object, map, elements);
+ Heap* heap = object->GetIsolate()->heap();
+ CHECK(object->map() != heap->sloppy_arguments_elements_map());
+ object->set_elements(object->map()->GetInitialElements());
}