OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/bailout-reason.h" | 8 #include "src/bailout-reason.h" |
9 #include "src/expression-classifier.h" | 9 #include "src/expression-classifier.h" |
10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 657 |
658 // Parses an identifier that is valid for the current scope, in particular it | 658 // Parses an identifier that is valid for the current scope, in particular it |
659 // fails on strict mode future reserved keywords in a strict scope. If | 659 // fails on strict mode future reserved keywords in a strict scope. If |
660 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 660 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
661 // "arguments" as identifier even in strict mode (this is needed in cases like | 661 // "arguments" as identifier even in strict mode (this is needed in cases like |
662 // "var foo = eval;"). | 662 // "var foo = eval;"). |
663 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); | 663 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); |
664 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier, | 664 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier, |
665 bool* ok); | 665 bool* ok); |
666 // Parses an identifier or a strict mode future reserved word, and indicate | 666 // Parses an identifier or a strict mode future reserved word, and indicate |
667 // whether it is strict mode future reserved. | 667 // whether it is strict mode future reserved. Allows passing in is_generator |
| 668 // for the case of parsing the identifier in a function expression, where the |
| 669 // relevant "is_generator" bit is of the function being parsed, not the |
| 670 // containing |
| 671 // function. |
| 672 IdentifierT ParseIdentifierOrStrictReservedWord(bool is_generator, |
| 673 bool* is_strict_reserved, |
| 674 bool* ok); |
668 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, | 675 IdentifierT ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, |
669 bool* ok); | 676 bool* ok) { |
| 677 return ParseIdentifierOrStrictReservedWord(this->is_generator(), |
| 678 is_strict_reserved, ok); |
| 679 } |
| 680 |
670 IdentifierT ParseIdentifierName(bool* ok); | 681 IdentifierT ParseIdentifierName(bool* ok); |
671 // Parses an identifier and determines whether or not it is 'get' or 'set'. | 682 // Parses an identifier and determines whether or not it is 'get' or 'set'. |
672 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, bool* is_set, | 683 IdentifierT ParseIdentifierNameOrGetOrSet(bool* is_get, bool* is_set, |
673 bool* ok); | 684 bool* ok); |
674 | 685 |
675 | 686 |
676 ExpressionT ParseRegExpLiteral(bool seen_equal, | 687 ExpressionT ParseRegExpLiteral(bool seen_equal, |
677 ExpressionClassifier* classifier, bool* ok); | 688 ExpressionClassifier* classifier, bool* ok); |
678 | 689 |
679 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 690 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
(...skipping 1459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2139 return this->GetSymbol(scanner()); | 2150 return this->GetSymbol(scanner()); |
2140 } else { | 2151 } else { |
2141 this->ReportUnexpectedToken(next); | 2152 this->ReportUnexpectedToken(next); |
2142 *ok = false; | 2153 *ok = false; |
2143 return Traits::EmptyIdentifier(); | 2154 return Traits::EmptyIdentifier(); |
2144 } | 2155 } |
2145 } | 2156 } |
2146 | 2157 |
2147 | 2158 |
2148 template <class Traits> | 2159 template <class Traits> |
2149 typename ParserBase<Traits>::IdentifierT ParserBase< | 2160 typename ParserBase<Traits>::IdentifierT |
2150 Traits>::ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved, | 2161 ParserBase<Traits>::ParseIdentifierOrStrictReservedWord( |
2151 bool* ok) { | 2162 bool is_generator, bool* is_strict_reserved, bool* ok) { |
2152 Token::Value next = Next(); | 2163 Token::Value next = Next(); |
2153 if (next == Token::IDENTIFIER) { | 2164 if (next == Token::IDENTIFIER) { |
2154 *is_strict_reserved = false; | 2165 *is_strict_reserved = false; |
2155 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 2166 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || |
2156 next == Token::STATIC || | 2167 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { |
2157 (next == Token::YIELD && !this->is_generator())) { | |
2158 *is_strict_reserved = true; | 2168 *is_strict_reserved = true; |
2159 } else { | 2169 } else { |
2160 ReportUnexpectedToken(next); | 2170 ReportUnexpectedToken(next); |
2161 *ok = false; | 2171 *ok = false; |
2162 return Traits::EmptyIdentifier(); | 2172 return Traits::EmptyIdentifier(); |
2163 } | 2173 } |
2164 | 2174 |
2165 IdentifierT name = this->GetSymbol(scanner()); | 2175 IdentifierT name = this->GetSymbol(scanner()); |
2166 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); | 2176 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); |
2167 return name; | 2177 return name; |
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3489 | 3499 |
3490 Consume(Token::FUNCTION); | 3500 Consume(Token::FUNCTION); |
3491 int function_token_position = position(); | 3501 int function_token_position = position(); |
3492 bool is_generator = Check(Token::MUL); | 3502 bool is_generator = Check(Token::MUL); |
3493 IdentifierT name = this->EmptyIdentifier(); | 3503 IdentifierT name = this->EmptyIdentifier(); |
3494 bool is_strict_reserved_name = false; | 3504 bool is_strict_reserved_name = false; |
3495 Scanner::Location function_name_location = Scanner::Location::invalid(); | 3505 Scanner::Location function_name_location = Scanner::Location::invalid(); |
3496 FunctionLiteral::FunctionType function_type = | 3506 FunctionLiteral::FunctionType function_type = |
3497 FunctionLiteral::ANONYMOUS_EXPRESSION; | 3507 FunctionLiteral::ANONYMOUS_EXPRESSION; |
3498 if (peek_any_identifier()) { | 3508 if (peek_any_identifier()) { |
3499 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 3509 name = ParseIdentifierOrStrictReservedWord( |
3500 CHECK_OK); | 3510 is_generator, &is_strict_reserved_name, CHECK_OK); |
3501 function_name_location = scanner()->location(); | 3511 function_name_location = scanner()->location(); |
3502 function_type = FunctionLiteral::NAMED_EXPRESSION; | 3512 function_type = FunctionLiteral::NAMED_EXPRESSION; |
3503 } | 3513 } |
3504 result = this->ParseFunctionLiteral( | 3514 result = this->ParseFunctionLiteral( |
3505 name, function_name_location, | 3515 name, function_name_location, |
3506 is_strict_reserved_name ? kFunctionNameIsStrictReserved | 3516 is_strict_reserved_name ? kFunctionNameIsStrictReserved |
3507 : kFunctionNameValidityUnknown, | 3517 : kFunctionNameValidityUnknown, |
3508 is_generator ? FunctionKind::kGeneratorFunction | 3518 is_generator ? FunctionKind::kGeneratorFunction |
3509 : FunctionKind::kNormalFunction, | 3519 : FunctionKind::kNormalFunction, |
3510 function_token_position, function_type, FunctionLiteral::NORMAL_ARITY, | 3520 function_token_position, function_type, FunctionLiteral::NORMAL_ARITY, |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4240 return; | 4250 return; |
4241 } | 4251 } |
4242 has_seen_constructor_ = true; | 4252 has_seen_constructor_ = true; |
4243 return; | 4253 return; |
4244 } | 4254 } |
4245 } | 4255 } |
4246 } // namespace internal | 4256 } // namespace internal |
4247 } // namespace v8 | 4257 } // namespace v8 |
4248 | 4258 |
4249 #endif // V8_PREPARSER_H | 4259 #endif // V8_PREPARSER_H |
OLD | NEW |