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 Expression enumerable = |
| 957 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 958 PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK); |
| 959 } else { |
| 960 ParseExpression(true, CHECK_OK); |
| 961 } |
| 962 |
954 Expect(Token::RPAREN, CHECK_OK); | 963 Expect(Token::RPAREN, CHECK_OK); |
955 ParseSubStatement(CHECK_OK); | 964 ParseSubStatement(CHECK_OK); |
956 return Statement::Default(); | 965 return Statement::Default(); |
957 } | 966 } |
958 } else { | 967 } else { |
959 int lhs_beg_pos = peek_position(); | 968 int lhs_beg_pos = peek_position(); |
960 ExpressionClassifier classifier; | 969 ExpressionClassifier classifier; |
961 Expression lhs = ParseExpression(false, &classifier, CHECK_OK); | 970 Expression lhs = ParseExpression(false, &classifier, CHECK_OK); |
962 int lhs_end_pos = scanner()->location().end_pos; | 971 int lhs_end_pos = scanner()->location().end_pos; |
963 is_let_identifier_expression = | 972 is_let_identifier_expression = |
964 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); | 973 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
965 bool is_for_each = CheckInOrOf(&mode, ok); | 974 bool is_for_each = CheckInOrOf(&mode, ok); |
966 if (!*ok) return Statement::Default(); | 975 if (!*ok) return Statement::Default(); |
967 bool is_destructuring = is_for_each && | 976 bool is_destructuring = is_for_each && |
968 allow_harmony_destructuring_assignment() && | 977 allow_harmony_destructuring_assignment() && |
969 (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()); | 978 (lhs->IsArrayLiteral() || lhs->IsObjectLiteral()); |
970 | 979 |
971 if (is_destructuring) { | 980 if (is_destructuring) { |
972 ValidateAssignmentPattern(&classifier, CHECK_OK); | 981 ValidateAssignmentPattern(&classifier, CHECK_OK); |
973 } else { | 982 } else { |
974 ValidateExpression(&classifier, CHECK_OK); | 983 ValidateExpression(&classifier, CHECK_OK); |
975 } | 984 } |
976 | 985 |
977 if (is_for_each) { | 986 if (is_for_each) { |
978 if (!is_destructuring) { | 987 if (!is_destructuring) { |
979 lhs = CheckAndRewriteReferenceExpression( | 988 lhs = CheckAndRewriteReferenceExpression( |
980 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, | 989 lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor, |
981 kSyntaxError, CHECK_OK); | 990 kSyntaxError, CHECK_OK); |
982 } | 991 } |
983 ParseExpression(true, CHECK_OK); | 992 |
| 993 if (mode == ForEachStatement::ITERATE) { |
| 994 ExpressionClassifier classifier; |
| 995 Expression enumerable = |
| 996 ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 997 PreParserTraits::RewriteNonPattern(enumerable, &classifier, CHECK_OK); |
| 998 } else { |
| 999 ParseExpression(true, CHECK_OK); |
| 1000 } |
| 1001 |
984 Expect(Token::RPAREN, CHECK_OK); | 1002 Expect(Token::RPAREN, CHECK_OK); |
985 ParseSubStatement(CHECK_OK); | 1003 ParseSubStatement(CHECK_OK); |
986 return Statement::Default(); | 1004 return Statement::Default(); |
987 } | 1005 } |
988 } | 1006 } |
989 } | 1007 } |
990 | 1008 |
991 // Parsed initializer at this point. | 1009 // Parsed initializer at this point. |
992 // Detect attempts at 'let' declarations in sloppy mode. | 1010 // Detect attempts at 'let' declarations in sloppy mode. |
993 if (!allow_harmony_sloppy_let() && peek() == Token::IDENTIFIER && | 1011 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); | 1301 Expect(Token::RBRACE, CHECK_OK); |
1284 return PreParserExpression::Default(); | 1302 return PreParserExpression::Default(); |
1285 } | 1303 } |
1286 } | 1304 } |
1287 | 1305 |
1288 #undef CHECK_OK | 1306 #undef CHECK_OK |
1289 | 1307 |
1290 | 1308 |
1291 } // namespace internal | 1309 } // namespace internal |
1292 } // namespace v8 | 1310 } // namespace v8 |
OLD | NEW |