OLD | NEW |
---|---|
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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 | 913 |
914 // Enter 'scope' with the given parsing mode. | 914 // Enter 'scope' with the given parsing mode. |
915 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 915 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
916 AstNodeFactory function_factory(ast_value_factory()); | 916 AstNodeFactory function_factory(ast_value_factory()); |
917 FunctionState function_state(&function_state_, &scope_, scope, | 917 FunctionState function_state(&function_state_, &scope_, scope, |
918 kNormalFunction, &function_factory); | 918 kNormalFunction, &function_factory); |
919 | 919 |
920 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 920 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
921 bool ok = true; | 921 bool ok = true; |
922 int beg_pos = scanner()->location().beg_pos; | 922 int beg_pos = scanner()->location().beg_pos; |
923 if (info->is_module()) { | 923 parsing_module_ = info->is_module(); |
924 if (parsing_module_) { | |
924 ParseModuleItemList(body, &ok); | 925 ParseModuleItemList(body, &ok); |
925 } else { | 926 } else { |
926 // Don't count the mode in the use counters--give the program a chance | 927 // Don't count the mode in the use counters--give the program a chance |
927 // to enable script-wide strict mode below. | 928 // to enable script-wide strict mode below. |
928 scope_->SetLanguageMode(info->language_mode()); | 929 scope_->SetLanguageMode(info->language_mode()); |
929 ParseStatementList(body, Token::EOS, &ok); | 930 ParseStatementList(body, Token::EOS, &ok); |
930 } | 931 } |
931 | 932 |
932 // The parser will peek but not consume EOS. Our scope logically goes all | 933 // The parser will peek but not consume EOS. Our scope logically goes all |
933 // the way to the EOS, though. | 934 // the way to the EOS, though. |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1348 // IdentifierName | 1349 // IdentifierName |
1349 // IdentifierName 'as' IdentifierName | 1350 // IdentifierName 'as' IdentifierName |
1350 | 1351 |
1351 Expect(Token::LBRACE, CHECK_OK); | 1352 Expect(Token::LBRACE, CHECK_OK); |
1352 | 1353 |
1353 Token::Value name_tok; | 1354 Token::Value name_tok; |
1354 while ((name_tok = peek()) != Token::RBRACE) { | 1355 while ((name_tok = peek()) != Token::RBRACE) { |
1355 // Keep track of the first reserved word encountered in case our | 1356 // Keep track of the first reserved word encountered in case our |
1356 // caller needs to report an error. | 1357 // caller needs to report an error. |
1357 if (!reserved_loc->IsValid() && | 1358 if (!reserved_loc->IsValid() && |
1358 !Token::IsIdentifier(name_tok, STRICT, false)) { | 1359 !Token::IsIdentifier(name_tok, STRICT, false, true)) { |
adamk
2016/04/22 22:03:04
Please just pass parsing_module_ for readability h
mike3
2016/04/22 23:05:58
Acknowledged.
| |
1359 *reserved_loc = scanner()->location(); | 1360 *reserved_loc = scanner()->location(); |
1360 } | 1361 } |
1361 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); | 1362 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); |
1362 const AstRawString* export_name = NULL; | 1363 const AstRawString* export_name = NULL; |
1363 if (CheckContextualKeyword(CStrVector("as"))) { | 1364 if (CheckContextualKeyword(CStrVector("as"))) { |
1364 export_name = ParseIdentifierName(CHECK_OK); | 1365 export_name = ParseIdentifierName(CHECK_OK); |
1365 } | 1366 } |
1366 if (export_name == NULL) { | 1367 if (export_name == NULL) { |
1367 export_name = local_name; | 1368 export_name = local_name; |
1368 } | 1369 } |
(...skipping 30 matching lines...) Expand all Loading... | |
1399 new (zone()) ZoneList<ImportDeclaration*>(1, zone()); | 1400 new (zone()) ZoneList<ImportDeclaration*>(1, zone()); |
1400 while (peek() != Token::RBRACE) { | 1401 while (peek() != Token::RBRACE) { |
1401 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); | 1402 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); |
1402 const AstRawString* local_name = import_name; | 1403 const AstRawString* local_name = import_name; |
1403 // In the presence of 'as', the left-side of the 'as' can | 1404 // In the presence of 'as', the left-side of the 'as' can |
1404 // be any IdentifierName. But without 'as', it must be a valid | 1405 // be any IdentifierName. But without 'as', it must be a valid |
1405 // BindingIdentifier. | 1406 // BindingIdentifier. |
1406 if (CheckContextualKeyword(CStrVector("as"))) { | 1407 if (CheckContextualKeyword(CStrVector("as"))) { |
1407 local_name = ParseIdentifierName(CHECK_OK); | 1408 local_name = ParseIdentifierName(CHECK_OK); |
1408 } | 1409 } |
1409 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { | 1410 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false, true)) { |
adamk
2016/04/22 22:03:04
And here
mike3
2016/04/22 23:05:58
Acknowledged.
| |
1410 *ok = false; | 1411 *ok = false; |
1411 ReportMessage(MessageTemplate::kUnexpectedReserved); | 1412 ReportMessage(MessageTemplate::kUnexpectedReserved); |
1412 return NULL; | 1413 return NULL; |
1413 } else if (IsEvalOrArguments(local_name)) { | 1414 } else if (IsEvalOrArguments(local_name)) { |
1414 *ok = false; | 1415 *ok = false; |
1415 ReportMessage(MessageTemplate::kStrictEvalArguments); | 1416 ReportMessage(MessageTemplate::kStrictEvalArguments); |
1416 return NULL; | 1417 return NULL; |
1417 } | 1418 } |
1418 VariableProxy* proxy = NewUnresolved(local_name, CONST); | 1419 VariableProxy* proxy = NewUnresolved(local_name, CONST); |
1419 ImportDeclaration* declaration = | 1420 ImportDeclaration* declaration = |
(...skipping 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4605 SET_ALLOW(natives); | 4606 SET_ALLOW(natives); |
4606 SET_ALLOW(harmony_do_expressions); | 4607 SET_ALLOW(harmony_do_expressions); |
4607 SET_ALLOW(harmony_function_name); | 4608 SET_ALLOW(harmony_function_name); |
4608 SET_ALLOW(harmony_function_sent); | 4609 SET_ALLOW(harmony_function_sent); |
4609 SET_ALLOW(harmony_exponentiation_operator); | 4610 SET_ALLOW(harmony_exponentiation_operator); |
4610 SET_ALLOW(harmony_restrictive_declarations); | 4611 SET_ALLOW(harmony_restrictive_declarations); |
4611 #undef SET_ALLOW | 4612 #undef SET_ALLOW |
4612 } | 4613 } |
4613 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4614 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4614 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), | 4615 language_mode(), function_state_->kind(), scope_->has_simple_parameters(), |
4615 logger, bookmark); | 4616 parsing_module_, logger, bookmark); |
4616 if (pre_parse_timer_ != NULL) { | 4617 if (pre_parse_timer_ != NULL) { |
4617 pre_parse_timer_->Stop(); | 4618 pre_parse_timer_->Stop(); |
4618 } | 4619 } |
4619 return result; | 4620 return result; |
4620 } | 4621 } |
4621 | 4622 |
4622 | 4623 |
4623 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, | 4624 ClassLiteral* Parser::ParseClassLiteral(const AstRawString* name, |
4624 Scanner::Location class_name_location, | 4625 Scanner::Location class_name_location, |
4625 bool name_is_strict_reserved, int pos, | 4626 bool name_is_strict_reserved, int pos, |
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6799 try_block, target); | 6800 try_block, target); |
6800 final_loop = target; | 6801 final_loop = target; |
6801 } | 6802 } |
6802 | 6803 |
6803 return final_loop; | 6804 return final_loop; |
6804 } | 6805 } |
6805 | 6806 |
6806 | 6807 |
6807 } // namespace internal | 6808 } // namespace internal |
6808 } // namespace v8 | 6809 } // namespace v8 |
OLD | NEW |