| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 DCHECK(!expr.AsIdentifier().IsFutureReserved()); | 502 DCHECK(!expr.AsIdentifier().IsFutureReserved()); |
| 503 DCHECK(strict_mode() == SLOPPY || | 503 DCHECK(strict_mode() == SLOPPY || |
| 504 !IsFutureStrictReserved(expr.AsIdentifier())); | 504 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 505 Consume(Token::COLON); | 505 Consume(Token::COLON); |
| 506 return ParseStatement(ok); | 506 return ParseStatement(ok); |
| 507 // Preparsing is disabled for extensions (because the extension details | 507 // Preparsing is disabled for extensions (because the extension details |
| 508 // aren't passed to lazily compiled functions), so we don't | 508 // aren't passed to lazily compiled functions), so we don't |
| 509 // accept "native function" in the preparser. | 509 // accept "native function" in the preparser. |
| 510 } | 510 } |
| 511 // Parsed expression statement. | 511 // Parsed expression statement. |
| 512 // Detect attempts at 'let' declarations in sloppy mode. |
| 513 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY && |
| 514 expr.IsIdentifier() && expr.AsIdentifier().IsLet()) { |
| 515 ReportMessage("lexical_strict_mode", NULL); |
| 516 *ok = false; |
| 517 return Statement::Default(); |
| 518 } |
| 512 ExpectSemicolon(CHECK_OK); | 519 ExpectSemicolon(CHECK_OK); |
| 513 return Statement::ExpressionStatement(expr); | 520 return Statement::ExpressionStatement(expr); |
| 514 } | 521 } |
| 515 | 522 |
| 516 | 523 |
| 517 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { | 524 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { |
| 518 // IfStatement :: | 525 // IfStatement :: |
| 519 // 'if' '(' Expression ')' Statement ('else' Statement)? | 526 // 'if' '(' Expression ')' Statement ('else' Statement)? |
| 520 | 527 |
| 521 Expect(Token::IF, CHECK_OK); | 528 Expect(Token::IF, CHECK_OK); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 return false; | 688 return false; |
| 682 } | 689 } |
| 683 | 690 |
| 684 | 691 |
| 685 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 692 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
| 686 // ForStatement :: | 693 // ForStatement :: |
| 687 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 694 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
| 688 | 695 |
| 689 Expect(Token::FOR, CHECK_OK); | 696 Expect(Token::FOR, CHECK_OK); |
| 690 Expect(Token::LPAREN, CHECK_OK); | 697 Expect(Token::LPAREN, CHECK_OK); |
| 698 bool is_let_identifier_expression = false; |
| 691 if (peek() != Token::SEMICOLON) { | 699 if (peek() != Token::SEMICOLON) { |
| 692 if (peek() == Token::VAR || peek() == Token::CONST || | 700 if (peek() == Token::VAR || peek() == Token::CONST || |
| 693 (peek() == Token::LET && strict_mode() == STRICT)) { | 701 (peek() == Token::LET && strict_mode() == STRICT)) { |
| 694 bool is_lexical = peek() == Token::LET || | 702 bool is_lexical = peek() == Token::LET || |
| 695 (peek() == Token::CONST && strict_mode() == STRICT); | 703 (peek() == Token::CONST && strict_mode() == STRICT); |
| 696 int decl_count; | 704 int decl_count; |
| 697 VariableDeclarationProperties decl_props = kHasNoInitializers; | 705 VariableDeclarationProperties decl_props = kHasNoInitializers; |
| 698 ParseVariableDeclarations( | 706 ParseVariableDeclarations( |
| 699 kForStatement, &decl_props, &decl_count, CHECK_OK); | 707 kForStatement, &decl_props, &decl_count, CHECK_OK); |
| 700 bool has_initializers = decl_props == kHasInitializers; | 708 bool has_initializers = decl_props == kHasInitializers; |
| 701 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); | 709 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); |
| 702 bool accept_OF = !has_initializers; | 710 bool accept_OF = !has_initializers; |
| 703 if (accept_IN && CheckInOrOf(accept_OF)) { | 711 if (accept_IN && CheckInOrOf(accept_OF)) { |
| 704 ParseExpression(true, CHECK_OK); | 712 ParseExpression(true, CHECK_OK); |
| 705 Expect(Token::RPAREN, CHECK_OK); | 713 Expect(Token::RPAREN, CHECK_OK); |
| 706 | 714 |
| 707 ParseStatement(CHECK_OK); | 715 ParseStatement(CHECK_OK); |
| 708 return Statement::Default(); | 716 return Statement::Default(); |
| 709 } | 717 } |
| 710 } else { | 718 } else { |
| 711 Expression lhs = ParseExpression(false, CHECK_OK); | 719 Expression lhs = ParseExpression(false, CHECK_OK); |
| 720 is_let_identifier_expression = |
| 721 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet(); |
| 712 if (CheckInOrOf(lhs.IsIdentifier())) { | 722 if (CheckInOrOf(lhs.IsIdentifier())) { |
| 713 ParseExpression(true, CHECK_OK); | 723 ParseExpression(true, CHECK_OK); |
| 714 Expect(Token::RPAREN, CHECK_OK); | 724 Expect(Token::RPAREN, CHECK_OK); |
| 715 | 725 |
| 716 ParseStatement(CHECK_OK); | 726 ParseStatement(CHECK_OK); |
| 717 return Statement::Default(); | 727 return Statement::Default(); |
| 718 } | 728 } |
| 719 } | 729 } |
| 720 } | 730 } |
| 721 | 731 |
| 722 // Parsed initializer at this point. | 732 // Parsed initializer at this point. |
| 733 // Detect attempts at 'let' declarations in sloppy mode. |
| 734 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY && |
| 735 is_let_identifier_expression) { |
| 736 ReportMessage("lexical_strict_mode", NULL); |
| 737 *ok = false; |
| 738 return Statement::Default(); |
| 739 } |
| 723 Expect(Token::SEMICOLON, CHECK_OK); | 740 Expect(Token::SEMICOLON, CHECK_OK); |
| 724 | 741 |
| 725 if (peek() != Token::SEMICOLON) { | 742 if (peek() != Token::SEMICOLON) { |
| 726 ParseExpression(true, CHECK_OK); | 743 ParseExpression(true, CHECK_OK); |
| 727 } | 744 } |
| 728 Expect(Token::SEMICOLON, CHECK_OK); | 745 Expect(Token::SEMICOLON, CHECK_OK); |
| 729 | 746 |
| 730 if (peek() != Token::RPAREN) { | 747 if (peek() != Token::RPAREN) { |
| 731 ParseExpression(true, CHECK_OK); | 748 ParseExpression(true, CHECK_OK); |
| 732 } | 749 } |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); | 1006 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); |
| 990 ParseArguments(ok); | 1007 ParseArguments(ok); |
| 991 | 1008 |
| 992 return Expression::Default(); | 1009 return Expression::Default(); |
| 993 } | 1010 } |
| 994 | 1011 |
| 995 #undef CHECK_OK | 1012 #undef CHECK_OK |
| 996 | 1013 |
| 997 | 1014 |
| 998 } } // v8::internal | 1015 } } // v8::internal |
| OLD | NEW |