| Index: src/x64/full-codegen-x64.cc
|
| diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
|
| index 463fbdc0dc5e125993c1a37f99beb64366482afe..6e26e7670cfc357883b16fb55d0f6bf77b7f55db 100644
|
| --- a/src/x64/full-codegen-x64.cc
|
| +++ b/src/x64/full-codegen-x64.cc
|
| @@ -1847,8 +1847,11 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
|
|
|
| // Emit code to evaluate all the non-constant subexpressions and to store
|
| // them into the newly cloned array.
|
| - for (int i = 0; i < length; i++) {
|
| - Expression* subexpr = subexprs->at(i);
|
| + int array_index = 0;
|
| + for (; array_index < length; array_index++) {
|
| + Expression* subexpr = subexprs->at(array_index);
|
| + if (subexpr->IsSpread()) break;
|
| +
|
| // If the subexpression is a literal or a simple materialized literal it
|
| // is already set in the cloned array.
|
| if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
|
| @@ -1863,7 +1866,7 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
|
| if (has_constant_fast_elements) {
|
| // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they
|
| // cannot transition and don't need to call the runtime stub.
|
| - int offset = FixedArray::kHeaderSize + (i * kPointerSize);
|
| + int offset = FixedArray::kHeaderSize + (array_index * kPointerSize);
|
| __ movp(rbx, Operand(rsp, kPointerSize)); // Copy of array literal.
|
| __ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
|
| // Store the subexpression value in the array's elements.
|
| @@ -1875,16 +1878,41 @@ void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
|
| INLINE_SMI_CHECK);
|
| } else {
|
| // Store the subexpression value in the array's elements.
|
| - __ Move(rcx, Smi::FromInt(i));
|
| + __ Move(rcx, Smi::FromInt(array_index));
|
| StoreArrayLiteralElementStub stub(isolate());
|
| __ CallStub(&stub);
|
| }
|
|
|
| - PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS);
|
| + PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
|
| + }
|
| +
|
| + // In case the array literal contains spread expressions it has two parts. The
|
| + // first part is the "static" array which has a literal index is handled
|
| + // above. The second part is the part after the first spread expression
|
| + // (inclusive) and these elements gets appended to the array. Note that the
|
| + // number elements an iterable produces is unknown ahead of time.
|
| + if (array_index < length && result_saved) {
|
| + __ Drop(1); // literal index
|
| + __ Pop(rax);
|
| + result_saved = false;
|
| + }
|
| + for (; array_index < length; array_index++) {
|
| + Expression* subexpr = subexprs->at(array_index);
|
| +
|
| + __ Push(rax);
|
| + if (subexpr->IsSpread()) {
|
| + VisitForStackValue(subexpr->AsSpread()->expression());
|
| + __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION);
|
| + } else {
|
| + VisitForStackValue(subexpr);
|
| + __ CallRuntime(Runtime::kAppendElement, 2);
|
| + }
|
| +
|
| + PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS);
|
| }
|
|
|
| if (result_saved) {
|
| - __ addp(rsp, Immediate(kPointerSize)); // literal index
|
| + __ Drop(1); // literal index
|
| context()->PlugTOS();
|
| } else {
|
| context()->Plug(rax);
|
|
|