| 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, | 32 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, |
| 33 MessageTemplate::Template message, | 33 MessageTemplate::Template message, |
| 34 const char* arg, | 34 const char* arg, |
| 35 ParseErrorType error_type) { | 35 ParseErrorType error_type) { |
| 36 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); | 36 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { | 40 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { |
| 41 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { | 41 if (scanner->current_token() == Token::ENUM) { |
| 42 return PreParserIdentifier::FutureReserved(); | 42 return PreParserIdentifier::Enum(); |
| 43 } else if (scanner->current_token() == Token::AWAIT) { |
| 44 return PreParserIdentifier::Await(); |
| 43 } else if (scanner->current_token() == | 45 } else if (scanner->current_token() == |
| 44 Token::FUTURE_STRICT_RESERVED_WORD) { | 46 Token::FUTURE_STRICT_RESERVED_WORD) { |
| 45 return PreParserIdentifier::FutureStrictReserved(); | 47 return PreParserIdentifier::FutureStrictReserved(); |
| 46 } else if (scanner->current_token() == Token::LET) { | 48 } else if (scanner->current_token() == Token::LET) { |
| 47 return PreParserIdentifier::Let(); | 49 return PreParserIdentifier::Let(); |
| 48 } else if (scanner->current_token() == Token::STATIC) { | 50 } else if (scanner->current_token() == Token::STATIC) { |
| 49 return PreParserIdentifier::Static(); | 51 return PreParserIdentifier::Static(); |
| 50 } else if (scanner->current_token() == Token::YIELD) { | 52 } else if (scanner->current_token() == Token::YIELD) { |
| 51 return PreParserIdentifier::Yield(); | 53 return PreParserIdentifier::Yield(); |
| 52 } | 54 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 PreParserExpression PreParserTraits::ParseFunctionLiteral( | 93 PreParserExpression PreParserTraits::ParseFunctionLiteral( |
| 92 PreParserIdentifier name, Scanner::Location function_name_location, | 94 PreParserIdentifier name, Scanner::Location function_name_location, |
| 93 FunctionNameValidity function_name_validity, FunctionKind kind, | 95 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 94 int function_token_position, FunctionLiteral::FunctionType type, | 96 int function_token_position, FunctionLiteral::FunctionType type, |
| 95 LanguageMode language_mode, bool* ok) { | 97 LanguageMode language_mode, bool* ok) { |
| 96 return pre_parser_->ParseFunctionLiteral( | 98 return pre_parser_->ParseFunctionLiteral( |
| 97 name, function_name_location, function_name_validity, kind, | 99 name, function_name_location, function_name_validity, kind, |
| 98 function_token_position, type, language_mode, ok); | 100 function_token_position, type, language_mode, ok); |
| 99 } | 101 } |
| 100 | 102 |
| 101 | |
| 102 PreParser::PreParseResult PreParser::PreParseLazyFunction( | 103 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 103 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, | 104 LanguageMode language_mode, FunctionKind kind, bool has_simple_parameters, |
| 104 ParserRecorder* log, Scanner::BookmarkScope* bookmark) { | 105 bool parsing_module, ParserRecorder* log, |
| 106 Scanner::BookmarkScope* bookmark) { |
| 107 parsing_module_ = parsing_module; |
| 105 log_ = log; | 108 log_ = log; |
| 106 // Lazy functions always have trivial outer scopes (no with/catch scopes). | 109 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 107 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); | 110 Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE); |
| 108 PreParserFactory top_factory(NULL); | 111 PreParserFactory top_factory(NULL); |
| 109 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, | 112 FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction, |
| 110 &top_factory); | 113 &top_factory); |
| 111 scope_->SetLanguageMode(language_mode); | 114 scope_->SetLanguageMode(language_mode); |
| 112 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); | 115 Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind); |
| 113 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); | 116 if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters(); |
| 114 PreParserFactory function_factory(NULL); | 117 PreParserFactory function_factory(NULL); |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 ExpressionClassifier classifier(this); | 582 ExpressionClassifier classifier(this); |
| 580 Expression expr = ParseExpression(true, &classifier, CHECK_OK); | 583 Expression expr = ParseExpression(true, &classifier, CHECK_OK); |
| 581 ValidateExpression(&classifier, CHECK_OK); | 584 ValidateExpression(&classifier, CHECK_OK); |
| 582 | 585 |
| 583 // Even if the expression starts with an identifier, it is not necessarily an | 586 // Even if the expression starts with an identifier, it is not necessarily an |
| 584 // identifier. For example, "foo + bar" starts with an identifier but is not | 587 // identifier. For example, "foo + bar" starts with an identifier but is not |
| 585 // an identifier. | 588 // an identifier. |
| 586 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { | 589 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { |
| 587 // Expression is a single identifier, and not, e.g., a parenthesized | 590 // Expression is a single identifier, and not, e.g., a parenthesized |
| 588 // identifier. | 591 // identifier. |
| 589 DCHECK(!expr.AsIdentifier().IsFutureReserved()); | 592 DCHECK(!expr.AsIdentifier().IsEnum()); |
| 593 DCHECK(!parsing_module_ || !expr.AsIdentifier().IsAwait()); |
| 590 DCHECK(is_sloppy(language_mode()) || | 594 DCHECK(is_sloppy(language_mode()) || |
| 591 !IsFutureStrictReserved(expr.AsIdentifier())); | 595 !IsFutureStrictReserved(expr.AsIdentifier())); |
| 592 Consume(Token::COLON); | 596 Consume(Token::COLON); |
| 593 // ES#sec-labelled-function-declarations Labelled Function Declarations | 597 // ES#sec-labelled-function-declarations Labelled Function Declarations |
| 594 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 598 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| 595 if (allow_function == kAllowLabelledFunctionStatement) { | 599 if (allow_function == kAllowLabelledFunctionStatement) { |
| 596 return ParseFunctionDeclaration(ok); | 600 return ParseFunctionDeclaration(ok); |
| 597 } else { | 601 } else { |
| 598 return ParseScopedStatement(true, ok); | 602 return ParseScopedStatement(true, ok); |
| 599 } | 603 } |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 Expect(Token::RBRACE, CHECK_OK); | 1156 Expect(Token::RBRACE, CHECK_OK); |
| 1153 return PreParserExpression::Default(); | 1157 return PreParserExpression::Default(); |
| 1154 } | 1158 } |
| 1155 } | 1159 } |
| 1156 | 1160 |
| 1157 #undef CHECK_OK | 1161 #undef CHECK_OK |
| 1158 | 1162 |
| 1159 | 1163 |
| 1160 } // namespace internal | 1164 } // namespace internal |
| 1161 } // namespace v8 | 1165 } // namespace v8 |
| OLD | NEW |