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

Unified Diff: src/parser.cc

Issue 8564001: Make let/const outside of the extended mode early errors (under harmony flag). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments and adapt preparser. Created 9 years, 1 month 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/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index de4457c3dd991b3ab36bc54ff16024000608a66c..b3b01109d72d599deb598733f2fc5fd00730ba90 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1263,6 +1263,7 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
return ParseBlock(labels, ok);
case Token::CONST: // fall through
+ case Token::LET:
case Token::VAR:
stmt = ParseVariableStatement(kStatement, ok);
break;
@@ -1690,6 +1691,16 @@ Block* Parser::ParseVariableDeclarations(
if (peek() == Token::VAR) {
Consume(Token::VAR);
} else if (peek() == Token::CONST) {
+ // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads:
+ //
+ // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';'
+ //
+ // * It is a Syntax Error if the code that matches this production is not
+ // contained in extended code.
+ //
+ // However disallowing const in classic mode will break compatibility with
+ // existing pages. Therefore we keep allowing const with the old
+ // non-harmony semantics in classic mode.
Consume(Token::CONST);
switch (top_scope_->language_mode()) {
case CLASSIC_MODE:
@@ -1715,7 +1726,17 @@ Block* Parser::ParseVariableDeclarations(
is_const = true;
needs_init = true;
} else if (peek() == Token::LET) {
- ASSERT(top_scope_->is_extended_mode());
+ // ES6 Draft Rev4 section 12.2.1:
+ //
+ // LetDeclaration : let LetBindingList ;
+ //
+ // * It is a Syntax Error if the code that matches this production is not
+ // contained in extended code.
+ if (!is_extended_mode()) {
+ ReportMessage("illegal_let", Vector<const char*>::empty());
+ *ok = false;
+ return NULL;
+ }
Consume(Token::LET);
if (var_context != kSourceElement &&
var_context != kForStatement) {
« no previous file with comments | « src/messages.js ('k') | src/preparser.cc » ('j') | test/mjsunit/harmony/block-early-errors.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698