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

Unified Diff: src/preparser.h

Issue 1191303002: Better error reporting for "return();" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: "we want to give a good arrow" -> "error" 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
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 862b7fb40dd894b53dfcec80d36aedde5b441e3f..238fb89ac8c9b6a9afece0a03c638fa3ce064e07 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);
}
}
@@ -3610,7 +3611,17 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
FunctionState function_state(&function_state_, &scope_, scope,
kArrowFunction, &function_factory);
- Expect(Token::ARROW, CHECK_OK);
+ // ParseArrowFunctionLiteral can be called in two ways: after seeing a
+ // formal parameter list that *must* be followed by an arrow, to wit "()" or
+ // "(...x)", or after reading a comma expression that is followed by =>. In
+ // the former cases we want to give a good error to the user who might have
+ // typed e.g. "return();".
+ if (!Check(Token::ARROW)) {
+ ReportUnexpectedTokenAt(scanner_->peek_location(), peek(),
+ MessageTemplate::kMissingArrow);
+ *ok = false;
+ return this->EmptyExpression();
+ }
if (peek() == Token::LBRACE) {
// Multiple statement body
« src/messages.h ('K') | « src/messages.h ('k') | test/message/arrow-missing.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698