Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: src/preparser.h

Issue 1315673009: Sloppy-mode let parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: clarify comment Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 bool stack_overflow() const { return stack_overflow_; } 331 bool stack_overflow() const { return stack_overflow_; }
332 void set_stack_overflow() { stack_overflow_ = true; } 332 void set_stack_overflow() { stack_overflow_ = true; }
333 Mode mode() const { return mode_; } 333 Mode mode() const { return mode_; }
334 Zone* zone() const { return zone_; } 334 Zone* zone() const { return zone_; }
335 335
336 INLINE(Token::Value peek()) { 336 INLINE(Token::Value peek()) {
337 if (stack_overflow_) return Token::ILLEGAL; 337 if (stack_overflow_) return Token::ILLEGAL;
338 return scanner()->peek(); 338 return scanner()->peek();
339 } 339 }
340 340
341 INLINE(Token::Value PeekAhead()) {
342 if (stack_overflow_) return Token::ILLEGAL;
343 return scanner()->PeekAhead();
344 }
345
341 INLINE(Token::Value Next()) { 346 INLINE(Token::Value Next()) {
342 if (stack_overflow_) return Token::ILLEGAL; 347 if (stack_overflow_) return Token::ILLEGAL;
343 { 348 {
344 if (GetCurrentStackPosition() < stack_limit_) { 349 if (GetCurrentStackPosition() < stack_limit_) {
345 // Any further calls to Next or peek will return the illegal token. 350 // Any further calls to Next or peek will return the illegal token.
346 // The current call must return the next token, which might already 351 // The current call must return the next token, which might already
347 // have been peek'ed. 352 // have been peek'ed.
348 stack_overflow_ = true; 353 stack_overflow_ = true;
349 } 354 }
350 } 355 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 bool* ok); 708 bool* ok);
704 709
705 void ParseFormalParameter(FormalParametersT* parameters, 710 void ParseFormalParameter(FormalParametersT* parameters,
706 ExpressionClassifier* classifier, bool* ok); 711 ExpressionClassifier* classifier, bool* ok);
707 void ParseFormalParameterList(FormalParametersT* parameters, 712 void ParseFormalParameterList(FormalParametersT* parameters,
708 ExpressionClassifier* classifier, bool* ok); 713 ExpressionClassifier* classifier, bool* ok);
709 void CheckArityRestrictions( 714 void CheckArityRestrictions(
710 int param_count, FunctionLiteral::ArityRestriction arity_restriction, 715 int param_count, FunctionLiteral::ArityRestriction arity_restriction,
711 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok); 716 bool has_rest, int formals_start_pos, int formals_end_pos, bool* ok);
712 717
718 bool IsNextLetKeyword();
719
713 // Checks if the expression is a valid reference expression (e.g., on the 720 // Checks if the expression is a valid reference expression (e.g., on the
714 // left-hand side of assignments). Although ruled out by ECMA as early errors, 721 // left-hand side of assignments). Although ruled out by ECMA as early errors,
715 // we allow calls for web compatibility and rewrite them to a runtime throw. 722 // we allow calls for web compatibility and rewrite them to a runtime throw.
716 ExpressionT CheckAndRewriteReferenceExpression( 723 ExpressionT CheckAndRewriteReferenceExpression(
717 ExpressionT expression, int beg_pos, int end_pos, 724 ExpressionT expression, int beg_pos, int end_pos,
718 MessageTemplate::Template message, bool* ok); 725 MessageTemplate::Template message, bool* ok);
719 ExpressionT CheckAndRewriteReferenceExpression( 726 ExpressionT CheckAndRewriteReferenceExpression(
720 ExpressionT expression, int beg_pos, int end_pos, 727 ExpressionT expression, int beg_pos, int end_pos,
721 MessageTemplate::Template message, ParseErrorType type, bool* ok); 728 MessageTemplate::Template message, ParseErrorType type, bool* ok);
722 729
(...skipping 3046 matching lines...) Expand 10 before | Expand all | Expand 10 after
3769 *ok = false; 3776 *ok = false;
3770 } 3777 }
3771 break; 3778 break;
3772 default: 3779 default:
3773 break; 3780 break;
3774 } 3781 }
3775 } 3782 }
3776 3783
3777 3784
3778 template <class Traits> 3785 template <class Traits>
3786 bool ParserBase<Traits>::IsNextLetKeyword() {
3787 DCHECK(peek() == Token::LET);
3788 if (!allow_let()) {
3789 return false;
3790 }
3791 Token::Value next_next = PeekAhead();
3792 switch (next_next) {
3793 case Token::LBRACE:
3794 case Token::LBRACK:
3795 case Token::IDENTIFIER:
3796 case Token::STATIC:
3797 case Token::LET: // Yes, you can do let let = ... in sloppy mode
3798 case Token::YIELD:
3799 return true;
3800 default:
3801 return false;
3802 }
3803 }
3804
3805
3806 template <class Traits>
3779 typename ParserBase<Traits>::ExpressionT 3807 typename ParserBase<Traits>::ExpressionT
3780 ParserBase<Traits>::ParseArrowFunctionLiteral( 3808 ParserBase<Traits>::ParseArrowFunctionLiteral(
3781 const FormalParametersT& formal_parameters, 3809 const FormalParametersT& formal_parameters,
3782 const ExpressionClassifier& formals_classifier, bool* ok) { 3810 const ExpressionClassifier& formals_classifier, bool* ok) {
3783 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { 3811 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
3784 // ASI inserts `;` after arrow parameters if a line terminator is found. 3812 // ASI inserts `;` after arrow parameters if a line terminator is found.
3785 // `=> ...` is never a valid expression, so report as syntax error. 3813 // `=> ...` is never a valid expression, so report as syntax error.
3786 // If next token is not `=>`, it's a syntax error anyways. 3814 // If next token is not `=>`, it's a syntax error anyways.
3787 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); 3815 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
3788 *ok = false; 3816 *ok = false;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 *ok = false; 4104 *ok = false;
4077 return; 4105 return;
4078 } 4106 }
4079 has_seen_constructor_ = true; 4107 has_seen_constructor_ = true;
4080 return; 4108 return;
4081 } 4109 }
4082 } 4110 }
4083 } } // v8::internal 4111 } } // v8::internal
4084 4112
4085 #endif // V8_PREPARSER_H 4113 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698