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

Unified Diff: src/ast.cc

Issue 1125183008: [es6] Spread in array literals (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: cleanup Created 5 years, 7 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/arm64/full-codegen-arm64.cc ('k') | src/ast-numbering.cc » ('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 5038716003e80125c1ff1fd1b3709443a0a3ea63..a73c61382322b4c793dc7c399038b6766e482bfa 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -386,8 +386,10 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
bool is_simple = true;
int depth_acc = 1;
bool is_holey = false;
- for (int i = 0, n = values()->length(); i < n; i++) {
- Expression* element = values()->at(i);
+ int array_index = 0;
+ for (int n = values()->length(); array_index < n; array_index++) {
+ Expression* element = values()->at(array_index);
+ if (element->IsSpread()) break;
MaterializedLiteral* m_literal = element->AsMaterializedLiteral();
if (m_literal != NULL) {
m_literal->BuildConstants(isolate);
@@ -400,18 +402,24 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) {
is_holey = true;
} else if (boilerplate_value->IsUninitialized()) {
is_simple = false;
- JSObject::SetOwnElement(
- array, i, handle(Smi::FromInt(0), isolate), SLOPPY).Assert();
+ JSObject::SetOwnElement(array, array_index,
+ handle(Smi::FromInt(0), isolate),
+ SLOPPY).Assert();
} else {
- JSObject::SetOwnElement(array, i, boilerplate_value, SLOPPY).Assert();
+ JSObject::SetOwnElement(array, array_index, boilerplate_value, SLOPPY)
+ .Assert();
}
}
+ if (array_index != values()->length()) {
+ JSArray::SetElementsLength(
+ array, handle(Smi::FromInt(array_index), isolate)).Assert();
+ }
Handle<FixedArrayBase> element_values(array->elements());
// Simple and shallow arrays can be lazily copied, we transform the
// elements array to a copy-on-write array.
- if (is_simple && depth_acc == 1 && values()->length() > 0 &&
+ if (is_simple && depth_acc == 1 && array_index > 0 &&
array->HasFastSmiOrObjectElements()) {
element_values->set_map(isolate->heap()->fixed_cow_array_map());
}
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ast-numbering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698