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

Side by Side Diff: src/compiler/ast-graph-builder.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 unified diff | Download patch
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/ast-graph-builder.h" 5 #include "src/compiler/ast-graph-builder.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/compiler/ast-loop-assignment-analyzer.h" 8 #include "src/compiler/ast-loop-assignment-analyzer.h"
9 #include "src/compiler/control-builders.h" 9 #include "src/compiler/control-builders.h"
10 #include "src/compiler/js-type-feedback.h" 10 #include "src/compiler/js-type-feedback.h"
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 PrepareFrameState(literal, expr->CreateLiteralId(), 1920 PrepareFrameState(literal, expr->CreateLiteralId(),
1921 OutputFrameStateCombine::Push()); 1921 OutputFrameStateCombine::Push());
1922 1922
1923 // The array and the literal index are both expected on the operand stack 1923 // The array and the literal index are both expected on the operand stack
1924 // during computation of the element values. 1924 // during computation of the element values.
1925 environment()->Push(literal); 1925 environment()->Push(literal);
1926 environment()->Push(literal_index); 1926 environment()->Push(literal_index);
1927 1927
1928 // Create nodes to evaluate all the non-constant subexpressions and to store 1928 // Create nodes to evaluate all the non-constant subexpressions and to store
1929 // them into the newly cloned array. 1929 // them into the newly cloned array.
1930 for (int i = 0; i < expr->values()->length(); i++) { 1930 int array_index = 0;
1931 Expression* subexpr = expr->values()->at(i); 1931 for (; array_index < expr->values()->length(); array_index++) {
1932 Expression* subexpr = expr->values()->at(array_index);
1933 if (subexpr->IsSpread()) break;
1932 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; 1934 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue;
1933 1935
1934 VisitForValue(subexpr); 1936 VisitForValue(subexpr);
1935 { 1937 {
1936 FrameStateBeforeAndAfter states(this, subexpr->id()); 1938 FrameStateBeforeAndAfter states(this, subexpr->id());
1937 Node* value = environment()->Pop(); 1939 Node* value = environment()->Pop();
1938 Node* index = jsgraph()->Constant(i); 1940 Node* index = jsgraph()->Constant(array_index);
1939 Node* store = 1941 Node* store =
1940 BuildKeyedStore(literal, index, value, TypeFeedbackId::None()); 1942 BuildKeyedStore(literal, index, value, TypeFeedbackId::None());
1941 states.AddToNode(store, expr->GetIdForElement(i), 1943 states.AddToNode(store, expr->GetIdForElement(array_index),
1942 OutputFrameStateCombine::Ignore()); 1944 OutputFrameStateCombine::Ignore());
1943 } 1945 }
1944 } 1946 }
1945 1947
1946 environment()->Pop(); // Array literal index. 1948 // In case the array literal contains spread expressions it has two parts. The
1949 // first part is the "static" array which has a literal index is handled
1950 // above. The second part is the part after the first spread expression
1951 // (inclusive) and these elements gets appended to the array. Note that the
1952 // number elements an iterable produces is unknown ahead of time.
1953 bool has_spread = array_index < expr->values()->length();
1954 if (has_spread) {
1955 environment()->Pop(); // Array literal index.
1956 }
1957
1958 for (; array_index < expr->values()->length(); array_index++) {
1959 Expression* subexpr = expr->values()->at(array_index);
1960 Node* array = environment()->Pop();
1961 Node* result;
1962
1963 if (subexpr->IsSpread()) {
1964 VisitForValue(subexpr->AsSpread()->expression());
1965 Node* iterable = environment()->Pop();
1966 Node* builtins = BuildLoadBuiltinsObject();
1967 Node* function = BuildLoadObjectField(
1968 builtins, JSBuiltinsObject::OffsetOfFunctionWithId(
1969 Builtins::CONCAT_ITERABLE_TO_ARRAY));
1970 result = NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS,
1971 language_mode()),
1972 function, array, iterable);
1973 } else {
1974 VisitForValue(subexpr);
1975 Node* value = environment()->Pop();
1976 const Operator* op =
1977 javascript()->CallRuntime(Runtime::kAppendElement, 2);
1978 result = NewNode(op, array, value);
1979 }
1980
1981 PrepareFrameState(result, expr->GetIdForElement(array_index));
1982 environment()->Push(result);
1983 }
1984
1985 if (!has_spread) {
1986 environment()->Pop(); // Array literal index.
1987 }
1947 ast_context()->ProduceValue(environment()->Pop()); 1988 ast_context()->ProduceValue(environment()->Pop());
1948 } 1989 }
1949 1990
1950 1991
1951 void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value, 1992 void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value,
1952 BailoutId bailout_id) { 1993 BailoutId bailout_id) {
1953 DCHECK(expr->IsValidReferenceExpression()); 1994 DCHECK(expr->IsValidReferenceExpression());
1954 1995
1955 // Left-hand side can only be a property, a global or a variable slot. 1996 // Left-hand side can only be a property, a global or a variable slot.
1956 Property* property = expr->AsProperty(); 1997 Property* property = expr->AsProperty();
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after
3686 // Phi does not exist yet, introduce one. 3727 // Phi does not exist yet, introduce one.
3687 value = NewPhi(inputs, value, control); 3728 value = NewPhi(inputs, value, control);
3688 value->ReplaceInput(inputs - 1, other); 3729 value->ReplaceInput(inputs - 1, other);
3689 } 3730 }
3690 return value; 3731 return value;
3691 } 3732 }
3692 3733
3693 } // namespace compiler 3734 } // namespace compiler
3694 } // namespace internal 3735 } // namespace internal
3695 } // namespace v8 3736 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698