diff --git a/src/ast.cc b/src/ast.cc index 086d015362..f6cf18915b 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -357,8 +357,7 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { // Allocate a fixed array to hold all the object literals. Handle array = isolate->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS); - isolate->factory()->SetElementsCapacityAndLength( - array, values()->length(), values()->length()); + JSArray::Expand(array, values()->length()); // Fill in the literals. bool is_simple = true; diff --git a/src/elements.cc b/src/elements.cc index 7fb294e552..c8e28c5953 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -766,14 +766,16 @@ class ElementsAccessorBase : public ElementsAccessor { Handle length, Handle backing_store); - MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength( - JSArray* array, + virtual void SetCapacityAndLength( + Handle array, int capacity, int length) V8_FINAL V8_OVERRIDE { - return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( - array, - capacity, - length); + CALL_HEAP_FUNCTION_VOID( + array->GetIsolate(), + ElementsAccessorSubclass::SetFastElementsCapacityAndLength( + *array, + capacity, + length)); } MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( diff --git a/src/elements.h b/src/elements.h index bd5e7229b9..2ee07aa474 100644 --- a/src/elements.h +++ b/src/elements.h @@ -126,9 +126,10 @@ class ElementsAccessor { // 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. - MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array, - int capacity, - int length) = 0; + virtual void SetCapacityAndLength( + Handle array, + int capacity, + int length) = 0; // Deletes an element in an object, returning a new elements backing store. MUST_USE_RESULT virtual Handle Delete( diff --git a/src/factory.cc b/src/factory.cc index 5c4ac9c5d0..e292455848 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1489,16 +1489,6 @@ void Factory::NewJSArrayStorage(Handle array, } -void Factory::SetElementsCapacityAndLength(Handle array, - int capacity, - int length) { - ElementsAccessor* accessor = array->GetElementsAccessor(); - CALL_HEAP_FUNCTION_VOID( - isolate(), - accessor->SetCapacityAndLength(*array, capacity, length)); -} - - Handle Factory::NewJSGeneratorObject( Handle function) { ASSERT(function->shared()->is_generator()); diff --git a/src/factory.h b/src/factory.h index 5562ef4ec2..e57e1301d2 100644 --- a/src/factory.h +++ b/src/factory.h @@ -387,10 +387,6 @@ class Factory { int capacity, ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS); - void SetElementsCapacityAndLength(Handle array, - int capacity, - int length); - Handle NewJSGeneratorObject(Handle function); Handle NewJSArrayBuffer(); diff --git a/src/json-stringifier.h b/src/json-stringifier.h index c063b67c08..3926969f65 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -393,13 +393,16 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush( if (check.HasOverflowed()) return STACK_OVERFLOW; int length = Smi::cast(stack_->length())->value(); - FixedArray* elements = FixedArray::cast(stack_->elements()); - for (int i = 0; i < length; i++) { - if (elements->get(i) == *object) { - return CIRCULAR; + { + DisallowHeapAllocation no_allocation; + FixedArray* elements = FixedArray::cast(stack_->elements()); + for (int i = 0; i < length; i++) { + if (elements->get(i) == *object) { + return CIRCULAR; + } } } - stack_->EnsureSize(length + 1); + JSArray::EnsureSize(stack_, length + 1); FixedArray::cast(stack_->elements())->set(length, *object); stack_->set_length(Smi::FromInt(length + 1)); return SUCCESS; diff --git a/src/jsregexp.cc b/src/jsregexp.cc index 830dd7b35e..a30fc26ff0 100644 --- a/src/jsregexp.cc +++ b/src/jsregexp.cc @@ -691,7 +691,8 @@ Handle RegExpImpl::SetLastMatchInfo(Handle last_match_info, int32_t* match) { ASSERT(last_match_info->HasFastObjectElements()); int capture_register_count = (capture_count + 1) * 2; - last_match_info->EnsureSize(capture_register_count + kLastMatchOverhead); + JSArray::EnsureSize(last_match_info, + capture_register_count + kLastMatchOverhead); DisallowHeapAllocation no_allocation; FixedArray* array = FixedArray::cast(last_match_info->elements()); if (match != NULL) { diff --git a/src/objects-inl.h b/src/objects-inl.h index b3f23e65e3..e454e2ebdf 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6527,20 +6527,20 @@ void Map::ClearCodeCache(Heap* heap) { } -void JSArray::EnsureSize(int required_size) { - ASSERT(HasFastSmiOrObjectElements()); - FixedArray* elts = FixedArray::cast(elements()); +void JSArray::EnsureSize(Handle array, int required_size) { + ASSERT(array->HasFastSmiOrObjectElements()); + Handle 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(required_size + (required_size >> 3)); + Expand(array, required_size + (required_size >> 3)); // It's a performance benefit to keep a frequently used array in new-space. - } else if (!GetHeap()->new_space()->Contains(elts) && + } 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(required_size); + Expand(array, required_size); } } diff --git a/src/objects.cc b/src/objects.cc index c764b33e67..131d031dcd 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -11279,9 +11279,9 @@ void JSArray::Initialize(Handle array, int capacity, int length) { } -void JSArray::Expand(int required_size) { - GetIsolate()->factory()->SetElementsCapacityAndLength( - Handle(this), required_size, required_size); +void JSArray::Expand(Handle array, int required_size) { + ElementsAccessor* accessor = array->GetElementsAccessor(); + accessor->SetCapacityAndLength(array, required_size, required_size); } diff --git a/src/objects.h b/src/objects.h index c4d3f251c3..bb0f0f11d3 100644 --- a/src/objects.h +++ b/src/objects.h @@ -10028,9 +10028,15 @@ class JSArray: public JSObject { // Casting. static inline JSArray* cast(Object* obj); - // Uses handles. Ensures that the fixed array backing the JSArray has at + // Ensures that the fixed array backing the JSArray has at // least the stated size. - inline void EnsureSize(int minimum_size_of_backing_fixed_array); + static inline void EnsureSize(Handle 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 array, + int minimum_size_of_backing_fixed_array); // Dispatched behavior. DECLARE_PRINTER(JSArray) @@ -10044,10 +10050,6 @@ class JSArray: public JSObject { static const int kSize = kLengthOffset + kPointerSize; private: - // Expand the fixed array backing of a fast-case JSArray to at least - // the requested size. - void Expand(int minimum_size_of_backing_fixed_array); - DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); };