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

Unified Diff: src/preparser.h

Issue 1191303002: Better error reporting for "return();" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Only signal an error for nullary arrow functions 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 | « src/messages.h ('k') | test/message/arrow-missing.js » ('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 862b7fb40dd894b53dfcec80d36aedde5b441e3f..ce2c6c429239742a3cca7c4438f377a14c348111 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -502,7 +502,9 @@ class ParserBase : public Traits {
}
void ReportUnexpectedToken(Token::Value token);
- void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token);
+ void ReportUnexpectedTokenAt(
+ Scanner::Location location, Token::Value token,
+ MessageTemplate::Template message = MessageTemplate::kUnexpectedToken);
void ReportClassifierError(const ExpressionClassifier::Error& error) {
@@ -1814,10 +1816,10 @@ void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) {
}
-template<class Traits>
+template <class Traits>
void ParserBase<Traits>::ReportUnexpectedTokenAt(
- Scanner::Location source_location, Token::Value token) {
-
+ Scanner::Location source_location, Token::Value token,
+ MessageTemplate::Template message) {
// Four of the tokens are treated specially
switch (token) {
case Token::EOS:
@@ -1850,8 +1852,7 @@ void ParserBase<Traits>::ReportUnexpectedTokenAt(
default:
const char* name = Token::String(token);
DCHECK(name != NULL);
- Traits::ReportMessageAt(source_location,
- MessageTemplate::kUnexpectedToken, name);
+ Traits::ReportMessageAt(source_location, message, name);
}
}
@@ -2152,6 +2153,13 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
classifier->RecordBindingPatternError(scanner()->location(),
MessageTemplate::kUnexpectedToken,
Token::String(Token::RPAREN));
+ // Give a good error to the user who might have typed e.g. "return();".
+ if (peek() != Token::ARROW) {
+ ReportUnexpectedTokenAt(scanner_->peek_location(), peek(),
+ MessageTemplate::kMissingArrow);
+ *ok = false;
+ return this->EmptyExpression();
+ }
Scope* scope =
this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction);
scope->set_start_position(beg_pos);
« no previous file with comments | « src/messages.h ('k') | test/message/arrow-missing.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698