| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 case Token::FUNCTION: | 190 case Token::FUNCTION: |
| 191 return ParseFunctionDeclaration(ok); | 191 return ParseFunctionDeclaration(ok); |
| 192 case Token::CLASS: | 192 case Token::CLASS: |
| 193 return ParseClassDeclaration(ok); | 193 return ParseClassDeclaration(ok); |
| 194 case Token::CONST: | 194 case Token::CONST: |
| 195 if (allow_const()) { | 195 if (allow_const()) { |
| 196 return ParseVariableStatement(kStatementListItem, ok); | 196 return ParseVariableStatement(kStatementListItem, ok); |
| 197 } | 197 } |
| 198 break; | 198 break; |
| 199 case Token::LET: | 199 case Token::LET: |
| 200 if (is_strict(language_mode())) { | 200 if (allow_let()) { |
| 201 return ParseVariableStatement(kStatementListItem, ok); | 201 return ParseVariableStatement(kStatementListItem, ok); |
| 202 } | 202 } |
| 203 break; | 203 break; |
| 204 default: | 204 default: |
| 205 break; | 205 break; |
| 206 } | 206 } |
| 207 return ParseStatement(ok); | 207 return ParseStatement(ok); |
| 208 } | 208 } |
| 209 | 209 |
| 210 | 210 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 449 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
| 450 // Block :: | 450 // Block :: |
| 451 // '{' Statement* '}' | 451 // '{' Statement* '}' |
| 452 | 452 |
| 453 // Note that a Block does not introduce a new execution scope! | 453 // Note that a Block does not introduce a new execution scope! |
| 454 // (ECMA-262, 3rd, 12.2) | 454 // (ECMA-262, 3rd, 12.2) |
| 455 // | 455 // |
| 456 Expect(Token::LBRACE, CHECK_OK); | 456 Expect(Token::LBRACE, CHECK_OK); |
| 457 Statement final = Statement::Default(); | 457 Statement final = Statement::Default(); |
| 458 while (peek() != Token::RBRACE) { | 458 while (peek() != Token::RBRACE) { |
| 459 if (is_strict(language_mode())) { | 459 if (is_strict(language_mode()) || allow_harmony_sloppy()) { |
| 460 final = ParseStatementListItem(CHECK_OK); | 460 final = ParseStatementListItem(CHECK_OK); |
| 461 } else { | 461 } else { |
| 462 final = ParseStatement(CHECK_OK); | 462 final = ParseStatement(CHECK_OK); |
| 463 } | 463 } |
| 464 } | 464 } |
| 465 Expect(Token::RBRACE, ok); | 465 Expect(Token::RBRACE, ok); |
| 466 return final; | 466 return final; |
| 467 } | 467 } |
| 468 | 468 |
| 469 | 469 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // | 517 // |
| 518 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 518 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
| 519 // | 519 // |
| 520 // * It is a Syntax Error if the code that matches this production is not | 520 // * It is a Syntax Error if the code that matches this production is not |
| 521 // contained in extended code. | 521 // contained in extended code. |
| 522 // | 522 // |
| 523 // However disallowing const in sloppy mode will break compatibility with | 523 // However disallowing const in sloppy mode will break compatibility with |
| 524 // existing pages. Therefore we keep allowing const with the old | 524 // existing pages. Therefore we keep allowing const with the old |
| 525 // non-harmony semantics in sloppy mode. | 525 // non-harmony semantics in sloppy mode. |
| 526 Consume(Token::CONST); | 526 Consume(Token::CONST); |
| 527 if (is_strict(language_mode())) { | 527 if (is_strict(language_mode()) || |
| 528 (allow_harmony_sloppy() && !allow_legacy_const())) { |
| 528 DCHECK(var_context != kStatement); | 529 DCHECK(var_context != kStatement); |
| 529 is_strict_const = true; | 530 is_strict_const = true; |
| 530 require_initializer = var_context != kForStatement; | 531 require_initializer = var_context != kForStatement; |
| 531 } | 532 } |
| 532 } else if (peek() == Token::LET && is_strict(language_mode())) { | 533 } else if (peek() == Token::LET && allow_let()) { |
| 533 Consume(Token::LET); | 534 Consume(Token::LET); |
| 534 DCHECK(var_context != kStatement); | 535 DCHECK(var_context != kStatement); |
| 535 } else { | 536 } else { |
| 536 *ok = false; | 537 *ok = false; |
| 537 return Statement::Default(); | 538 return Statement::Default(); |
| 538 } | 539 } |
| 539 | 540 |
| 540 // The scope of a var/const declared variable anywhere inside a function | 541 // The scope of a var/const declared variable anywhere inside a function |
| 541 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 542 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
| 542 // of a let declared variable is the scope of the immediately enclosing | 543 // of a let declared variable is the scope of the immediately enclosing |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 863 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
| 863 // ForStatement :: | 864 // ForStatement :: |
| 864 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 865 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
| 865 | 866 |
| 866 Expect(Token::FOR, CHECK_OK); | 867 Expect(Token::FOR, CHECK_OK); |
| 867 Expect(Token::LPAREN, CHECK_OK); | 868 Expect(Token::LPAREN, CHECK_OK); |
| 868 bool is_let_identifier_expression = false; | 869 bool is_let_identifier_expression = false; |
| 869 if (peek() != Token::SEMICOLON) { | 870 if (peek() != Token::SEMICOLON) { |
| 870 ForEachStatement::VisitMode mode; | 871 ForEachStatement::VisitMode mode; |
| 871 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || | 872 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || |
| 872 (peek() == Token::LET && is_strict(language_mode()))) { | 873 (peek() == Token::LET && allow_let())) { |
| 873 int decl_count; | 874 int decl_count; |
| 874 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 875 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
| 875 Scanner::Location bindings_loc = Scanner::Location::invalid(); | 876 Scanner::Location bindings_loc = Scanner::Location::invalid(); |
| 876 ParseVariableDeclarations(kForStatement, &decl_count, | 877 ParseVariableDeclarations(kForStatement, &decl_count, |
| 877 &first_initializer_loc, &bindings_loc, | 878 &first_initializer_loc, &bindings_loc, |
| 878 CHECK_OK); | 879 CHECK_OK); |
| 879 bool accept_IN = decl_count >= 1; | 880 bool accept_IN = decl_count >= 1; |
| 880 bool accept_OF = true; | 881 bool accept_OF = true; |
| 881 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { | 882 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { |
| 882 if (!*ok) return Statement::Default(); | 883 if (!*ok) return Statement::Default(); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 | 1193 |
| 1193 DCHECK(!spread_pos.IsValid()); | 1194 DCHECK(!spread_pos.IsValid()); |
| 1194 | 1195 |
| 1195 return Expression::Default(); | 1196 return Expression::Default(); |
| 1196 } | 1197 } |
| 1197 | 1198 |
| 1198 #undef CHECK_OK | 1199 #undef CHECK_OK |
| 1199 | 1200 |
| 1200 | 1201 |
| 1201 } } // v8::internal | 1202 } } // v8::internal |
| OLD | NEW |