Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: src/ast.cc

Issue 1225223004: Fix spread array inside array literal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add flag Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast.h ('k') | src/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index f7eab6ec710dd438fbe3d9095e90f5e00e086d85..93cb6c09b99358f6a118f58e83442ef01f58e832 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -505,9 +505,12 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) {
void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
if (!constant_elements_.is_null()) return;
+ int constants_length =
+ first_spread_index_ >= 0 ? first_spread_index_ : values()->length();
+
// 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 +518,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 +546,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());
« no previous file with comments | « src/ast.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698