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

Side by Side Diff: src/preparser.cc

Issue 722203006: Disable classes in sloppy mode unless --harmony-sloppy is set (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Comments Created 6 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
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 is_generator ? FunctionKind::kGeneratorFunction 343 is_generator ? FunctionKind::kGeneratorFunction
344 : FunctionKind::kNormalFunction, 344 : FunctionKind::kNormalFunction,
345 pos, FunctionLiteral::DECLARATION, 345 pos, FunctionLiteral::DECLARATION,
346 FunctionLiteral::NORMAL_ARITY, CHECK_OK); 346 FunctionLiteral::NORMAL_ARITY, CHECK_OK);
347 return Statement::FunctionDeclaration(); 347 return Statement::FunctionDeclaration();
348 } 348 }
349 349
350 350
351 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) { 351 PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
352 Expect(Token::CLASS, CHECK_OK); 352 Expect(Token::CLASS, CHECK_OK);
353 if (!allow_harmony_sloppy() && strict_mode() == SLOPPY) {
354 ReportMessage("sloppy_lexical");
355 *ok = false;
356 return Statement::Default();
357 }
358
353 int pos = position(); 359 int pos = position();
354 bool is_strict_reserved = false; 360 bool is_strict_reserved = false;
355 Identifier name = 361 Identifier name =
356 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); 362 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK);
357 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos, 363 ParseClassLiteral(name, scanner()->location(), is_strict_reserved, pos,
358 CHECK_OK); 364 CHECK_OK);
359 return Statement::Default(); 365 return Statement::Default();
360 } 366 }
361 367
362 368
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 DCHECK(!expr.AsIdentifier().IsFutureReserved()); 508 DCHECK(!expr.AsIdentifier().IsFutureReserved());
503 DCHECK(strict_mode() == SLOPPY || 509 DCHECK(strict_mode() == SLOPPY ||
504 !IsFutureStrictReserved(expr.AsIdentifier())); 510 !IsFutureStrictReserved(expr.AsIdentifier()));
505 Consume(Token::COLON); 511 Consume(Token::COLON);
506 return ParseStatement(ok); 512 return ParseStatement(ok);
507 // Preparsing is disabled for extensions (because the extension details 513 // Preparsing is disabled for extensions (because the extension details
508 // aren't passed to lazily compiled functions), so we don't 514 // aren't passed to lazily compiled functions), so we don't
509 // accept "native function" in the preparser. 515 // accept "native function" in the preparser.
510 } 516 }
511 // Parsed expression statement. 517 // Parsed expression statement.
518 // Detect attempts at 'let' declarations in sloppy mode.
519 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
520 expr.IsIdentifier() && expr.AsIdentifier().IsLet()) {
521 ReportMessage("sloppy_lexical", NULL);
522 *ok = false;
523 return Statement::Default();
524 }
512 ExpectSemicolon(CHECK_OK); 525 ExpectSemicolon(CHECK_OK);
513 return Statement::ExpressionStatement(expr); 526 return Statement::ExpressionStatement(expr);
514 } 527 }
515 528
516 529
517 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { 530 PreParser::Statement PreParser::ParseIfStatement(bool* ok) {
518 // IfStatement :: 531 // IfStatement ::
519 // 'if' '(' Expression ')' Statement ('else' Statement)? 532 // 'if' '(' Expression ')' Statement ('else' Statement)?
520 533
521 Expect(Token::IF, CHECK_OK); 534 Expect(Token::IF, CHECK_OK);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 return false; 694 return false;
682 } 695 }
683 696
684 697
685 PreParser::Statement PreParser::ParseForStatement(bool* ok) { 698 PreParser::Statement PreParser::ParseForStatement(bool* ok) {
686 // ForStatement :: 699 // ForStatement ::
687 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement 700 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
688 701
689 Expect(Token::FOR, CHECK_OK); 702 Expect(Token::FOR, CHECK_OK);
690 Expect(Token::LPAREN, CHECK_OK); 703 Expect(Token::LPAREN, CHECK_OK);
704 bool is_let_identifier_expression = false;
691 if (peek() != Token::SEMICOLON) { 705 if (peek() != Token::SEMICOLON) {
692 if (peek() == Token::VAR || peek() == Token::CONST || 706 if (peek() == Token::VAR || peek() == Token::CONST ||
693 (peek() == Token::LET && strict_mode() == STRICT)) { 707 (peek() == Token::LET && strict_mode() == STRICT)) {
694 bool is_lexical = peek() == Token::LET || 708 bool is_lexical = peek() == Token::LET ||
695 (peek() == Token::CONST && strict_mode() == STRICT); 709 (peek() == Token::CONST && strict_mode() == STRICT);
696 int decl_count; 710 int decl_count;
697 VariableDeclarationProperties decl_props = kHasNoInitializers; 711 VariableDeclarationProperties decl_props = kHasNoInitializers;
698 ParseVariableDeclarations( 712 ParseVariableDeclarations(
699 kForStatement, &decl_props, &decl_count, CHECK_OK); 713 kForStatement, &decl_props, &decl_count, CHECK_OK);
700 bool has_initializers = decl_props == kHasInitializers; 714 bool has_initializers = decl_props == kHasInitializers;
701 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers); 715 bool accept_IN = decl_count == 1 && !(is_lexical && has_initializers);
702 bool accept_OF = !has_initializers; 716 bool accept_OF = !has_initializers;
703 if (accept_IN && CheckInOrOf(accept_OF)) { 717 if (accept_IN && CheckInOrOf(accept_OF)) {
704 ParseExpression(true, CHECK_OK); 718 ParseExpression(true, CHECK_OK);
705 Expect(Token::RPAREN, CHECK_OK); 719 Expect(Token::RPAREN, CHECK_OK);
706 720
707 ParseStatement(CHECK_OK); 721 ParseStatement(CHECK_OK);
708 return Statement::Default(); 722 return Statement::Default();
709 } 723 }
710 } else { 724 } else {
711 Expression lhs = ParseExpression(false, CHECK_OK); 725 Expression lhs = ParseExpression(false, CHECK_OK);
726 is_let_identifier_expression =
727 lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
712 if (CheckInOrOf(lhs.IsIdentifier())) { 728 if (CheckInOrOf(lhs.IsIdentifier())) {
713 ParseExpression(true, CHECK_OK); 729 ParseExpression(true, CHECK_OK);
714 Expect(Token::RPAREN, CHECK_OK); 730 Expect(Token::RPAREN, CHECK_OK);
715 731
716 ParseStatement(CHECK_OK); 732 ParseStatement(CHECK_OK);
717 return Statement::Default(); 733 return Statement::Default();
718 } 734 }
719 } 735 }
720 } 736 }
721 737
722 // Parsed initializer at this point. 738 // Parsed initializer at this point.
739 // Detect attempts at 'let' declarations in sloppy mode.
740 if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
741 is_let_identifier_expression) {
742 ReportMessage("sloppy_lexical", NULL);
743 *ok = false;
744 return Statement::Default();
745 }
723 Expect(Token::SEMICOLON, CHECK_OK); 746 Expect(Token::SEMICOLON, CHECK_OK);
724 747
725 if (peek() != Token::SEMICOLON) { 748 if (peek() != Token::SEMICOLON) {
726 ParseExpression(true, CHECK_OK); 749 ParseExpression(true, CHECK_OK);
727 } 750 }
728 Expect(Token::SEMICOLON, CHECK_OK); 751 Expect(Token::SEMICOLON, CHECK_OK);
729 752
730 if (peek() != Token::RPAREN) { 753 if (peek() != Token::RPAREN) {
731 ParseExpression(true, CHECK_OK); 754 ParseExpression(true, CHECK_OK);
732 } 755 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 Expect(Token::RBRACE, CHECK_OK); 997 Expect(Token::RBRACE, CHECK_OK);
975 998
976 return Expression::Default(); 999 return Expression::Default();
977 } 1000 }
978 1001
979 1002
980 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { 1003 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
981 // CallRuntime :: 1004 // CallRuntime ::
982 // '%' Identifier Arguments 1005 // '%' Identifier Arguments
983 Expect(Token::MOD, CHECK_OK); 1006 Expect(Token::MOD, CHECK_OK);
984 if (!allow_natives_syntax()) { 1007 if (!allow_natives()) {
985 *ok = false; 1008 *ok = false;
986 return Expression::Default(); 1009 return Expression::Default();
987 } 1010 }
988 // Allow "eval" or "arguments" for backward compatibility. 1011 // Allow "eval" or "arguments" for backward compatibility.
989 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1012 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
990 ParseArguments(ok); 1013 ParseArguments(ok);
991 1014
992 return Expression::Default(); 1015 return Expression::Default();
993 } 1016 }
994 1017
995 #undef CHECK_OK 1018 #undef CHECK_OK
996 1019
997 1020
998 } } // v8::internal 1021 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698