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

Side by Side Diff: src/parsing/parser-base.h

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
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('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_PARSING_PARSER_BASE_H 5 #ifndef V8_PARSING_PARSER_BASE_H
6 #define V8_PARSING_PARSER_BASE_H 6 #define V8_PARSING_PARSER_BASE_H
7 7
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/hashmap.h" 10 #include "src/hashmap.h"
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 778
779 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { 779 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) {
780 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken; 780 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
781 const char* arg; 781 const char* arg;
782 Scanner::Location location = scanner()->peek_location(); 782 Scanner::Location location = scanner()->peek_location();
783 GetUnexpectedTokenMessage(peek(), &message, &location, &arg); 783 GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
784 classifier->RecordArrowFormalParametersError(location, message, arg); 784 classifier->RecordArrowFormalParametersError(location, message, arg);
785 } 785 }
786 786
787 void FormalParameterInitializerUnexpectedToken(
788 ExpressionClassifier* classifier) {
789 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
790 const char* arg;
791 Scanner::Location location = scanner()->peek_location();
792 GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
793 classifier->RecordFormalParameterInitializerError(location, message, arg);
794 }
795
796 // Recursive descent functions: 787 // Recursive descent functions:
797 788
798 // Parses an identifier that is valid for the current scope, in particular it 789 // Parses an identifier that is valid for the current scope, in particular it
799 // fails on strict mode future reserved keywords in a strict scope. If 790 // fails on strict mode future reserved keywords in a strict scope. If
800 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or 791 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or
801 // "arguments" as identifier even in strict mode (this is needed in cases like 792 // "arguments" as identifier even in strict mode (this is needed in cases like
802 // "var foo = eval;"). 793 // "var foo = eval;").
803 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); 794 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok);
804 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier, 795 IdentifierT ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
805 bool* ok); 796 bool* ok);
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 Consume(Token::CLASS); 1399 Consume(Token::CLASS);
1409 int class_token_position = position(); 1400 int class_token_position = position();
1410 IdentifierT name = this->EmptyIdentifier(); 1401 IdentifierT name = this->EmptyIdentifier();
1411 bool is_strict_reserved_name = false; 1402 bool is_strict_reserved_name = false;
1412 Scanner::Location class_name_location = Scanner::Location::invalid(); 1403 Scanner::Location class_name_location = Scanner::Location::invalid();
1413 if (peek_any_identifier()) { 1404 if (peek_any_identifier()) {
1414 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 1405 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
1415 CHECK_OK); 1406 CHECK_OK);
1416 class_name_location = scanner()->location(); 1407 class_name_location = scanner()->location();
1417 } 1408 }
1418 return this->ParseClassLiteral(name, class_name_location, 1409 return this->ParseClassLiteral(classifier, name, class_name_location,
1419 is_strict_reserved_name, 1410 is_strict_reserved_name,
1420 class_token_position, ok); 1411 class_token_position, ok);
1421 } 1412 }
1422 1413
1423 case Token::TEMPLATE_SPAN: 1414 case Token::TEMPLATE_SPAN:
1424 case Token::TEMPLATE_TAIL: 1415 case Token::TEMPLATE_TAIL:
1425 BindingPatternUnexpectedToken(classifier); 1416 BindingPatternUnexpectedToken(classifier);
1426 return this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, 1417 return this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos,
1427 classifier, ok); 1418 classifier, ok);
1428 1419
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); 1974 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
1984 } 1975 }
1985 ExpressionT expression = this->ParseConditionalExpression( 1976 ExpressionT expression = this->ParseConditionalExpression(
1986 accept_IN, &arrow_formals_classifier, CHECK_OK); 1977 accept_IN, &arrow_formals_classifier, CHECK_OK);
1987 if (peek() == Token::ARROW) { 1978 if (peek() == Token::ARROW) {
1988 classifier->RecordPatternError(scanner()->peek_location(), 1979 classifier->RecordPatternError(scanner()->peek_location(),
1989 MessageTemplate::kUnexpectedToken, 1980 MessageTemplate::kUnexpectedToken,
1990 Token::String(Token::ARROW)); 1981 Token::String(Token::ARROW));
1991 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, 1982 ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
1992 parenthesized_formals, CHECK_OK); 1983 parenthesized_formals, CHECK_OK);
1984 // This reads strangely, but is correct: it checks whether any
1985 // sub-expression of the parameter list failed to be a valid formal
1986 // parameter initializer. Since YieldExpressions are banned anywhere
1987 // in an arrow parameter list, this is correct.
1988 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to
1989 // "YieldExpression", which is its only use.
Dan Ehrenberg 2016/05/02 23:11:43 You probably want to remove this TODO
adamk 2016/05/02 23:14:18 I actually also want to rename the methods on Expr
1990 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
1993 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); 1991 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
1994 Scope* scope = 1992 Scope* scope =
1995 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction); 1993 this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
1996 // Because the arrow's parameters were parsed in the outer scope, any 1994 // Because the arrow's parameters were parsed in the outer scope, any
1997 // usage flags that might have been triggered there need to be copied 1995 // usage flags that might have been triggered there need to be copied
1998 // to the arrow scope. 1996 // to the arrow scope.
1999 scope_->PropagateUsageFlagsToScope(scope); 1997 scope_->PropagateUsageFlagsToScope(scope);
2000 FormalParametersT parameters(scope); 1998 FormalParametersT parameters(scope);
2001 if (!arrow_formals_classifier.is_simple_parameter_list()) { 1999 if (!arrow_formals_classifier.is_simple_parameter_list()) {
2002 scope->SetHasNonSimpleParameters(); 2000 scope->SetHasNonSimpleParameters();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 template <class Traits> 2117 template <class Traits>
2120 typename ParserBase<Traits>::ExpressionT 2118 typename ParserBase<Traits>::ExpressionT
2121 ParserBase<Traits>::ParseYieldExpression(bool accept_IN, 2119 ParserBase<Traits>::ParseYieldExpression(bool accept_IN,
2122 ExpressionClassifier* classifier, 2120 ExpressionClassifier* classifier,
2123 bool* ok) { 2121 bool* ok) {
2124 // YieldExpression :: 2122 // YieldExpression ::
2125 // 'yield' ([no line terminator] '*'? AssignmentExpression)? 2123 // 'yield' ([no line terminator] '*'? AssignmentExpression)?
2126 int pos = peek_position(); 2124 int pos = peek_position();
2127 classifier->RecordPatternError(scanner()->peek_location(), 2125 classifier->RecordPatternError(scanner()->peek_location(),
2128 MessageTemplate::kInvalidDestructuringTarget); 2126 MessageTemplate::kInvalidDestructuringTarget);
2129 FormalParameterInitializerUnexpectedToken(classifier); 2127 classifier->RecordFormalParameterInitializerError(
2128 scanner()->peek_location(), MessageTemplate::kYieldInParameter);
2130 Expect(Token::YIELD, CHECK_OK); 2129 Expect(Token::YIELD, CHECK_OK);
2131 ExpressionT generator_object = 2130 ExpressionT generator_object =
2132 factory()->NewVariableProxy(function_state_->generator_object_variable()); 2131 factory()->NewVariableProxy(function_state_->generator_object_variable());
2133 ExpressionT expression = Traits::EmptyExpression(); 2132 ExpressionT expression = Traits::EmptyExpression();
2134 bool delegating = false; // yield* 2133 bool delegating = false; // yield*
2135 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { 2134 if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
2136 if (Check(Token::MUL)) delegating = true; 2135 if (Check(Token::MUL)) delegating = true;
2137 switch (peek()) { 2136 switch (peek()) {
2138 case Token::EOS: 2137 case Token::EOS:
2139 case Token::SEMICOLON: 2138 case Token::SEMICOLON:
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
3211 has_seen_constructor_ = true; 3210 has_seen_constructor_ = true;
3212 return; 3211 return;
3213 } 3212 }
3214 } 3213 }
3215 3214
3216 3215
3217 } // namespace internal 3216 } // namespace internal
3218 } // namespace v8 3217 } // namespace v8
3219 3218
3220 #endif // V8_PARSING_PARSER_BASE_H 3219 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698