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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 7202c981e566165d4cf8495e86aad758ae2ae5ae..b475f1f15b539f43c554bdb1e6022ea6548a3731 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -784,15 +784,6 @@ class ParserBase : public Traits {
classifier->RecordArrowFormalParametersError(location, message, arg);
}
- void FormalParameterInitializerUnexpectedToken(
- ExpressionClassifier* classifier) {
- MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
- const char* arg;
- Scanner::Location location = scanner()->peek_location();
- GetUnexpectedTokenMessage(peek(), &message, &location, &arg);
- classifier->RecordFormalParameterInitializerError(location, message, arg);
- }
-
// Recursive descent functions:
// Parses an identifier that is valid for the current scope, in particular it
@@ -1415,7 +1406,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
CHECK_OK);
class_name_location = scanner()->location();
}
- return this->ParseClassLiteral(name, class_name_location,
+ return this->ParseClassLiteral(classifier, name, class_name_location,
is_strict_reserved_name,
class_token_position, ok);
}
@@ -1990,6 +1981,13 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
Token::String(Token::ARROW));
ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
parenthesized_formals, CHECK_OK);
+ // This reads strangely, but is correct: it checks whether any
+ // sub-expression of the parameter list failed to be a valid formal
+ // parameter initializer. Since YieldExpressions are banned anywhere
+ // in an arrow parameter list, this is correct.
+ // TODO(adamk): Rename "FormalParameterInitializerError" to refer to
+ // "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
+ ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
Scope* scope =
this->NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
@@ -2126,7 +2124,8 @@ ParserBase<Traits>::ParseYieldExpression(bool accept_IN,
int pos = peek_position();
classifier->RecordPatternError(scanner()->peek_location(),
MessageTemplate::kInvalidDestructuringTarget);
- FormalParameterInitializerUnexpectedToken(classifier);
+ classifier->RecordFormalParameterInitializerError(
+ scanner()->peek_location(), MessageTemplate::kYieldInParameter);
Expect(Token::YIELD, CHECK_OK);
ExpressionT generator_object =
factory()->NewVariableProxy(function_state_->generator_object_variable());
« 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