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

Side by Side Diff: src/parsing/preparser.cc

Issue 1517973002: [es6] support AssignmentPattern as LHS in for-in/of loops (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Centralize the error validation to a single place, to ease confusion Created 5 years 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/parsing/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 *ok = false; 949 *ok = false;
950 return Statement::Default(); 950 return Statement::Default();
951 } 951 }
952 ParseExpression(true, CHECK_OK); 952 ParseExpression(true, CHECK_OK);
953 Expect(Token::RPAREN, CHECK_OK); 953 Expect(Token::RPAREN, CHECK_OK);
954 ParseSubStatement(CHECK_OK); 954 ParseSubStatement(CHECK_OK);
955 return Statement::Default(); 955 return Statement::Default();
956 } 956 }
957 } else { 957 } else {
958 int lhs_beg_pos = peek_position(); 958 int lhs_beg_pos = peek_position();
959 Expression lhs = ParseExpression(false, CHECK_OK); 959 ExpressionClassifier classifier;
960 Expression lhs = ParseExpression(false, &classifier, CHECK_OK);
960 int lhs_end_pos = scanner()->location().end_pos; 961 int lhs_end_pos = scanner()->location().end_pos;
961 is_let_identifier_expression = 962 is_let_identifier_expression =
962 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); 963 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
963 if (CheckInOrOf(&mode, ok)) { 964 bool is_for_each = CheckInOrOf(&mode, ok);
964 if (!*ok) return Statement::Default(); 965 if (!*ok) return Statement::Default();
965 lhs = CheckAndRewriteReferenceExpression( 966 bool is_destructuring = is_for_each &&
966 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, 967 allow_harmony_destructuring_assignment() &&
967 kSyntaxError, CHECK_OK); 968 (lhs->IsArrayLiteral() || lhs->IsObjectLiteral());
969
970 if (is_destructuring) {
971 ValidateAssignmentPattern(&classifier, CHECK_OK);
972 } else {
973 ValidateExpression(&classifier, CHECK_OK);
974 }
975
976 if (is_for_each) {
977 if (!is_destructuring) {
978 lhs = CheckAndRewriteReferenceExpression(
979 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
980 kSyntaxError, CHECK_OK);
981 }
968 ParseExpression(true, CHECK_OK); 982 ParseExpression(true, CHECK_OK);
969 Expect(Token::RPAREN, CHECK_OK); 983 Expect(Token::RPAREN, CHECK_OK);
970 ParseSubStatement(CHECK_OK); 984 ParseSubStatement(CHECK_OK);
971 return Statement::Default(); 985 return Statement::Default();
972 } 986 }
973 } 987 }
974 } 988 }
975 989
976 // Parsed initializer at this point. 990 // Parsed initializer at this point.
977 // Detect attempts at 'let' declarations in sloppy mode. 991 // Detect attempts at 'let' declarations in sloppy mode.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 Expect(Token::RBRACE, CHECK_OK); 1281 Expect(Token::RBRACE, CHECK_OK);
1268 return PreParserExpression::Default(); 1282 return PreParserExpression::Default();
1269 } 1283 }
1270 } 1284 }
1271 1285
1272 #undef CHECK_OK 1286 #undef CHECK_OK
1273 1287
1274 1288
1275 } // namespace internal 1289 } // namespace internal
1276 } // namespace v8 1290 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/pattern-rewriter.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698