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

Unified Diff: src/preparser.h

Issue 1210003003: Better error message for eval=>42 in strict mode (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 6 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 | « no previous file | test/message/arrow-strict-eval-bare-parameter.out » ('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 0653ded54a9522bf4a68e146456680ff24b29bf2..272b429be53ae5e7bd2bdfbcec6833f1da8020af 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -560,7 +560,8 @@ class ParserBase : public Traits {
}
void ValidateArrowFormalParameters(const ExpressionClassifier* classifier,
- ExpressionT expr, bool* ok) {
+ ExpressionT expr,
+ bool parenthesized_formals, bool* ok) {
if (classifier->is_valid_binding_pattern()) {
// A simple arrow formal parameter: IDENTIFIER => BODY.
if (!this->IsIdentifier(expr)) {
@@ -570,7 +571,14 @@ class ParserBase : public Traits {
*ok = false;
}
} else if (!classifier->is_valid_arrow_formal_parameters()) {
- ReportClassifierError(classifier->arrow_formal_parameters_error());
+ // If after parsing the expr, we see an error but the expression is
+ // neither a valid binding pattern nor a valid parenthesized formal
+ // parameter list, show the "arrow formal parameters" error if the formals
+ // started with a parenthesis, and the binding pattern error otherwise.
+ const ExpressionClassifier::Error& error =
+ parenthesized_formals ? classifier->arrow_formal_parameters_error()
+ : classifier->binding_pattern_error();
+ ReportClassifierError(error);
*ok = false;
}
}
@@ -2763,9 +2771,8 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
if (fni_ != NULL) fni_->Enter();
ParserBase<Traits>::Checkpoint checkpoint(this);
ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder());
- if (peek() != Token::LPAREN) {
- // The expression we are going to read is not a parenthesized arrow function
- // formal parameter list.
+ bool parenthesized_formals = peek() == Token::LPAREN;
+ if (!parenthesized_formals) {
ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier);
}
ExpressionT expression = this->ParseConditionalExpression(
@@ -2775,7 +2782,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
checkpoint.Restore();
BindingPatternUnexpectedToken(classifier);
ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
- CHECK_OK);
+ parenthesized_formals, CHECK_OK);
Scanner::Location loc(lhs_location.beg_pos, scanner()->location().end_pos);
Scope* scope =
this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
« no previous file with comments | « no previous file | test/message/arrow-strict-eval-bare-parameter.out » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698