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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 // parsed into an empty statement. 1256 // parsed into an empty statement.
1257 1257
1258 // Keep the source position of the statement 1258 // Keep the source position of the statement
1259 int statement_pos = scanner().peek_location().beg_pos; 1259 int statement_pos = scanner().peek_location().beg_pos;
1260 Statement* stmt = NULL; 1260 Statement* stmt = NULL;
1261 switch (peek()) { 1261 switch (peek()) {
1262 case Token::LBRACE: 1262 case Token::LBRACE:
1263 return ParseBlock(labels, ok); 1263 return ParseBlock(labels, ok);
1264 1264
1265 case Token::CONST: // fall through 1265 case Token::CONST: // fall through
1266 case Token::LET:
1266 case Token::VAR: 1267 case Token::VAR:
1267 stmt = ParseVariableStatement(kStatement, ok); 1268 stmt = ParseVariableStatement(kStatement, ok);
1268 break; 1269 break;
1269 1270
1270 case Token::SEMICOLON: 1271 case Token::SEMICOLON:
1271 Next(); 1272 Next();
1272 return EmptyStatement(); 1273 return EmptyStatement();
1273 1274
1274 case Token::IF: 1275 case Token::IF:
1275 stmt = ParseIfStatement(labels, ok); 1276 stmt = ParseIfStatement(labels, ok);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 // True if the binding needs initialization. 'let' and 'const' declared 1684 // True if the binding needs initialization. 'let' and 'const' declared
1684 // bindings are created uninitialized by their declaration nodes and 1685 // bindings are created uninitialized by their declaration nodes and
1685 // need initialization. 'var' declared bindings are always initialized 1686 // need initialization. 'var' declared bindings are always initialized
1686 // immediately by their declaration nodes. 1687 // immediately by their declaration nodes.
1687 bool needs_init = false; 1688 bool needs_init = false;
1688 bool is_const = false; 1689 bool is_const = false;
1689 Token::Value init_op = Token::INIT_VAR; 1690 Token::Value init_op = Token::INIT_VAR;
1690 if (peek() == Token::VAR) { 1691 if (peek() == Token::VAR) {
1691 Consume(Token::VAR); 1692 Consume(Token::VAR);
1692 } else if (peek() == Token::CONST) { 1693 } else if (peek() == Token::CONST) {
1694 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads:
1695 //
1696 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';'
1697 //
1698 // * It is a Syntax Error if the code that matches this production is not
1699 // contained in extended code.
1700 //
1701 // However disallowing const in classic mode will break compatibility with
1702 // existing pages. Therefore we keep allowing const with the old
1703 // non-harmony semantics in classic mode.
1693 Consume(Token::CONST); 1704 Consume(Token::CONST);
1694 switch (top_scope_->language_mode()) { 1705 switch (top_scope_->language_mode()) {
1695 case CLASSIC_MODE: 1706 case CLASSIC_MODE:
1696 mode = CONST; 1707 mode = CONST;
1697 init_op = Token::INIT_CONST; 1708 init_op = Token::INIT_CONST;
1698 break; 1709 break;
1699 case STRICT_MODE: 1710 case STRICT_MODE:
1700 ReportMessage("strict_const", Vector<const char*>::empty()); 1711 ReportMessage("strict_const", Vector<const char*>::empty());
1701 *ok = false; 1712 *ok = false;
1702 return NULL; 1713 return NULL;
1703 case EXTENDED_MODE: 1714 case EXTENDED_MODE:
1704 if (var_context != kSourceElement && 1715 if (var_context != kSourceElement &&
1705 var_context != kForStatement) { 1716 var_context != kForStatement) {
1706 // In extended mode 'const' declarations are only allowed in source 1717 // In extended mode 'const' declarations are only allowed in source
1707 // element positions. 1718 // element positions.
1708 ReportMessage("unprotected_const", Vector<const char*>::empty()); 1719 ReportMessage("unprotected_const", Vector<const char*>::empty());
1709 *ok = false; 1720 *ok = false;
1710 return NULL; 1721 return NULL;
1711 } 1722 }
1712 mode = CONST_HARMONY; 1723 mode = CONST_HARMONY;
1713 init_op = Token::INIT_CONST_HARMONY; 1724 init_op = Token::INIT_CONST_HARMONY;
1714 } 1725 }
1715 is_const = true; 1726 is_const = true;
1716 needs_init = true; 1727 needs_init = true;
1717 } else if (peek() == Token::LET) { 1728 } else if (peek() == Token::LET) {
1718 ASSERT(top_scope_->is_extended_mode()); 1729 // ES6 Draft Rev4 section 12.2.1:
1730 //
1731 // LetDeclaration : let LetBindingList ;
1732 //
1733 // * It is a Syntax Error if the code that matches this production is not
1734 // contained in extended code.
1735 if (!is_extended_mode()) {
1736 ReportMessage("illegal_let", Vector<const char*>::empty());
1737 *ok = false;
1738 return NULL;
1739 }
1719 Consume(Token::LET); 1740 Consume(Token::LET);
1720 if (var_context != kSourceElement && 1741 if (var_context != kSourceElement &&
1721 var_context != kForStatement) { 1742 var_context != kForStatement) {
1722 // Let declarations are only allowed in source element positions. 1743 // Let declarations are only allowed in source element positions.
1723 ASSERT(var_context == kStatement); 1744 ASSERT(var_context == kStatement);
1724 ReportMessage("unprotected_let", Vector<const char*>::empty()); 1745 ReportMessage("unprotected_let", Vector<const char*>::empty());
1725 *ok = false; 1746 *ok = false;
1726 return NULL; 1747 return NULL;
1727 } 1748 }
1728 mode = LET; 1749 mode = LET;
(...skipping 3710 matching lines...) Expand 10 before | Expand all | Expand 10 after
5439 result = parser.ParseProgram(source, 5460 result = parser.ParseProgram(source,
5440 info->is_global(), 5461 info->is_global(),
5441 info->language_mode()); 5462 info->language_mode());
5442 } 5463 }
5443 } 5464 }
5444 info->SetFunction(result); 5465 info->SetFunction(result);
5445 return (result != NULL); 5466 return (result != NULL);
5446 } 5467 }
5447 5468
5448 } } // namespace v8::internal 5469 } } // namespace v8::internal
OLDNEW
« 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