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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 | 708 |
709 Expect(Token::WHILE, CHECK_OK); | 709 Expect(Token::WHILE, CHECK_OK); |
710 Expect(Token::LPAREN, CHECK_OK); | 710 Expect(Token::LPAREN, CHECK_OK); |
711 ParseExpression(true, CHECK_OK); | 711 ParseExpression(true, CHECK_OK); |
712 Expect(Token::RPAREN, CHECK_OK); | 712 Expect(Token::RPAREN, CHECK_OK); |
713 ParseSubStatement(ok); | 713 ParseSubStatement(ok); |
714 return Statement::Default(); | 714 return Statement::Default(); |
715 } | 715 } |
716 | 716 |
717 | 717 |
718 bool PreParser::CheckInOrOf(bool accept_OF) { | 718 bool PreParser::CheckInOrOf(bool accept_OF, bool* ok) { |
719 if (Check(Token::IN) || | 719 if (Check(Token::IN)) { |
720 (accept_OF && CheckContextualKeyword(CStrVector("of")))) { | 720 if (is_strong(language_mode())) { |
721 ReportMessageAt(scanner()->location(), "strong_for_in"); | |
722 *ok = false; | |
723 } | |
724 return true; | |
725 } else if (accept_OF && CheckContextualKeyword(CStrVector("of"))) { | |
721 return true; | 726 return true; |
722 } | 727 } |
723 return false; | 728 return false; |
724 } | 729 } |
725 | 730 |
726 | 731 |
727 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 732 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
728 // ForStatement :: | 733 // ForStatement :: |
729 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 734 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
730 | 735 |
731 Expect(Token::FOR, CHECK_OK); | 736 Expect(Token::FOR, CHECK_OK); |
732 Expect(Token::LPAREN, CHECK_OK); | 737 Expect(Token::LPAREN, CHECK_OK); |
733 bool is_let_identifier_expression = false; | 738 bool is_let_identifier_expression = false; |
734 if (peek() != Token::SEMICOLON) { | 739 if (peek() != Token::SEMICOLON) { |
735 if (peek() == Token::VAR || peek() == Token::CONST || | 740 if (peek() == Token::VAR || peek() == Token::CONST || |
736 (peek() == Token::LET && is_strict(language_mode()))) { | 741 (peek() == Token::LET && is_strict(language_mode()))) { |
737 bool is_lexical = peek() == Token::LET || | 742 bool is_lexical = peek() == Token::LET || |
738 (peek() == Token::CONST && is_strict(language_mode())); | 743 (peek() == Token::CONST && is_strict(language_mode())); |
739 int decl_count; | 744 int decl_count; |
740 VariableDeclarationProperties decl_props = kHasNoInitializers; | 745 VariableDeclarationProperties decl_props = kHasNoInitializers; |
741 ParseVariableDeclarations( | 746 ParseVariableDeclarations( |
742 kForStatement, &decl_props, &decl_count, CHECK_OK); | 747 kForStatement, &decl_props, &decl_count, CHECK_OK); |
743 bool has_initializers = decl_props == kHasInitializers; | 748 bool has_initializers = decl_props == kHasInitializers; |
744 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); | 749 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); |
745 bool accept_OF = !has_initializers; | 750 bool accept_OF = !has_initializers; |
746 if (accept_IN && CheckInOrOf(accept_OF)) { | 751 if (accept_IN && CheckInOrOf(accept_OF, ok)) { |
747 ParseExpression(true, CHECK_OK); | 752 if (*ok) { |
marja
2015/02/19 12:34:22
Nit: I'd write this the same style as Parser, so,
rossberg
2015/02/19 13:23:05
Done.
| |
748 Expect(Token::RPAREN, CHECK_OK); | 753 ParseExpression(true, CHECK_OK); |
749 | 754 Expect(Token::RPAREN, CHECK_OK); |
750 ParseSubStatement(CHECK_OK); | 755 ParseSubStatement(CHECK_OK); |
756 } | |
751 return Statement::Default(); | 757 return Statement::Default(); |
752 } | 758 } |
753 } else { | 759 } else { |
754 Expression lhs = ParseExpression(false, CHECK_OK); | 760 Expression lhs = ParseExpression(false, CHECK_OK); |
755 is_let_identifier_expression = | 761 is_let_identifier_expression = |
756 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); | 762 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
757 if (CheckInOrOf(lhs.IsIdentifier())) { | 763 if (CheckInOrOf(lhs.IsIdentifier(), ok)) { |
758 ParseExpression(true, CHECK_OK); | 764 if (*ok) { |
759 Expect(Token::RPAREN, CHECK_OK); | 765 ParseExpression(true, CHECK_OK); |
760 | 766 Expect(Token::RPAREN, CHECK_OK); |
761 ParseSubStatement(CHECK_OK); | 767 ParseSubStatement(CHECK_OK); |
768 } | |
762 return Statement::Default(); | 769 return Statement::Default(); |
763 } | 770 } |
764 } | 771 } |
765 } | 772 } |
766 | 773 |
767 // Parsed initializer at this point. | 774 // Parsed initializer at this point. |
768 // Detect attempts at 'let' declarations in sloppy mode. | 775 // Detect attempts at 'let' declarations in sloppy mode. |
769 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && | 776 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && |
770 is_let_identifier_expression) { | 777 is_let_identifier_expression) { |
771 ReportMessage("sloppy_lexical", NULL); | 778 ReportMessage("sloppy_lexical", NULL); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1039 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1046 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
1040 ParseArguments(ok); | 1047 ParseArguments(ok); |
1041 | 1048 |
1042 return Expression::Default(); | 1049 return Expression::Default(); |
1043 } | 1050 } |
1044 | 1051 |
1045 #undef CHECK_OK | 1052 #undef CHECK_OK |
1046 | 1053 |
1047 | 1054 |
1048 } } // v8::internal | 1055 } } // v8::internal |
OLD | NEW |