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

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

Issue 1723313002: [parser] Enforce module-specific identifier restriction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Relax assertion criteria Created 4 years, 7 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 "src/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 916
917 // Enter 'scope' with the given parsing mode. 917 // Enter 'scope' with the given parsing mode.
918 ParsingModeScope parsing_mode_scope(this, parsing_mode); 918 ParsingModeScope parsing_mode_scope(this, parsing_mode);
919 AstNodeFactory function_factory(ast_value_factory()); 919 AstNodeFactory function_factory(ast_value_factory());
920 FunctionState function_state(&function_state_, &scope_, scope, 920 FunctionState function_state(&function_state_, &scope_, scope,
921 kNormalFunction, &function_factory); 921 kNormalFunction, &function_factory);
922 922
923 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 923 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
924 bool ok = true; 924 bool ok = true;
925 int beg_pos = scanner()->location().beg_pos; 925 int beg_pos = scanner()->location().beg_pos;
926 if (info->is_module()) { 926 parsing_module_ = info->is_module();
927 if (parsing_module_) {
927 ParseModuleItemList(body, &ok); 928 ParseModuleItemList(body, &ok);
928 } else { 929 } else {
929 // Don't count the mode in the use counters--give the program a chance 930 // Don't count the mode in the use counters--give the program a chance
930 // to enable script-wide strict mode below. 931 // to enable script-wide strict mode below.
931 scope_->SetLanguageMode(info->language_mode()); 932 scope_->SetLanguageMode(info->language_mode());
932 ParseStatementList(body, Token::EOS, &ok); 933 ParseStatementList(body, Token::EOS, &ok);
933 } 934 }
934 935
935 // The parser will peek but not consume EOS. Our scope logically goes all 936 // The parser will peek but not consume EOS. Our scope logically goes all
936 // the way to the EOS, though. 937 // the way to the EOS, though.
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 // IdentifierName 1352 // IdentifierName
1352 // IdentifierName 'as' IdentifierName 1353 // IdentifierName 'as' IdentifierName
1353 1354
1354 Expect(Token::LBRACE, CHECK_OK); 1355 Expect(Token::LBRACE, CHECK_OK);
1355 1356
1356 Token::Value name_tok; 1357 Token::Value name_tok;
1357 while ((name_tok = peek()) != Token::RBRACE) { 1358 while ((name_tok = peek()) != Token::RBRACE) {
1358 // Keep track of the first reserved word encountered in case our 1359 // Keep track of the first reserved word encountered in case our
1359 // caller needs to report an error. 1360 // caller needs to report an error.
1360 if (!reserved_loc->IsValid() && 1361 if (!reserved_loc->IsValid() &&
1361 !Token::IsIdentifier(name_tok, STRICT, false)) { 1362 !Token::IsIdentifier(name_tok, STRICT, false, parsing_module_)) {
1362 *reserved_loc = scanner()->location(); 1363 *reserved_loc = scanner()->location();
1363 } 1364 }
1364 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); 1365 const AstRawString* local_name = ParseIdentifierName(CHECK_OK);
1365 const AstRawString* export_name = NULL; 1366 const AstRawString* export_name = NULL;
1366 if (CheckContextualKeyword(CStrVector("as"))) { 1367 if (CheckContextualKeyword(CStrVector("as"))) {
1367 export_name = ParseIdentifierName(CHECK_OK); 1368 export_name = ParseIdentifierName(CHECK_OK);
1368 } 1369 }
1369 if (export_name == NULL) { 1370 if (export_name == NULL) {
1370 export_name = local_name; 1371 export_name = local_name;
1371 } 1372 }
(...skipping 30 matching lines...) Expand all
1402 new (zone()) ZoneList<ImportDeclaration*>(1, zone()); 1403 new (zone()) ZoneList<ImportDeclaration*>(1, zone());
1403 while (peek() != Token::RBRACE) { 1404 while (peek() != Token::RBRACE) {
1404 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); 1405 const AstRawString* import_name = ParseIdentifierName(CHECK_OK);
1405 const AstRawString* local_name = import_name; 1406 const AstRawString* local_name = import_name;
1406 // In the presence of 'as', the left-side of the 'as' can 1407 // In the presence of 'as', the left-side of the 'as' can
1407 // be any IdentifierName. But without 'as', it must be a valid 1408 // be any IdentifierName. But without 'as', it must be a valid
1408 // BindingIdentifier. 1409 // BindingIdentifier.
1409 if (CheckContextualKeyword(CStrVector("as"))) { 1410 if (CheckContextualKeyword(CStrVector("as"))) {
1410 local_name = ParseIdentifierName(CHECK_OK); 1411 local_name = ParseIdentifierName(CHECK_OK);
1411 } 1412 }
1412 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { 1413 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false,
1414 parsing_module_)) {
1413 *ok = false; 1415 *ok = false;
1414 ReportMessage(MessageTemplate::kUnexpectedReserved); 1416 ReportMessage(MessageTemplate::kUnexpectedReserved);
1415 return NULL; 1417 return NULL;
1416 } else if (IsEvalOrArguments(local_name)) { 1418 } else if (IsEvalOrArguments(local_name)) {
1417 *ok = false; 1419 *ok = false;
1418 ReportMessage(MessageTemplate::kStrictEvalArguments); 1420 ReportMessage(MessageTemplate::kStrictEvalArguments);
1419 return NULL; 1421 return NULL;
1420 } 1422 }
1421 VariableProxy* proxy = NewUnresolved(local_name, CONST); 1423 VariableProxy* proxy = NewUnresolved(local_name, CONST);
1422 ImportDeclaration* declaration = 1424 ImportDeclaration* declaration =
(...skipping 3191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4614 SET_ALLOW(harmony_do_expressions); 4616 SET_ALLOW(harmony_do_expressions);
4615 SET_ALLOW(harmony_for_in); 4617 SET_ALLOW(harmony_for_in);
4616 SET_ALLOW(harmony_function_name); 4618 SET_ALLOW(harmony_function_name);
4617 SET_ALLOW(harmony_function_sent); 4619 SET_ALLOW(harmony_function_sent);
4618 SET_ALLOW(harmony_exponentiation_operator); 4620 SET_ALLOW(harmony_exponentiation_operator);
4619 SET_ALLOW(harmony_restrictive_declarations); 4621 SET_ALLOW(harmony_restrictive_declarations);
4620 #undef SET_ALLOW 4622 #undef SET_ALLOW
4621 } 4623 }
4622 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( 4624 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
4623 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), 4625 language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
4624 logger, bookmark, use_counts_); 4626 parsing_module_, logger, bookmark, use_counts_);
4625 if (pre_parse_timer_ != NULL) { 4627 if (pre_parse_timer_ != NULL) {
4626 pre_parse_timer_->Stop(); 4628 pre_parse_timer_->Stop();
4627 } 4629 }
4628 return result; 4630 return result;
4629 } 4631 }
4630 4632
4631 4633
4632 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, 4634 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name,
4633 Scanner::Location class_name_location, 4635 Scanner::Location class_name_location,
4634 bool name_is_strict_reserved, int pos, 4636 bool name_is_strict_reserved, int pos,
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
6808 try_block, target); 6810 try_block, target);
6809 final_loop = target; 6811 final_loop = target;
6810 } 6812 }
6811 6813
6812 return final_loop; 6814 return final_loop;
6813 } 6815 }
6814 6816
6815 6817
6816 } // namespace internal 6818 } // namespace internal
6817 } // namespace v8 6819 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser-base.h » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698