Chromium Code Reviews| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 bool stack_overflow() const { return stack_overflow_; } | 329 bool stack_overflow() const { return stack_overflow_; } |
| 330 void set_stack_overflow() { stack_overflow_ = true; } | 330 void set_stack_overflow() { stack_overflow_ = true; } |
| 331 Mode mode() const { return mode_; } | 331 Mode mode() const { return mode_; } |
| 332 Zone* zone() const { return zone_; } | 332 Zone* zone() const { return zone_; } |
| 333 | 333 |
| 334 INLINE(Token::Value peek()) { | 334 INLINE(Token::Value peek()) { |
| 335 if (stack_overflow_) return Token::ILLEGAL; | 335 if (stack_overflow_) return Token::ILLEGAL; |
| 336 return scanner()->peek(); | 336 return scanner()->peek(); |
| 337 } | 337 } |
| 338 | 338 |
| 339 INLINE(Token::Value PeekAhead()) { | |
| 340 if (stack_overflow_) return Token::ILLEGAL; | |
| 341 return scanner()->PeekAhead(); | |
| 342 } | |
| 343 | |
| 339 INLINE(Token::Value Next()) { | 344 INLINE(Token::Value Next()) { |
| 340 if (stack_overflow_) return Token::ILLEGAL; | 345 if (stack_overflow_) return Token::ILLEGAL; |
| 341 { | 346 { |
| 342 if (GetCurrentStackPosition() < stack_limit_) { | 347 if (GetCurrentStackPosition() < stack_limit_) { |
| 343 // Any further calls to Next or peek will return the illegal token. | 348 // Any further calls to Next or peek will return the illegal token. |
| 344 // The current call must return the next token, which might already | 349 // The current call must return the next token, which might already |
| 345 // have been peek'ed. | 350 // have been peek'ed. |
| 346 stack_overflow_ = true; | 351 stack_overflow_ = true; |
| 347 } | 352 } |
| 348 } | 353 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 | 707 |
| 703 void ParseFormalParameter(bool is_rest, | 708 void ParseFormalParameter(bool is_rest, |
| 704 FormalParametersT* parameters, | 709 FormalParametersT* parameters, |
| 705 ExpressionClassifier* classifier, bool* ok); | 710 ExpressionClassifier* classifier, bool* ok); |
| 706 void ParseFormalParameterList(FormalParametersT* parameters, | 711 void ParseFormalParameterList(FormalParametersT* parameters, |
| 707 ExpressionClassifier* classifier, bool* ok); | 712 ExpressionClassifier* classifier, bool* ok); |
| 708 void CheckArityRestrictions( | 713 void CheckArityRestrictions( |
| 709 int param_count, FunctionLiteral::ArityRestriction arity_restriction, | 714 int param_count, FunctionLiteral::ArityRestriction arity_restriction, |
| 710 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); | 715 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); |
| 711 | 716 |
| 717 bool IsLetKeyword(); | |
| 718 | |
| 712 // Checks if the expression is a valid reference expression (e.g., on the | 719 // Checks if the expression is a valid reference expression (e.g., on the |
| 713 // left-hand side of assignments). Although ruled out by ECMA as early errors, | 720 // left-hand side of assignments). Although ruled out by ECMA as early errors, |
| 714 // we allow calls for web compatibility and rewrite them to a runtime throw. | 721 // we allow calls for web compatibility and rewrite them to a runtime throw. |
| 715 ExpressionT CheckAndRewriteReferenceExpression( | 722 ExpressionT CheckAndRewriteReferenceExpression( |
| 716 ExpressionT expression, Scanner::Location location, | 723 ExpressionT expression, Scanner::Location location, |
| 717 MessageTemplate::Template message, bool* ok); | 724 MessageTemplate::Template message, bool* ok); |
| 718 | 725 |
| 719 // Used to validate property names in object literals and class literals | 726 // Used to validate property names in object literals and class literals |
| 720 enum PropertyKind { | 727 enum PropertyKind { |
| 721 kAccessorProperty, | 728 kAccessorProperty, |
| (...skipping 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3727 *ok = false; | 3734 *ok = false; |
| 3728 } | 3735 } |
| 3729 break; | 3736 break; |
| 3730 default: | 3737 default: |
| 3731 break; | 3738 break; |
| 3732 } | 3739 } |
| 3733 } | 3740 } |
| 3734 | 3741 |
| 3735 | 3742 |
| 3736 template <class Traits> | 3743 template <class Traits> |
| 3744 bool ParserBase<Traits>::IsLetKeyword() { | |
|
adamk
2015/08/15 00:28:31
How about "IsNextLetKeyword()"? I think that makes
Dan Ehrenberg
2015/08/17 18:05:02
Done
| |
| 3745 DCHECK(peek() == Token::LET); | |
| 3746 if (!allow_let()) { | |
| 3747 return false; | |
| 3748 } | |
| 3749 Token::Value uber_next = PeekAhead(); | |
|
adamk
2015/08/15 00:28:31
next_next, maybe? See later comment.
Dan Ehrenberg
2015/08/17 18:05:01
Done
| |
| 3750 switch (uber_next) { | |
| 3751 case Token::LBRACE: | |
| 3752 case Token::LBRACK: | |
| 3753 case Token::IDENTIFIER: | |
| 3754 case Token::STATIC: | |
| 3755 case Token::LET: // Yes, you can do let let = ... in sloppy mode | |
| 3756 case Token::YIELD: | |
| 3757 return true; | |
| 3758 default: | |
| 3759 return false; | |
| 3760 } | |
| 3761 } | |
| 3762 | |
| 3763 | |
| 3764 template <class Traits> | |
| 3737 typename ParserBase<Traits>::ExpressionT | 3765 typename ParserBase<Traits>::ExpressionT |
| 3738 ParserBase<Traits>::ParseArrowFunctionLiteral( | 3766 ParserBase<Traits>::ParseArrowFunctionLiteral( |
| 3739 const FormalParametersT& formal_parameters, | 3767 const FormalParametersT& formal_parameters, |
| 3740 const ExpressionClassifier& formals_classifier, bool* ok) { | 3768 const ExpressionClassifier& formals_classifier, bool* ok) { |
| 3741 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { | 3769 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
| 3742 // ASI inserts `;` after arrow parameters if a line terminator is found. | 3770 // ASI inserts `;` after arrow parameters if a line terminator is found. |
| 3743 // `=> ...` is never a valid expression, so report as syntax error. | 3771 // `=> ...` is never a valid expression, so report as syntax error. |
| 3744 // If next token is not `=>`, it's a syntax error anyways. | 3772 // If next token is not `=>`, it's a syntax error anyways. |
| 3745 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); | 3773 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
| 3746 *ok = false; | 3774 *ok = false; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4023 *ok = false; | 4051 *ok = false; |
| 4024 return; | 4052 return; |
| 4025 } | 4053 } |
| 4026 has_seen_constructor_ = true; | 4054 has_seen_constructor_ = true; |
| 4027 return; | 4055 return; |
| 4028 } | 4056 } |
| 4029 } | 4057 } |
| 4030 } } // v8::internal | 4058 } } // v8::internal |
| 4031 | 4059 |
| 4032 #endif // V8_PREPARSER_H | 4060 #endif // V8_PREPARSER_H |
| OLD | NEW |