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

Side by Side Diff: src/preparser.h

Issue 987203003: [parser] parse arrow function only if no linefeed before => (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | test/cctest/test-parsing.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/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/bailout-reason.h" 10 #include "src/bailout-reason.h"
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Traits::ReportMessageAt(source_location, message, arg, error_type); 531 Traits::ReportMessageAt(source_location, message, arg, error_type);
532 } 532 }
533 533
534 void ReportMessageAt(Scanner::Location location, const char* message, 534 void ReportMessageAt(Scanner::Location location, const char* message,
535 ParseErrorType error_type = kSyntaxError) { 535 ParseErrorType error_type = kSyntaxError) {
536 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), 536 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0),
537 error_type); 537 error_type);
538 } 538 }
539 539
540 void ReportUnexpectedToken(Token::Value token); 540 void ReportUnexpectedToken(Token::Value token);
541 void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token);
541 542
542 // Recursive descent functions: 543 // Recursive descent functions:
543 544
544 // Parses an identifier that is valid for the current scope, in particular it 545 // Parses an identifier that is valid for the current scope, in particular it
545 // fails on strict mode future reserved keywords in a strict scope. If 546 // fails on strict mode future reserved keywords in a strict scope. If
546 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or 547 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
547 // "arguments" as identifier even in strict mode (this is needed in cases like 548 // "arguments" as identifier even in strict mode (this is needed in cases like
548 // "var foo = eval;"). 549 // "var foo = eval;").
549 IdentifierT ParseIdentifier( 550 IdentifierT ParseIdentifier(
550 AllowEvalOrArgumentsAsIdentifier, 551 AllowEvalOrArgumentsAsIdentifier,
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 } 1673 }
1673 1674
1674 1675
1675 template <class Traits> 1676 template <class Traits>
1676 ParserBase<Traits>::FunctionState::~FunctionState() { 1677 ParserBase<Traits>::FunctionState::~FunctionState() {
1677 *scope_stack_ = outer_scope_; 1678 *scope_stack_ = outer_scope_;
1678 *function_state_stack_ = outer_function_state_; 1679 *function_state_stack_ = outer_function_state_;
1679 } 1680 }
1680 1681
1681 1682
1683
arv (Not doing code reviews) 2015/03/10 17:39:55 too many new lines
arv (Not doing code reviews) 2015/03/10 17:39:55 too many new lines
caitp (gmail) 2015/03/10 17:41:55 oops, fixed
1684 template<class Traits>
1685 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
1686 return ReportUnexpectedTokenAt(scanner_->location(), token);
1687 }
1688
1689
1682 template<class Traits> 1690 template<class Traits>
1683 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { 1691 void ParserBase<Traits>::ReportUnexpectedTokenAt(
1684 Scanner::Location source_location = scanner()->location(); 1692 Scanner::Location source_location, Token::Value token) {
1685 1693
1686 // Four of the tokens are treated specially 1694 // Four of the tokens are treated specially
1687 switch (token) { 1695 switch (token) {
1688 case Token::EOS: 1696 case Token::EOS:
1689 return ReportMessageAt(source_location, "unexpected_eos"); 1697 return ReportMessageAt(source_location, "unexpected_eos");
1690 case Token::SMI: 1698 case Token::SMI:
1691 case Token::NUMBER: 1699 case Token::NUMBER:
1692 return ReportMessageAt(source_location, "unexpected_token_number"); 1700 return ReportMessageAt(source_location, "unexpected_token_number");
1693 case Token::STRING: 1701 case Token::STRING:
1694 return ReportMessageAt(source_location, "unexpected_token_string"); 1702 return ReportMessageAt(source_location, "unexpected_token_string");
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 DCHECK(false); 2847 DCHECK(false);
2840 return this->EmptyExpression(); 2848 return this->EmptyExpression();
2841 } 2849 }
2842 2850
2843 2851
2844 template <class Traits> 2852 template <class Traits>
2845 typename ParserBase<Traits>::ExpressionT 2853 typename ParserBase<Traits>::ExpressionT
2846 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, 2854 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
2847 ExpressionT params_ast, 2855 ExpressionT params_ast,
2848 bool* ok) { 2856 bool* ok) {
2857 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
2858 // ASI inserts `;` after arrow parameters if a line terminator is found.
2859 // `=> ...` is never a valid expression, so report as syntax error.
2860 // If next token is not `=>`, it's a syntax error anyways.
2861 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW);
2862 *ok = false;
2863 return this->EmptyExpression();
2864 }
2865
2849 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2866 Scope* scope = this->NewScope(scope_, ARROW_SCOPE);
2850 typename Traits::Type::StatementList body; 2867 typename Traits::Type::StatementList body;
2851 int num_parameters = -1; 2868 int num_parameters = -1;
2852 int materialized_literal_count = -1; 2869 int materialized_literal_count = -1;
2853 int expected_property_count = -1; 2870 int expected_property_count = -1;
2854 int handler_count = 0; 2871 int handler_count = 0;
2855 2872
2856 { 2873 {
2857 typename Traits::Type::Factory function_factory(ast_value_factory()); 2874 typename Traits::Type::Factory function_factory(ast_value_factory());
2858 FunctionState function_state(&function_state_, &scope_, scope, 2875 FunctionState function_state(&function_state_, &scope_, scope,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 *ok = false; 3133 *ok = false;
3117 return; 3134 return;
3118 } 3135 }
3119 has_seen_constructor_ = true; 3136 has_seen_constructor_ = true;
3120 return; 3137 return;
3121 } 3138 }
3122 } 3139 }
3123 } } // v8::internal 3140 } } // v8::internal
3124 3141
3125 #endif // V8_PREPARSER_H 3142 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698