OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "src/allocation.h" | 7 #include "src/allocation.h" |
8 #include "src/base/logging.h" | 8 #include "src/base/logging.h" |
9 #include "src/conversions-inl.h" | 9 #include "src/conversions-inl.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // | 185 // |
186 // LexicalDeclaration[In, Yield] : | 186 // LexicalDeclaration[In, Yield] : |
187 // LetOrConst BindingList[?In, ?Yield] ; | 187 // LetOrConst BindingList[?In, ?Yield] ; |
188 | 188 |
189 switch (peek()) { | 189 switch (peek()) { |
190 case Token::FUNCTION: | 190 case Token::FUNCTION: |
191 return ParseFunctionDeclaration(ok); | 191 return ParseFunctionDeclaration(ok); |
192 case Token::CLASS: | 192 case Token::CLASS: |
193 return ParseClassDeclaration(ok); | 193 return ParseClassDeclaration(ok); |
194 case Token::CONST: | 194 case Token::CONST: |
195 return ParseVariableStatement(kStatementListItem, ok); | 195 if (allow_const()) { |
| 196 return ParseVariableStatement(kStatementListItem, ok); |
| 197 } |
| 198 break; |
196 case Token::LET: | 199 case Token::LET: |
197 if (is_strict(language_mode())) { | 200 if (is_strict(language_mode())) { |
198 return ParseVariableStatement(kStatementListItem, ok); | 201 return ParseVariableStatement(kStatementListItem, ok); |
199 } | 202 } |
200 // Fall through. | 203 break; |
201 default: | 204 default: |
202 return ParseStatement(ok); | 205 break; |
203 } | 206 } |
| 207 return ParseStatement(ok); |
204 } | 208 } |
205 | 209 |
206 | 210 |
207 void PreParser::ParseStatementList(int end_token, bool* ok, | 211 void PreParser::ParseStatementList(int end_token, bool* ok, |
208 Scanner::BookmarkScope* bookmark) { | 212 Scanner::BookmarkScope* bookmark) { |
209 // SourceElements :: | 213 // SourceElements :: |
210 // (Statement)* <end_token> | 214 // (Statement)* <end_token> |
211 | 215 |
212 // Bookkeeping for trial parse if bookmark is set: | 216 // Bookkeeping for trial parse if bookmark is set: |
213 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); | 217 DCHECK_IMPLIES(bookmark, bookmark->HasBeenSet()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 case Token::DEBUGGER: | 389 case Token::DEBUGGER: |
386 return ParseDebuggerStatement(ok); | 390 return ParseDebuggerStatement(ok); |
387 | 391 |
388 case Token::VAR: | 392 case Token::VAR: |
389 return ParseVariableStatement(kStatement, ok); | 393 return ParseVariableStatement(kStatement, ok); |
390 | 394 |
391 case Token::CONST: | 395 case Token::CONST: |
392 // In ES6 CONST is not allowed as a Statement, only as a | 396 // In ES6 CONST is not allowed as a Statement, only as a |
393 // LexicalDeclaration, however we continue to allow it in sloppy mode for | 397 // LexicalDeclaration, however we continue to allow it in sloppy mode for |
394 // backwards compatibility. | 398 // backwards compatibility. |
395 if (is_sloppy(language_mode())) { | 399 if (is_sloppy(language_mode()) && allow_legacy_const()) { |
396 return ParseVariableStatement(kStatement, ok); | 400 return ParseVariableStatement(kStatement, ok); |
397 } | 401 } |
398 | 402 |
399 // Fall through. | 403 // Fall through. |
400 default: | 404 default: |
401 return ParseExpressionOrLabelledStatement(ok); | 405 return ParseExpressionOrLabelledStatement(ok); |
402 } | 406 } |
403 } | 407 } |
404 | 408 |
405 | 409 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 bool require_initializer = false; | 505 bool require_initializer = false; |
502 bool is_strict_const = false; | 506 bool is_strict_const = false; |
503 if (peek() == Token::VAR) { | 507 if (peek() == Token::VAR) { |
504 if (is_strong(language_mode())) { | 508 if (is_strong(language_mode())) { |
505 Scanner::Location location = scanner()->peek_location(); | 509 Scanner::Location location = scanner()->peek_location(); |
506 ReportMessageAt(location, MessageTemplate::kStrongVar); | 510 ReportMessageAt(location, MessageTemplate::kStrongVar); |
507 *ok = false; | 511 *ok = false; |
508 return Statement::Default(); | 512 return Statement::Default(); |
509 } | 513 } |
510 Consume(Token::VAR); | 514 Consume(Token::VAR); |
511 } else if (peek() == Token::CONST) { | 515 } else if (peek() == Token::CONST && allow_const()) { |
512 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: | 516 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: |
513 // | 517 // |
514 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 518 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
515 // | 519 // |
516 // * It is a Syntax Error if the code that matches this production is not | 520 // * It is a Syntax Error if the code that matches this production is not |
517 // contained in extended code. | 521 // contained in extended code. |
518 // | 522 // |
519 // However disallowing const in sloppy mode will break compatibility with | 523 // However disallowing const in sloppy mode will break compatibility with |
520 // existing pages. Therefore we keep allowing const with the old | 524 // existing pages. Therefore we keep allowing const with the old |
521 // non-harmony semantics in sloppy mode. | 525 // non-harmony semantics in sloppy mode. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 861 |
858 PreParser::Statement PreParser::ParseForStatement(bool* ok) { | 862 PreParser::Statement PreParser::ParseForStatement(bool* ok) { |
859 // ForStatement :: | 863 // ForStatement :: |
860 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 864 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
861 | 865 |
862 Expect(Token::FOR, CHECK_OK); | 866 Expect(Token::FOR, CHECK_OK); |
863 Expect(Token::LPAREN, CHECK_OK); | 867 Expect(Token::LPAREN, CHECK_OK); |
864 bool is_let_identifier_expression = false; | 868 bool is_let_identifier_expression = false; |
865 if (peek() != Token::SEMICOLON) { | 869 if (peek() != Token::SEMICOLON) { |
866 ForEachStatement::VisitMode mode; | 870 ForEachStatement::VisitMode mode; |
867 if (peek() == Token::VAR || peek() == Token::CONST || | 871 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || |
868 (peek() == Token::LET && is_strict(language_mode()))) { | 872 (peek() == Token::LET && is_strict(language_mode()))) { |
869 int decl_count; | 873 int decl_count; |
870 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); | 874 Scanner::Location first_initializer_loc = Scanner::Location::invalid(); |
871 Scanner::Location bindings_loc = Scanner::Location::invalid(); | 875 Scanner::Location bindings_loc = Scanner::Location::invalid(); |
872 ParseVariableDeclarations(kForStatement, &decl_count, | 876 ParseVariableDeclarations(kForStatement, &decl_count, |
873 &first_initializer_loc, &bindings_loc, | 877 &first_initializer_loc, &bindings_loc, |
874 CHECK_OK); | 878 CHECK_OK); |
875 bool accept_IN = decl_count >= 1; | 879 bool accept_IN = decl_count >= 1; |
876 bool accept_OF = true; | 880 bool accept_OF = true; |
877 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { | 881 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 | 1192 |
1189 DCHECK(!spread_pos.IsValid()); | 1193 DCHECK(!spread_pos.IsValid()); |
1190 | 1194 |
1191 return Expression::Default(); | 1195 return Expression::Default(); |
1192 } | 1196 } |
1193 | 1197 |
1194 #undef CHECK_OK | 1198 #undef CHECK_OK |
1195 | 1199 |
1196 | 1200 |
1197 } } // v8::internal | 1201 } } // v8::internal |
OLD | NEW |