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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 : MessageTemplate::kSloppyFunction); | 364 : MessageTemplate::kSloppyFunction); |
365 *ok = false; | 365 *ok = false; |
366 return Statement::Default(); | 366 return Statement::Default(); |
367 | 367 |
368 case Token::DEBUGGER: | 368 case Token::DEBUGGER: |
369 return ParseDebuggerStatement(ok); | 369 return ParseDebuggerStatement(ok); |
370 | 370 |
371 case Token::VAR: | 371 case Token::VAR: |
372 return ParseVariableStatement(kStatement, ok); | 372 return ParseVariableStatement(kStatement, ok); |
373 | 373 |
374 case Token::CONST: | |
375 // In ES6 CONST is not allowed as a Statement, only as a | |
376 // LexicalDeclaration, however we continue to allow it in sloppy mode for | |
377 // backwards compatibility. | |
378 if (is_sloppy(language_mode()) && allow_legacy_const()) { | |
379 return ParseVariableStatement(kStatement, ok); | |
380 } | |
381 | |
382 // Fall through. | |
383 default: | 374 default: |
384 return ParseExpressionOrLabelledStatement(ok); | 375 return ParseExpressionOrLabelledStatement(ok); |
385 } | 376 } |
386 } | 377 } |
387 | 378 |
388 | 379 |
389 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 380 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
390 // FunctionDeclaration :: | 381 // FunctionDeclaration :: |
391 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' | 382 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}' |
392 // GeneratorDeclaration :: | 383 // GeneratorDeclaration :: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // | 477 // |
487 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' | 478 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
488 // | 479 // |
489 // * It is a Syntax Error if the code that matches this production is not | 480 // * It is a Syntax Error if the code that matches this production is not |
490 // contained in extended code. | 481 // contained in extended code. |
491 // | 482 // |
492 // However disallowing const in sloppy mode will break compatibility with | 483 // However disallowing const in sloppy mode will break compatibility with |
493 // existing pages. Therefore we keep allowing const with the old | 484 // existing pages. Therefore we keep allowing const with the old |
494 // non-harmony semantics in sloppy mode. | 485 // non-harmony semantics in sloppy mode. |
495 Consume(Token::CONST); | 486 Consume(Token::CONST); |
496 if (is_strict(language_mode()) || | 487 if (is_strict(language_mode()) || allow_harmony_sloppy()) { |
497 (allow_harmony_sloppy() && !allow_legacy_const())) { | |
498 DCHECK(var_context != kStatement); | 488 DCHECK(var_context != kStatement); |
499 require_initializer = true; | 489 require_initializer = true; |
500 lexical = true; | 490 lexical = true; |
501 } | 491 } |
502 } else if (peek() == Token::LET && allow_let()) { | 492 } else if (peek() == Token::LET && allow_let()) { |
503 Consume(Token::LET); | 493 Consume(Token::LET); |
504 DCHECK(var_context != kStatement); | 494 DCHECK(var_context != kStatement); |
505 lexical = true; | 495 lexical = true; |
506 } else { | 496 } else { |
507 *ok = false; | 497 *ok = false; |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 Expect(Token::RBRACE, CHECK_OK); | 1146 Expect(Token::RBRACE, CHECK_OK); |
1157 return PreParserExpression::Default(); | 1147 return PreParserExpression::Default(); |
1158 } | 1148 } |
1159 } | 1149 } |
1160 | 1150 |
1161 #undef CHECK_OK | 1151 #undef CHECK_OK |
1162 | 1152 |
1163 | 1153 |
1164 } // namespace internal | 1154 } // namespace internal |
1165 } // namespace v8 | 1155 } // namespace v8 |
OLD | NEW |