Index: src/ast.cc |
diff --git a/src/ast.cc b/src/ast.cc |
index f7eab6ec710dd438fbe3d9095e90f5e00e086d85..a25ceb92844e82758110c13f6d0719f68e070ef6 100644 |
--- a/src/ast.cc |
+++ b/src/ast.cc |
@@ -505,9 +505,19 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) { |
void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
if (!constant_elements_.is_null()) return; |
+ // Find the first spread; everything before that is part of |
+ // the constant elements. |
+ // TODO(adamk): Store constant length in the AST. |
+ int constants_length = values()->length(); |
+ for (int i = 0; i < values()->length(); i++) { |
+ if (values()->at(i)->IsSpread()) { |
+ constants_length = i; |
caitp (gmail)
2015/07/14 05:49:03
Looks like you just need a `break` here to make th
caitp (gmail)
2015/07/14 05:49:53
Otherwise if there are multiple spread elements, i
adamk
2015/07/14 16:04:55
Oops, indeed, I refactored this from a different a
|
+ } |
+ } |
+ |
// Allocate a fixed array to hold all the object literals. |
Handle<JSArray> array = isolate->factory()->NewJSArray( |
- FAST_HOLEY_SMI_ELEMENTS, values()->length(), values()->length(), |
+ FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length, |
Strength::WEAK, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
// Fill in the literals. |
@@ -515,9 +525,9 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
int depth_acc = 1; |
bool is_holey = false; |
int array_index = 0; |
- for (int n = values()->length(); array_index < n; array_index++) { |
+ for (; array_index < constants_length; array_index++) { |
Expression* element = values()->at(array_index); |
- if (element->IsSpread()) break; |
+ DCHECK(!element->IsSpread()); |
MaterializedLiteral* m_literal = element->AsMaterializedLiteral(); |
if (m_literal != NULL) { |
m_literal->BuildConstants(isolate); |
@@ -543,9 +553,6 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
.Assert(); |
} |
- if (array_index != values()->length()) { |
- JSArray::SetLength(array, array_index); |
- } |
JSObject::ValidateElements(array); |
Handle<FixedArrayBase> element_values(array->elements()); |