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

Unified Diff: src/preparser.h

Issue 1320673007: Disallow yield in default parameter initializers (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Rebase Created 5 years, 4 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/expression-classifier.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 07e431bfc54790b0a65c081f9ea8021ab6fba84c..170c744946d651540b098ef1e4337e5b1dd3e796 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -548,6 +548,14 @@ class ParserBase : public Traits {
}
}
+ void ValidateFormalParameterInitializer(
+ const ExpressionClassifier* classifier, bool* ok) {
+ if (!classifier->is_valid_formal_parameter_initializer()) {
+ ReportClassifierError(classifier->formal_parameter_initializer_error());
+ *ok = false;
+ }
+ }
+
void ValidateBindingPattern(const ExpressionClassifier* classifier,
bool* ok) {
if (!classifier->is_valid_binding_pattern()) {
@@ -629,6 +637,15 @@ class ParserBase : public Traits {
message, arg);
}
+ void FormalParameterInitializerUnexpectedToken(
+ ExpressionClassifier* classifier) {
+ MessageTemplate::Template message = MessageTemplate::kUnexpectedToken;
+ const char* arg;
+ GetUnexpectedTokenMessage(peek(), &message, &arg);
+ classifier->RecordFormalParameterInitializerError(
+ scanner()->peek_location(), message, arg);
+ }
+
// Recursive descent functions:
// Parses an identifier that is valid for the current scope, in particular it
@@ -2522,7 +2539,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParsePropertyName(
ExpressionT expression =
ParseAssignmentExpression(true, &computed_name_classifier, CHECK_OK);
classifier->Accumulate(computed_name_classifier,
- ExpressionClassifier::ExpressionProduction);
+ ExpressionClassifier::ExpressionProductions);
Expect(Token::RBRACK, CHECK_OK);
return expression;
}
@@ -2668,7 +2685,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
ExpressionT rhs = this->ParseAssignmentExpression(
true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
classifier->Accumulate(rhs_classifier,
- ExpressionClassifier::ExpressionProduction);
+ ExpressionClassifier::ExpressionProductions);
value = factory()->NewAssignment(Token::ASSIGN, lhs, rhs,
RelocInfo::kNoPosition);
} else {
@@ -2910,7 +2927,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ExpressionT right =
this->ParseAssignmentExpression(accept_IN, &rhs_classifier, CHECK_OK);
classifier->Accumulate(rhs_classifier,
- ExpressionClassifier::ExpressionProduction);
+ ExpressionClassifier::ExpressionProductions);
// TODO(1231235): We try to estimate the set of properties set by
// constructors. We define a new property whenever there is an
@@ -2949,6 +2966,7 @@ ParserBase<Traits>::ParseYieldExpression(ExpressionClassifier* classifier,
// 'yield' ([no line terminator] '*'? AssignmentExpression)?
int pos = peek_position();
BindingPatternUnexpectedToken(classifier);
+ FormalParameterInitializerUnexpectedToken(classifier);
Expect(Token::YIELD, CHECK_OK);
ExpressionT generator_object =
factory()->NewVariableProxy(function_state_->generator_object_variable());
@@ -3676,6 +3694,8 @@ void ParserBase<Traits>::ParseFormalParameter(
return;
}
parameters->is_simple = false;
+ ValidateFormalParameterInitializer(classifier, ok);
+ if (!*ok) return;
classifier->RecordNonSimpleParameter();
}
@@ -3685,6 +3705,7 @@ void ParserBase<Traits>::ParseFormalParameter(
initializer = ParseAssignmentExpression(true, &init_classifier, ok);
if (!*ok) return;
ValidateExpression(&init_classifier, ok);
+ ValidateFormalParameterInitializer(&init_classifier, ok);
if (!*ok) return;
parameters->is_simple = false;
classifier->RecordNonSimpleParameter();
« no previous file with comments | « src/expression-classifier.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698