OLD | NEW |
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 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 ReportMessageAt(first_initializer_loc, | 943 ReportMessageAt(first_initializer_loc, |
944 MessageTemplate::kForOfLoopInitializer); | 944 MessageTemplate::kForOfLoopInitializer); |
945 } else { | 945 } else { |
946 // TODO(caitp): This should be an error in sloppy mode, too. | 946 // TODO(caitp): This should be an error in sloppy mode, too. |
947 ReportMessageAt(first_initializer_loc, | 947 ReportMessageAt(first_initializer_loc, |
948 MessageTemplate::kForInLoopInitializer); | 948 MessageTemplate::kForInLoopInitializer); |
949 } | 949 } |
950 *ok = false; | 950 *ok = false; |
951 return Statement::Default(); | 951 return Statement::Default(); |
952 } | 952 } |
953 ParseExpression(true, CHECK_OK); | 953 |
| 954 if (mode == ForEachStatement::ITERATE) { |
| 955 ExpressionClassifier classifier; |
| 956 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 957 ValidateExpression(&classifier, CHECK_OK); |
| 958 } else { |
| 959 ParseExpression(true, CHECK_OK); |
| 960 } |
| 961 |
954 Expect(Token::RPAREN, CHECK_OK); | 962 Expect(Token::RPAREN, CHECK_OK); |
955 ParseSubStatement(CHECK_OK); | 963 ParseSubStatement(CHECK_OK); |
956 return Statement::Default(); | 964 return Statement::Default(); |
957 } | 965 } |
958 } else { | 966 } else { |
959 int lhs_beg_pos = peek_position(); | 967 int lhs_beg_pos = peek_position(); |
960 ExpressionClassifier classifier; | 968 ExpressionClassifier classifier; |
961 Expression lhs = ParseExpression(false, &classifier, CHECK_OK); | 969 Expression lhs = ParseExpression(false, &classifier, CHECK_OK); |
962 int lhs_end_pos = scanner()->location().end_pos; | 970 int lhs_end_pos = scanner()->location().end_pos; |
963 is_let_identifier_expression = | 971 is_let_identifier_expression = |
964 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); | 972 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
965 bool is_for_each = CheckInOrOf(&mode, ok); | 973 bool is_for_each = CheckInOrOf(&mode, ok); |
966 if (!*ok) return Statement::Default(); | 974 if (!*ok) return Statement::Default(); |
967 bool is_destructuring = is_for_each && | 975 bool is_destructuring = is_for_each && |
968 allow_harmony_destructuring_assignment() && | 976 allow_harmony_destructuring_assignment() && |
969 (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()); | 977 (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()); |
970 | 978 |
971 if (is_destructuring) { | 979 if (is_destructuring) { |
972 ValidateAssignmentPattern(&classifier, CHECK_OK); | 980 ValidateAssignmentPattern(&classifier, CHECK_OK); |
973 } else { | 981 } else { |
974 ValidateExpression(&classifier, CHECK_OK); | 982 ValidateExpression(&classifier, CHECK_OK); |
975 } | 983 } |
976 | 984 |
977 if (is_for_each) { | 985 if (is_for_each) { |
978 if (!is_destructuring) { | 986 if (!is_destructuring) { |
979 lhs = CheckAndRewriteReferenceExpression( | 987 lhs = CheckAndRewriteReferenceExpression( |
980 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, | 988 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, |
981 kSyntaxError, CHECK_OK); | 989 kSyntaxError, CHECK_OK); |
982 } | 990 } |
983 ParseExpression(true, CHECK_OK); | 991 |
| 992 if (mode == ForEachStatement::ITERATE) { |
| 993 ExpressionClassifier classifier; |
| 994 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 995 ValidateExpression(&classifier, CHECK_OK); |
| 996 } else { |
| 997 ParseExpression(true, CHECK_OK); |
| 998 } |
| 999 |
984 Expect(Token::RPAREN, CHECK_OK); | 1000 Expect(Token::RPAREN, CHECK_OK); |
985 ParseSubStatement(CHECK_OK); | 1001 ParseSubStatement(CHECK_OK); |
986 return Statement::Default(); | 1002 return Statement::Default(); |
987 } | 1003 } |
988 } | 1004 } |
989 } | 1005 } |
990 | 1006 |
991 // Parsed initializer at this point. | 1007 // Parsed initializer at this point. |
992 // Detect attempts at 'let' declarations in sloppy mode. | 1008 // Detect attempts at 'let' declarations in sloppy mode. |
993 if (!allow_harmony_sloppy_let() && peek() == Token::IDENTIFIER && | 1009 if (!allow_harmony_sloppy_let() && peek() == Token::IDENTIFIER && |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 Expect(Token::RBRACE, CHECK_OK); | 1299 Expect(Token::RBRACE, CHECK_OK); |
1284 return PreParserExpression::Default(); | 1300 return PreParserExpression::Default(); |
1285 } | 1301 } |
1286 } | 1302 } |
1287 | 1303 |
1288 #undef CHECK_OK | 1304 #undef CHECK_OK |
1289 | 1305 |
1290 | 1306 |
1291 } // namespace internal | 1307 } // namespace internal |
1292 } // namespace v8 | 1308 } // namespace v8 |
OLD | NEW |