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

Unified Diff: src/preparser.cc

Issue 869293002: Lexical declarations should not be allowed in Statement (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update comment a bit Created 5 years, 11 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.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index 4d621c2dd9004c0a2b3434a8be2e561b42cfc1ee..6b9756dff0be8752e4db9a92481b0aaf70fa87b9 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -162,16 +162,22 @@ PreParserExpression PreParserTraits::ParseClassLiteral(
PreParser::Statement PreParser::ParseSourceElement(bool* ok) {
- // (Ecma 262 5th Edition, clause 14):
- // SourceElement:
- // Statement
- // FunctionDeclaration
+ // ECMA 262 6th Edition
+ // StatementListItem[Yield, Return] :
+ // Statement[?Yield, ?Return]
+ // Declaration[?Yield]
//
- // In harmony mode we allow additionally the following productions
- // SourceElement:
- // LetDeclaration
- // ConstDeclaration
- // GeneratorDeclaration
+ // Declaration[Yield] :
+ // HoistableDeclaration[?Yield]
+ // ClassDeclaration[?Yield]
+ // LexicalDeclaration[In, ?Yield]
+ //
+ // HoistableDeclaration[Yield, Default] :
+ // FunctionDeclaration[?Yield, ?Default]
+ // GeneratorDeclaration[?Yield, ?Default]
+ //
+ // LexicalDeclaration[In, Yield] :
+ // LetOrConst BindingList[?In, ?Yield] ;
switch (peek()) {
case Token::FUNCTION:
@@ -305,22 +311,21 @@ PreParser::Statement PreParser::ParseStatement(bool* ok) {
}
}
- case Token::CLASS:
- return ParseClassDeclaration(CHECK_OK);
-
case Token::DEBUGGER:
return ParseDebuggerStatement(ok);
case Token::VAR:
- case Token::CONST:
return ParseVariableStatement(kStatement, ok);
- case Token::LET:
- DCHECK(allow_harmony_scoping());
- if (strict_mode() == STRICT) {
+ case Token::CONST:
+ // In ES6 CONST is not allowed as a Statement , only as a
+ // LexicalDeclaration, however we continue to allow it in sloppy mode for
+ // backwards compatibility.
+ if (strict_mode() == SLOPPY) {
return ParseVariableStatement(kStatement, ok);
}
- // Fall through.
+
+ // Fall through.
default:
return ParseExpressionOrLabelledStatement(ok);
}
@@ -497,6 +502,22 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
// Expression ';'
// Identifier ':' Statement
+ switch (peek()) {
+ case Token::FUNCTION:
+ case Token::LBRACE:
+ UNREACHABLE(); // Always handled by the callers.
+ case Token::CLASS:
+ ReportUnexpectedToken(Next());
+ *ok = false;
+ return Statement::Default();
+
+ // TODO(arv): Handle `let [`
+ // https://code.google.com/p/v8/issues/detail?id=3847
+
+ default:
+ break;
+ }
+
bool starts_with_identifier = peek_any_identifier();
Expression expr = ParseExpression(true, CHECK_OK);
// Even if the expression starts with an identifier, it is not necessarily an
« src/parser.cc ('K') | « src/parser.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698