Better error message for eval=>42 in strict mode

BUG=v8:4213
R=arv@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1210003003

Cr-Commit-Position: refs/heads/master@{#29299}
This commit is contained in:
wingo 2015-06-25 09:17:06 -07:00 committed by Commit bot
parent efbb4c6cdc
commit 87fd436670
2 changed files with 15 additions and 8 deletions

View File

@ -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);

View File

@ -1,4 +1,4 @@
*%(basename)s:8: SyntaxError: Unexpected identifier
*%(basename)s:8: SyntaxError: Unexpected eval or arguments in strict mode
eval => 42
^^^^
SyntaxError: Unexpected identifier
SyntaxError: Unexpected eval or arguments in strict mode