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

Side by Side Diff: src/preparser.cc

Issue 939063002: [strong] Deprecate for-in (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 5 years, 10 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/preparser.h ('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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
719 if (Check(Token::IN) ||
720 (accept_OF && CheckContextualKeyword(CStrVector("of")))) {
721 return true;
722 }
723 return false;
724 }
725
726
727 PreParser::Statement PreParser::ParseForStatement(bool* ok) { 718 PreParser::Statement PreParser::ParseForStatement(bool* ok) {
728 // ForStatement :: 719 // ForStatement ::
729 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 720 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
730 721
731 Expect(Token::FOR, CHECK_OK); 722 Expect(Token::FOR, CHECK_OK);
732 Expect(Token::LPAREN, CHECK_OK); 723 Expect(Token::LPAREN, CHECK_OK);
733 bool is_let_identifier_expression = false; 724 bool is_let_identifier_expression = false;
734 if (peek() != Token::SEMICOLON) { 725 if (peek() != Token::SEMICOLON) {
726 ForEachStatement::VisitMode visit_mode;
735 if (peek() == Token::VAR || peek() == Token::CONST || 727 if (peek() == Token::VAR || peek() == Token::CONST ||
736 (peek() == Token::LET && is_strict(language_mode()))) { 728 (peek() == Token::LET && is_strict(language_mode()))) {
737 bool is_lexical = peek() == Token::LET || 729 bool is_lexical = peek() == Token::LET ||
738 (peek() == Token::CONST && is_strict(language_mode())); 730 (peek() == Token::CONST && is_strict(language_mode()));
739 int decl_count; 731 int decl_count;
740 VariableDeclarationProperties decl_props = kHasNoInitializers; 732 VariableDeclarationProperties decl_props = kHasNoInitializers;
741 ParseVariableDeclarations( 733 ParseVariableDeclarations(
742 kForStatement, &decl_props, &decl_count, CHECK_OK); 734 kForStatement, &decl_props, &decl_count, CHECK_OK);
743 bool has_initializers = decl_props == kHasInitializers; 735 bool has_initializers = decl_props == kHasInitializers;
744 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); 736 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers);
745 bool accept_OF = !has_initializers; 737 bool accept_OF = !has_initializers;
746 if (accept_IN && CheckInOrOf(accept_OF)) { 738 if (accept_IN && CheckInOrOf(accept_OF, &visit_mode, ok)) {
739 if (!*ok) return Statement::Default();
747 ParseExpression(true, CHECK_OK); 740 ParseExpression(true, CHECK_OK);
748 Expect(Token::RPAREN, CHECK_OK); 741 Expect(Token::RPAREN, CHECK_OK);
749
750 ParseSubStatement(CHECK_OK); 742 ParseSubStatement(CHECK_OK);
751 return Statement::Default(); 743 return Statement::Default();
752 } 744 }
753 } else { 745 } else {
754 Expression lhs = ParseExpression(false, CHECK_OK); 746 Expression lhs = ParseExpression(false, CHECK_OK);
755 is_let_identifier_expression = 747 is_let_identifier_expression =
756 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); 748 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
757 if (CheckInOrOf(lhs.IsIdentifier())) { 749 if (CheckInOrOf(lhs.IsIdentifier(), &visit_mode, ok)) {
750 if (!*ok) return Statement::Default();
758 ParseExpression(true, CHECK_OK); 751 ParseExpression(true, CHECK_OK);
759 Expect(Token::RPAREN, CHECK_OK); 752 Expect(Token::RPAREN, CHECK_OK);
760
761 ParseSubStatement(CHECK_OK); 753 ParseSubStatement(CHECK_OK);
762 return Statement::Default(); 754 return Statement::Default();
763 } 755 }
764 } 756 }
765 } 757 }
766 758
767 // Parsed initializer at this point. 759 // Parsed initializer at this point.
768 // Detect attempts at 'let' declarations in sloppy mode. 760 // Detect attempts at 'let' declarations in sloppy mode.
769 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) && 761 if (peek() == Token::IDENTIFIER && is_sloppy(language_mode()) &&
770 is_let_identifier_expression) { 762 is_let_identifier_expression) {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1031 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1040 ParseArguments(ok); 1032 ParseArguments(ok);
1041 1033
1042 return Expression::Default(); 1034 return Expression::Default();
1043 } 1035 }
1044 1036
1045 #undef CHECK_OK 1037 #undef CHECK_OK
1046 1038
1047 1039
1048 } } // v8::internal 1040 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698