| 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 do { | 492 do { |
| 493 // Parse variable name. | 493 // Parse variable name. |
| 494 if (nvars > 0) Consume(Token::COMMA); | 494 if (nvars > 0) Consume(Token::COMMA); |
| 495 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 495 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); |
| 496 Scanner::Location variable_loc = scanner()->location(); | 496 Scanner::Location variable_loc = scanner()->location(); |
| 497 nvars++; | 497 nvars++; |
| 498 if (peek() == Token::ASSIGN || require_initializer || | 498 if (peek() == Token::ASSIGN || require_initializer || |
| 499 // require initializers for multiple consts. | 499 // require initializers for multiple consts. |
| 500 (is_strict_const && peek() == Token::COMMA)) { | 500 (is_strict_const && peek() == Token::COMMA)) { |
| 501 Expect(Token::ASSIGN, CHECK_OK); | 501 Expect(Token::ASSIGN, CHECK_OK); |
| 502 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 502 ExpressionClassifier classifier; |
| 503 ParseAssignmentExpression(var_context != kForStatement, &classifier, |
| 504 CHECK_OK); |
| 505 // TODO(dslomov): report error if not valid expression. |
| 503 | 506 |
| 504 variable_loc.end_pos = scanner()->location().end_pos; | 507 variable_loc.end_pos = scanner()->location().end_pos; |
| 505 if (first_initializer_loc && !first_initializer_loc->IsValid()) { | 508 if (first_initializer_loc && !first_initializer_loc->IsValid()) { |
| 506 *first_initializer_loc = variable_loc; | 509 *first_initializer_loc = variable_loc; |
| 507 } | 510 } |
| 508 } | 511 } |
| 509 } while (peek() == Token::COMMA); | 512 } while (peek() == Token::COMMA); |
| 510 | 513 |
| 511 if (bindings_loc) { | 514 if (bindings_loc) { |
| 512 *bindings_loc = | 515 *bindings_loc = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 533 return Statement::Default(); | 536 return Statement::Default(); |
| 534 | 537 |
| 535 // TODO(arv): Handle `let [` | 538 // TODO(arv): Handle `let [` |
| 536 // https://code.google.com/p/v8/issues/detail?id=3847 | 539 // https://code.google.com/p/v8/issues/detail?id=3847 |
| 537 | 540 |
| 538 default: | 541 default: |
| 539 break; | 542 break; |
| 540 } | 543 } |
| 541 | 544 |
| 542 bool starts_with_identifier = peek_any_identifier(); | 545 bool starts_with_identifier = peek_any_identifier(); |
| 543 Expression expr = ParseExpression(true, CHECK_OK); | 546 ExpressionClassifier classifier; |
| 547 Expression expr = ParseExpression(true, &classifier, CHECK_OK); |
| 548 // TODO(dslomov): report error if not a valid expression. |
| 549 |
| 544 // Even if the expression starts with an identifier, it is not necessarily an | 550 // Even if the expression starts with an identifier, it is not necessarily an |
| 545 // identifier. For example, "foo + bar" starts with an identifier but is not | 551 // identifier. For example, "foo + bar" starts with an identifier but is not |
| 546 // an identifier. | 552 // an identifier. |
| 547 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { | 553 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { |
| 548 // Expression is a single identifier, and not, e.g., a parenthesized | 554 // Expression is a single identifier, and not, e.g., a parenthesized |
| 549 // identifier. | 555 // identifier. |
| 550 DCHECK(!expr.AsIdentifier().IsFutureReserved()); | 556 DCHECK(!expr.AsIdentifier().IsFutureReserved()); |
| 551 DCHECK(is_sloppy(language_mode()) || | 557 DCHECK(is_sloppy(language_mode()) || |
| 552 !IsFutureStrictReserved(expr.AsIdentifier())); | 558 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 553 Consume(Token::COLON); | 559 Consume(Token::COLON); |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 | 1067 |
| 1062 Scope* scope = NewScope(scope_, BLOCK_SCOPE); | 1068 Scope* scope = NewScope(scope_, BLOCK_SCOPE); |
| 1063 BlockState block_state(&scope_, scope); | 1069 BlockState block_state(&scope_, scope); |
| 1064 scope_->SetLanguageMode( | 1070 scope_->SetLanguageMode( |
| 1065 static_cast<LanguageMode>(class_language_mode | STRICT_BIT)); | 1071 static_cast<LanguageMode>(class_language_mode | STRICT_BIT)); |
| 1066 // TODO(marja): Make PreParser use scope names too. | 1072 // TODO(marja): Make PreParser use scope names too. |
| 1067 // scope_->SetScopeName(name); | 1073 // scope_->SetScopeName(name); |
| 1068 | 1074 |
| 1069 bool has_extends = Check(Token::EXTENDS); | 1075 bool has_extends = Check(Token::EXTENDS); |
| 1070 if (has_extends) { | 1076 if (has_extends) { |
| 1071 ParseLeftHandSideExpression(CHECK_OK); | 1077 ExpressionClassifier classifier; |
| 1078 ParseLeftHandSideExpression(&classifier, CHECK_OK); |
| 1079 // TODO(dslomov): report error if not a valid expression. |
| 1072 } | 1080 } |
| 1073 | 1081 |
| 1074 ClassLiteralChecker checker(this); | 1082 ClassLiteralChecker checker(this); |
| 1075 bool has_seen_constructor = false; | 1083 bool has_seen_constructor = false; |
| 1076 | 1084 |
| 1077 Expect(Token::LBRACE, CHECK_OK); | 1085 Expect(Token::LBRACE, CHECK_OK); |
| 1078 while (peek() != Token::RBRACE) { | 1086 while (peek() != Token::RBRACE) { |
| 1079 if (Check(Token::SEMICOLON)) continue; | 1087 if (Check(Token::SEMICOLON)) continue; |
| 1080 const bool in_class = true; | 1088 const bool in_class = true; |
| 1081 const bool is_static = false; | 1089 const bool is_static = false; |
| 1082 bool is_computed_name = false; // Classes do not care about computed | 1090 bool is_computed_name = false; // Classes do not care about computed |
| 1083 // property names here. | 1091 // property names here. |
| 1092 ExpressionClassifier classifier; |
| 1084 ParsePropertyDefinition(&checker, in_class, has_extends, is_static, | 1093 ParsePropertyDefinition(&checker, in_class, has_extends, is_static, |
| 1085 &is_computed_name, &has_seen_constructor, CHECK_OK); | 1094 &is_computed_name, &has_seen_constructor, |
| 1095 &classifier, CHECK_OK); |
| 1096 // TODO(dslomov): report error if not a valid expression. |
| 1086 } | 1097 } |
| 1087 | 1098 |
| 1088 Expect(Token::RBRACE, CHECK_OK); | 1099 Expect(Token::RBRACE, CHECK_OK); |
| 1089 | 1100 |
| 1090 return Expression::Default(); | 1101 return Expression::Default(); |
| 1091 } | 1102 } |
| 1092 | 1103 |
| 1093 | 1104 |
| 1094 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { | 1105 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { |
| 1095 // CallRuntime :: | 1106 // CallRuntime :: |
| 1096 // '%' Identifier Arguments | 1107 // '%' Identifier Arguments |
| 1097 Expect(Token::MOD, CHECK_OK); | 1108 Expect(Token::MOD, CHECK_OK); |
| 1098 if (!allow_natives()) { | 1109 if (!allow_natives()) { |
| 1099 *ok = false; | 1110 *ok = false; |
| 1100 return Expression::Default(); | 1111 return Expression::Default(); |
| 1101 } | 1112 } |
| 1102 // Allow "eval" or "arguments" for backward compatibility. | 1113 // Allow "eval" or "arguments" for backward compatibility. |
| 1103 ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); | 1114 ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK); |
| 1104 Scanner::Location spread_pos; | 1115 Scanner::Location spread_pos; |
| 1105 ParseArguments(&spread_pos, ok); | 1116 ExpressionClassifier classifier; |
| 1117 ParseArguments(&spread_pos, &classifier, ok); |
| 1118 // TODO(dslomov): report error if not a valid expression. |
| 1106 | 1119 |
| 1107 DCHECK(!spread_pos.IsValid()); | 1120 DCHECK(!spread_pos.IsValid()); |
| 1108 | 1121 |
| 1109 return Expression::Default(); | 1122 return Expression::Default(); |
| 1110 } | 1123 } |
| 1111 | 1124 |
| 1112 #undef CHECK_OK | 1125 #undef CHECK_OK |
| 1113 | 1126 |
| 1114 | 1127 |
| 1115 } } // v8::internal | 1128 } } // v8::internal |
| OLD | NEW |