if (!constant_elements_.is_null()) return;
// Allocate a fixed array to hold all the object literals.
- Handle<JSArray> array =
- isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
- JSArray::Expand(array, values()->length());
+ Handle<JSArray> array = isolate->factory()->NewJSArray(
+ FAST_HOLEY_SMI_ELEMENTS, values()->length(), values()->length(),
+ Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
// Fill in the literals.
bool is_simple = true;
static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
Handle<FixedArrayBase> backing_store);
- virtual void SetCapacityAndLength(Handle<JSArray> array, int capacity,
- int length) final {
- ElementsAccessorSubclass::
- SetFastElementsCapacityAndLength(array, capacity, length);
- }
-
- static void SetFastElementsCapacityAndLength(
- Handle<JSObject> obj,
- int capacity,
- int length) {
+ static void GrowCapacityAndConvert(Handle<JSObject> obj, int capacity) {
UNIMPLEMENTED();
}
break;
case SLOPPY_ARGUMENTS_ELEMENTS: {
// TODO(verwaest): This is a temporary hack to support extending
- // SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength.
+ // SLOPPY_ARGUMENTS_ELEMENTS in GrowCapacityAndConvert.
// This case should be UNREACHABLE().
FixedArray* parameter_map = FixedArray::cast(from);
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
}
- static void SetFastElementsCapacityAndLength(
- Handle<JSObject> obj,
- uint32_t capacity,
- uint32_t length) {
+ static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) {
JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
obj->HasFastSmiElements()
? JSObject::kAllowSmiElements
: JSObject::kDontAllowSmiElements;
- JSObject::SetFastElementsCapacityAndLength(
- obj, capacity, length, set_capacity_mode);
+ JSObject::SetFastElementsCapacity(obj, capacity, set_capacity_mode);
}
};
: FastElementsAccessor<FastElementsAccessorSubclass,
KindTraits>(name) {}
- static void SetFastElementsCapacityAndLength(Handle<JSObject> obj,
- uint32_t capacity,
- uint32_t length) {
- JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length);
+ static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) {
+ JSObject::SetFastDoubleElementsCapacity(obj, capacity);
}
protected:
} else {
// Check whether the backing store should be expanded.
capacity = Max(length, JSObject::NewElementsCapacity(capacity));
- ElementsAccessorSubclass::SetFastElementsCapacityAndLength(array, capacity,
- length);
+ ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity);
}
array->set_length(Smi::FromInt(length));
// element that is non-deletable.
virtual void SetLength(Handle<JSArray> holder, uint32_t new_length) = 0;
- // Modifies both the length and capacity of a JSArray, resizing the underlying
- // backing store as necessary. This method does NOT honor the semantics of
- // EcmaScript 5.1 15.4.5.2, arrays can be shrunk beyond non-deletable
- // elements. This method should only be called for array expansion OR by
- // runtime JavaScript code that use InternalArrays and don't care about
- // EcmaScript 5.1 semantics.
- virtual void SetCapacityAndLength(
- Handle<JSArray> array,
- int capacity,
- int length) = 0;
-
// Deletes an element in an object.
virtual void Delete(Handle<JSObject> holder, uint32_t key,
LanguageMode language_mode) = 0;
}
}
}
- JSArray::EnsureSize(stack_, length + 1);
+ JSArray::SetLength(stack_, length + 1);
FixedArray::cast(stack_->elements())->set(length, *object);
- stack_->set_length(Smi::FromInt(length + 1));
return SUCCESS;
}
int32_t* match) {
DCHECK(last_match_info->HasFastObjectElements());
int capture_register_count = (capture_count + 1) * 2;
- JSArray::EnsureSize(last_match_info,
- capture_register_count + kLastMatchOverhead);
+ JSArray::SetLength(last_match_info,
+ capture_register_count + kLastMatchOverhead);
DisallowHeapAllocation no_allocation;
FixedArray* array = FixedArray::cast(last_match_info->elements());
if (match != NULL) {
}
-void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
- DCHECK(array->HasFastSmiOrObjectElements());
- Handle<FixedArray> elts = handle(FixedArray::cast(array->elements()));
- const int kArraySizeThatFitsComfortablyInNewSpace = 128;
- if (elts->length() < required_size) {
- // Doubling in size would be overkill, but leave some slack to avoid
- // constantly growing.
- Expand(array, required_size + (required_size >> 3));
- // It's a performance benefit to keep a frequently used array in new-space.
- } else if (!array->GetHeap()->new_space()->Contains(*elts) &&
- required_size < kArraySizeThatFitsComfortablyInNewSpace) {
- // Expand will allocate a new backing store in new space even if the size
- // we asked for isn't larger than what we had before.
- Expand(array, required_size);
- }
-}
-
-
void JSArray::set_length(Smi* length) {
// Don't need a write barrier for a Smi.
set_length(static_cast<Object*>(length), SKIP_WRITE_BARRIER);
}
-void JSArray::Expand(Handle<JSArray> array, int required_size) {
- ElementsAccessor* accessor = array->GetElementsAccessor();
- accessor->SetCapacityAndLength(array, required_size, required_size);
-}
-
-
// Returns false if the passed-in index is marked non-configurable, which will
// cause the truncation operation to halt, and thus no further old values need
// be collected.
DECLARE_CAST(JSArray)
- // Ensures that the fixed array backing the JSArray has at
- // least the stated size.
- static inline void EnsureSize(Handle<JSArray> array,
- int minimum_size_of_backing_fixed_array);
-
- // Expand the fixed array backing of a fast-case JSArray to at least
- // the requested size.
- static void Expand(Handle<JSArray> array,
- int minimum_size_of_backing_fixed_array);
-
// Dispatched behavior.
DECLARE_PRINTER(JSArray)
DECLARE_VERIFIER(JSArray)