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

Side by Side Diff: src/parsing/preparser.cc

Issue 1723313002: [parser] Enforce module-specific identifier restriction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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
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 20 matching lines...) Expand all
31 31
32 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos, 32 void PreParserTraits::ReportMessageAt(int start_pos, int end_pos,
33 MessageTemplate::Template message, 33 MessageTemplate::Template message,
34 const char* arg, 34 const char* arg,
35 ParseErrorType error_type) { 35 ParseErrorType error_type) {
36 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type); 36 pre_parser_->log_->LogMessage(start_pos, end_pos, message, arg, error_type);
37 } 37 }
38 38
39 39
40 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) { 40 PreParserIdentifier PreParserTraits::GetSymbol(Scanner* scanner) {
41 if (scanner->current_token() == Token::FUTURE_RESERVED_WORD) { 41 if (scanner->current_token() == Token::ENUM) {
42 return PreParserIdentifier::FutureReserved(); 42 return PreParserIdentifier::Enum();
43 } else if (scanner->current_token() == Token::AWAIT) {
44 return PreParserIdentifier::Await();
43 } else if (scanner->current_token() == 45 } else if (scanner->current_token() ==
44 Token::FUTURE_STRICT_RESERVED_WORD) { 46 Token::FUTURE_STRICT_RESERVED_WORD) {
45 return PreParserIdentifier::FutureStrictReserved(); 47 return PreParserIdentifier::FutureStrictReserved();
46 } else if (scanner->current_token() == Token::LET) { 48 } else if (scanner->current_token() == Token::LET) {
47 return PreParserIdentifier::Let(); 49 return PreParserIdentifier::Let();
48 } else if (scanner->current_token() == Token::STATIC) { 50 } else if (scanner->current_token() == Token::STATIC) {
49 return PreParserIdentifier::Static(); 51 return PreParserIdentifier::Static();
50 } else if (scanner->current_token() == Token::YIELD) { 52 } else if (scanner->current_token() == Token::YIELD) {
51 return PreParserIdentifier::Yield(); 53 return PreParserIdentifier::Yield();
52 } 54 }
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 ExpressionClassifier classifier(this); 689 ExpressionClassifier classifier(this);
688 Expression expr = ParseExpression(true, &classifier, CHECK_OK); 690 Expression expr = ParseExpression(true, &classifier, CHECK_OK);
689 ValidateExpression(&classifier, CHECK_OK); 691 ValidateExpression(&classifier, CHECK_OK);
690 692
691 // Even if the expression starts with an identifier, it is not necessarily an 693 // Even if the expression starts with an identifier, it is not necessarily an
692 // identifier. For example, "foo + bar" starts with an identifier but is not 694 // identifier. For example, "foo + bar" starts with an identifier but is not
693 // an identifier. 695 // an identifier.
694 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) { 696 if (starts_with_identifier && expr.IsIdentifier() && peek() == Token::COLON) {
695 // Expression is a single identifier, and not, e.g., a parenthesized 697 // Expression is a single identifier, and not, e.g., a parenthesized
696 // identifier. 698 // identifier.
697 DCHECK(!expr.AsIdentifier().IsFutureReserved());
mike3 2016/02/23 19:29:44 I'm not convinced that removing this check outrigh
adamk 2016/02/23 22:37:15 "DCHECK" is the V8 equivalent of "assert": it's no
mike3 2016/02/24 16:20:54 Acknowledged.
698 DCHECK(is_sloppy(language_mode()) || 699 DCHECK(is_sloppy(language_mode()) ||
699 !IsFutureStrictReserved(expr.AsIdentifier())); 700 !IsFutureStrictReserved(expr.AsIdentifier()));
700 Consume(Token::COLON); 701 Consume(Token::COLON);
701 Statement statement = ParseStatement(ok); 702 Statement statement = ParseStatement(ok);
702 return statement.IsJumpStatement() ? Statement::Default() : statement; 703 return statement.IsJumpStatement() ? Statement::Default() : statement;
703 // Preparsing is disabled for extensions (because the extension details 704 // Preparsing is disabled for extensions (because the extension details
704 // aren't passed to lazily compiled functions), so we don't 705 // aren't passed to lazily compiled functions), so we don't
705 // accept "native function" in the preparser. 706 // accept "native function" in the preparser.
706 } 707 }
707 // Parsed expression statement. 708 // Parsed expression statement.
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 Expect(Token::RBRACE, CHECK_OK); 1283 Expect(Token::RBRACE, CHECK_OK);
1283 return PreParserExpression::Default(); 1284 return PreParserExpression::Default();
1284 } 1285 }
1285 } 1286 }
1286 1287
1287 #undef CHECK_OK 1288 #undef CHECK_OK
1288 1289
1289 1290
1290 } // namespace internal 1291 } // namespace internal
1291 } // namespace v8 1292 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698