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

Side by Side Diff: src/parsing/parser.cc

Issue 1941823003: Properly disallow 'yield' in class expressions and arrow parameters (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Better error message for yield in parameter Created 4 years, 7 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
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 #include "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 FunctionLiteral* ParserTraits::ParseFunctionLiteral( 746 FunctionLiteral* ParserTraits::ParseFunctionLiteral(
747 const AstRawString* name, Scanner::Location function_name_location, 747 const AstRawString* name, Scanner::Location function_name_location,
748 FunctionNameValidity function_name_validity, FunctionKind kind, 748 FunctionNameValidity function_name_validity, FunctionKind kind,
749 int function_token_position, FunctionLiteral::FunctionType type, 749 int function_token_position, FunctionLiteral::FunctionType type,
750 LanguageMode language_mode, bool* ok) { 750 LanguageMode language_mode, bool* ok) {
751 return parser_->ParseFunctionLiteral( 751 return parser_->ParseFunctionLiteral(
752 name, function_name_location, function_name_validity, kind, 752 name, function_name_location, function_name_validity, kind,
753 function_token_position, type, language_mode, ok); 753 function_token_position, type, language_mode, ok);
754 } 754 }
755 755
756
757 ClassLiteral* ParserTraits::ParseClassLiteral( 756 ClassLiteral* ParserTraits::ParseClassLiteral(
758 const AstRawString* name, Scanner::Location class_name_location, 757 Type::ExpressionClassifier* classifier, const AstRawString* name,
759 bool name_is_strict_reserved, int pos, bool* ok) { 758 Scanner::Location class_name_location, bool name_is_strict_reserved,
760 return parser_->ParseClassLiteral(name, class_name_location, 759 int pos, bool* ok) {
760 return parser_->ParseClassLiteral(classifier, name, class_name_location,
761 name_is_strict_reserved, pos, ok); 761 name_is_strict_reserved, pos, ok);
762 } 762 }
763 763
764 void ParserTraits::MarkTailPosition(Expression* expression) { 764 void ParserTraits::MarkTailPosition(Expression* expression) {
765 expression->MarkTail(); 765 expression->MarkTail();
766 } 766 }
767 767
768 Parser::Parser(ParseInfo* info) 768 Parser::Parser(ParseInfo* info)
769 : ParserBase<ParserTraits>(info->zone(), &scanner_, info->stack_limit(), 769 : ParserBase<ParserTraits>(info->zone(), &scanner_, info->stack_limit(),
770 info->extension(), info->ast_value_factory(), 770 info->extension(), info->ast_value_factory(),
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 result = ParseHoistableDeclaration(pos, is_generator, &names, CHECK_OK); 1557 result = ParseHoistableDeclaration(pos, is_generator, &names, CHECK_OK);
1558 } 1558 }
1559 break; 1559 break;
1560 } 1560 }
1561 1561
1562 case Token::CLASS: 1562 case Token::CLASS:
1563 Consume(Token::CLASS); 1563 Consume(Token::CLASS);
1564 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) { 1564 if (peek() == Token::EXTENDS || peek() == Token::LBRACE) {
1565 // ClassDeclaration[+Default] :: 1565 // ClassDeclaration[+Default] ::
1566 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}' 1566 // 'class' ('extends' LeftHandExpression)? '{' ClassBody '}'
1567 default_export = 1567 default_export = ParseClassLiteral(nullptr, default_string,
1568 ParseClassLiteral(default_string, Scanner::Location::invalid(), 1568 Scanner::Location::invalid(), false,
1569 false, position(), CHECK_OK); 1569 position(), CHECK_OK);
1570 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition); 1570 result = factory()->NewEmptyStatement(RelocInfo::kNoPosition);
1571 } else { 1571 } else {
1572 result = ParseClassDeclaration(&names, CHECK_OK); 1572 result = ParseClassDeclaration(&names, CHECK_OK);
1573 } 1573 }
1574 break; 1574 break;
1575 1575
1576 default: { 1576 default: {
1577 int pos = peek_position(); 1577 int pos = peek_position();
1578 ExpressionClassifier classifier(this); 1578 ExpressionClassifier classifier(this);
1579 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); 1579 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK);
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
2123 // has the same semantics as: 2123 // has the same semantics as:
2124 // 2124 //
2125 // let C = class C { ... }; 2125 // let C = class C { ... };
2126 // 2126 //
2127 // so rewrite it as such. 2127 // so rewrite it as such.
2128 2128
2129 int pos = position(); 2129 int pos = position();
2130 bool is_strict_reserved = false; 2130 bool is_strict_reserved = false;
2131 const AstRawString* name = 2131 const AstRawString* name =
2132 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 2132 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
2133 ClassLiteral* value = ParseClassLiteral(name, scanner()->location(), 2133 ClassLiteral* value = ParseClassLiteral(nullptr, name, scanner()->location(),
2134 is_strict_reserved, pos, CHECK_OK); 2134 is_strict_reserved, pos, CHECK_OK);
2135 2135
2136 VariableProxy* proxy = NewUnresolved(name, LET); 2136 VariableProxy* proxy = NewUnresolved(name, LET);
2137 Declaration* declaration = 2137 Declaration* declaration =
2138 factory()->NewVariableDeclaration(proxy, LET, scope_, pos); 2138 factory()->NewVariableDeclaration(proxy, LET, scope_, pos);
2139 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 2139 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
2140 proxy->var()->set_initializer_position(position()); 2140 proxy->var()->set_initializer_position(position());
2141 Assignment* assignment = 2141 Assignment* assignment =
2142 factory()->NewAssignment(Token::INIT, proxy, value, pos); 2142 factory()->NewAssignment(Token::INIT, proxy, value, pos);
2143 Statement* assignment_statement = 2143 Statement* assignment_statement =
(...skipping 2479 matching lines...) Expand 10 before | Expand all | Expand 10 after
4623 } 4623 }
4624 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4624 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4625 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4625 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4626 parsing_module_, logger, bookmark, use_counts_); 4626 parsing_module_, logger, bookmark, use_counts_);
4627 if (pre_parse_timer_ != NULL) { 4627 if (pre_parse_timer_ != NULL) {
4628 pre_parse_timer_->Stop(); 4628 pre_parse_timer_->Stop();
4629 } 4629 }
4630 return result; 4630 return result;
4631 } 4631 }
4632 4632
4633 4633 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
4634 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, 4634 const AstRawString* name,
4635 Scanner::Location class_name_location, 4635 Scanner::Location class_name_location,
4636 bool name_is_strict_reserved, int pos, 4636 bool name_is_strict_reserved, int pos,
4637 bool* ok) { 4637 bool* ok) {
4638 // All parts of a ClassDeclaration and ClassExpression are strict code. 4638 // All parts of a ClassDeclaration and ClassExpression are strict code.
4639 if (name_is_strict_reserved) { 4639 if (name_is_strict_reserved) {
4640 ReportMessageAt(class_name_location, 4640 ReportMessageAt(class_name_location,
4641 MessageTemplate::kUnexpectedStrictReserved); 4641 MessageTemplate::kUnexpectedStrictReserved);
4642 *ok = false; 4642 *ok = false;
4643 return NULL; 4643 return NULL;
4644 } 4644 }
(...skipping 12 matching lines...) Expand all
4657 if (name != NULL) { 4657 if (name != NULL) {
4658 proxy = NewUnresolved(name, CONST); 4658 proxy = NewUnresolved(name, CONST);
4659 Declaration* declaration = 4659 Declaration* declaration =
4660 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); 4660 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
4661 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 4661 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
4662 } 4662 }
4663 4663
4664 Expression* extends = NULL; 4664 Expression* extends = NULL;
4665 if (Check(Token::EXTENDS)) { 4665 if (Check(Token::EXTENDS)) {
4666 block_scope->set_start_position(scanner()->location().end_pos); 4666 block_scope->set_start_position(scanner()->location().end_pos);
4667 ExpressionClassifier classifier(this); 4667 ExpressionClassifier extends_classifier(this);
4668 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); 4668 extends = ParseLeftHandSideExpression(&extends_classifier, CHECK_OK);
4669 RewriteNonPattern(&classifier, CHECK_OK); 4669 RewriteNonPattern(&extends_classifier, CHECK_OK);
4670 if (classifier != nullptr) {
4671 classifier->Accumulate(&extends_classifier,
4672 ExpressionClassifier::ExpressionProductions);
4673 }
4670 } else { 4674 } else {
4671 block_scope->set_start_position(scanner()->location().end_pos); 4675 block_scope->set_start_position(scanner()->location().end_pos);
4672 } 4676 }
4673 4677
4674 4678
4675 ClassLiteralChecker checker(this); 4679 ClassLiteralChecker checker(this);
4676 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4680 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4677 FunctionLiteral* constructor = NULL; 4681 FunctionLiteral* constructor = NULL;
4678 bool has_seen_constructor = false; 4682 bool has_seen_constructor = false;
4679 4683
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6810 try_block, target); 6814 try_block, target);
6811 final_loop = target; 6815 final_loop = target;
6812 } 6816 }
6813 6817
6814 return final_loop; 6818 return final_loop;
6815 } 6819 }
6816 6820
6817 6821
6818 } // namespace internal 6822 } // namespace internal
6819 } // namespace v8 6823 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698