Chromium Code Reviews| Index: src/parser.cc |
| diff --git a/src/parser.cc b/src/parser.cc |
| index d795b3ce166ae54af87e623553386faf888cc25f..55b4122d71f8cbcccc2d04e8c5d494ef01e508a1 100644 |
| --- a/src/parser.cc |
| +++ b/src/parser.cc |
| @@ -919,6 +919,7 @@ Parser::Parser(ParseInfo* info) |
| set_allow_harmony_spread_arrays(FLAG_harmony_spread_arrays); |
| set_allow_harmony_new_target(FLAG_harmony_new_target); |
| set_allow_strong_mode(FLAG_strong_mode); |
| + set_allow_legacy_const(FLAG_legacy_const); |
| for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| ++feature) { |
| use_counts_[feature] = 0; |
| @@ -1379,16 +1380,21 @@ Statement* Parser::ParseStatementListItem(bool* ok) { |
| } |
| return ParseClassDeclaration(NULL, ok); |
| case Token::CONST: |
| + if (allow_const()) { |
| + return ParseVariableStatement(kStatementListItem, NULL, ok); |
| + } |
|
Dan Ehrenberg
2015/07/06 21:26:12
Do we want to interpret const as a variable (like
arv (Not doing code reviews)
2015/07/06 21:35:24
It should do that already since CONST is a keyword
|
| + break; |
| case Token::VAR: |
| return ParseVariableStatement(kStatementListItem, NULL, ok); |
| case Token::LET: |
| if (is_strict(language_mode())) { |
| return ParseVariableStatement(kStatementListItem, NULL, ok); |
| } |
| - // Fall through. |
| + break; |
| default: |
| - return ParseStatement(NULL, ok); |
| + break; |
| } |
| + return ParseStatement(NULL, ok); |
| } |
| @@ -1937,7 +1943,7 @@ Statement* Parser::ParseSubStatement(ZoneList<const AstRawString*>* labels, |
| // 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 (is_sloppy(language_mode())) { |
| + if (is_sloppy(language_mode()) && allow_legacy_const()) { |
| return ParseVariableStatement(kStatement, NULL, ok); |
| } |
| @@ -2426,13 +2432,14 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context, |
| return; |
| } |
| Consume(Token::VAR); |
| - } else if (peek() == Token::CONST) { |
| + } else if (peek() == Token::CONST && allow_const()) { |
|
Dan Ehrenberg
2015/07/06 21:26:12
How do we interpret the const token if const is no
arv (Not doing code reviews)
2015/07/06 21:35:24
The code is unreachable. The callers peek already.
|
| Consume(Token::CONST); |
| - if (is_sloppy(language_mode())) { |
| + if (is_sloppy(language_mode()) && allow_legacy_const()) { |
| parsing_result->descriptor.mode = CONST_LEGACY; |
| parsing_result->descriptor.init_op = Token::INIT_CONST_LEGACY; |
| ++use_counts_[v8::Isolate::kLegacyConst]; |
| } else { |
| + DCHECK(is_strict(language_mode())); |
| DCHECK(var_context != kStatement); |
| parsing_result->descriptor.mode = CONST; |
| parsing_result->descriptor.init_op = Token::INIT_CONST; |
| @@ -3490,7 +3497,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| bool is_let_identifier_expression = false; |
| DeclarationParsingResult parsing_result; |
| if (peek() != Token::SEMICOLON) { |
| - if (peek() == Token::VAR || peek() == Token::CONST || |
| + if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || |
| (peek() == Token::LET && is_strict(language_mode()))) { |
| ParseVariableDeclarations(kForStatement, &parsing_result, CHECK_OK); |
| is_const = parsing_result.descriptor.mode == CONST; |
| @@ -3531,8 +3538,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| Block* init_block = nullptr; |
| // special case for legacy for (var/const x =.... in) |
| - if (is_sloppy(language_mode()) && |
| - !IsLexicalVariableMode(parsing_result.descriptor.mode) && |
| + if (!IsLexicalVariableMode(parsing_result.descriptor.mode) && |
| parsing_result.declarations[0].initializer != nullptr) { |
| VariableProxy* single_var = scope_->NewUnresolved( |
| factory(), parsing_result.SingleName(), Variable::NORMAL, |
| @@ -3615,8 +3621,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels, |
| } |
| // Create a TDZ for any lexically-bound names. |
| - if (is_strict(language_mode()) && |
| - IsLexicalVariableMode(parsing_result.descriptor.mode)) { |
| + if (IsLexicalVariableMode(parsing_result.descriptor.mode)) { |
| DCHECK_NULL(init_block); |
| init_block = |