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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 FunctionState function_state(&function_state_, &scope_, scope, | 900 FunctionState function_state(&function_state_, &scope_, scope, |
901 kNormalFunction, &function_factory); | 901 kNormalFunction, &function_factory); |
902 | 902 |
903 // Don't count the mode in the use counters--give the program a chance | 903 // Don't count the mode in the use counters--give the program a chance |
904 // to enable script/module-wide strict/strong mode below. | 904 // to enable script/module-wide strict/strong mode below. |
905 scope_->SetLanguageMode(info->language_mode()); | 905 scope_->SetLanguageMode(info->language_mode()); |
906 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 906 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
907 bool ok = true; | 907 bool ok = true; |
908 int beg_pos = scanner()->location().beg_pos; | 908 int beg_pos = scanner()->location().beg_pos; |
909 if (info->is_module()) { | 909 if (info->is_module()) { |
| 910 parsing_module_ = true; |
910 ParseModuleItemList(body, &ok); | 911 ParseModuleItemList(body, &ok); |
911 } else { | 912 } else { |
| 913 parsing_module_ = false; |
912 ParseStatementList(body, Token::EOS, &ok); | 914 ParseStatementList(body, Token::EOS, &ok); |
913 } | 915 } |
914 | 916 |
915 // The parser will peek but not consume EOS. Our scope logically goes all | 917 // The parser will peek but not consume EOS. Our scope logically goes all |
916 // the way to the EOS, though. | 918 // the way to the EOS, though. |
917 scope->set_end_position(scanner()->peek_location().beg_pos); | 919 scope->set_end_position(scanner()->peek_location().beg_pos); |
918 | 920 |
919 if (ok && is_strict(language_mode())) { | 921 if (ok && is_strict(language_mode())) { |
920 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 922 CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
921 } | 923 } |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 // IdentifierName | 1381 // IdentifierName |
1380 // IdentifierName 'as' IdentifierName | 1382 // IdentifierName 'as' IdentifierName |
1381 | 1383 |
1382 Expect(Token::LBRACE, CHECK_OK); | 1384 Expect(Token::LBRACE, CHECK_OK); |
1383 | 1385 |
1384 Token::Value name_tok; | 1386 Token::Value name_tok; |
1385 while ((name_tok = peek()) != Token::RBRACE) { | 1387 while ((name_tok = peek()) != Token::RBRACE) { |
1386 // Keep track of the first reserved word encountered in case our | 1388 // Keep track of the first reserved word encountered in case our |
1387 // caller needs to report an error. | 1389 // caller needs to report an error. |
1388 if (!reserved_loc->IsValid() && | 1390 if (!reserved_loc->IsValid() && |
1389 !Token::IsIdentifier(name_tok, STRICT, false)) { | 1391 !Token::IsIdentifier(name_tok, STRICT, false, true)) { |
1390 *reserved_loc = scanner()->location(); | 1392 *reserved_loc = scanner()->location(); |
1391 } | 1393 } |
1392 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); | 1394 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); |
1393 const AstRawString* export_name = NULL; | 1395 const AstRawString* export_name = NULL; |
1394 if (CheckContextualKeyword(CStrVector("as"))) { | 1396 if (CheckContextualKeyword(CStrVector("as"))) { |
1395 export_name = ParseIdentifierName(CHECK_OK); | 1397 export_name = ParseIdentifierName(CHECK_OK); |
1396 } | 1398 } |
1397 if (export_name == NULL) { | 1399 if (export_name == NULL) { |
1398 export_name = local_name; | 1400 export_name = local_name; |
1399 } | 1401 } |
(...skipping 30 matching lines...) Expand all Loading... |
1430 new (zone()) ZoneList<ImportDeclaration*>(1, zone()); | 1432 new (zone()) ZoneList<ImportDeclaration*>(1, zone()); |
1431 while (peek() != Token::RBRACE) { | 1433 while (peek() != Token::RBRACE) { |
1432 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); | 1434 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); |
1433 const AstRawString* local_name = import_name; | 1435 const AstRawString* local_name = import_name; |
1434 // In the presence of 'as', the left-side of the 'as' can | 1436 // In the presence of 'as', the left-side of the 'as' can |
1435 // be any IdentifierName. But without 'as', it must be a valid | 1437 // be any IdentifierName. But without 'as', it must be a valid |
1436 // BindingIdentifier. | 1438 // BindingIdentifier. |
1437 if (CheckContextualKeyword(CStrVector("as"))) { | 1439 if (CheckContextualKeyword(CStrVector("as"))) { |
1438 local_name = ParseIdentifierName(CHECK_OK); | 1440 local_name = ParseIdentifierName(CHECK_OK); |
1439 } | 1441 } |
1440 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { | 1442 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false, true)) { |
1441 *ok = false; | 1443 *ok = false; |
1442 ReportMessage(MessageTemplate::kUnexpectedReserved); | 1444 ReportMessage(MessageTemplate::kUnexpectedReserved); |
1443 return NULL; | 1445 return NULL; |
1444 } else if (IsEvalOrArguments(local_name)) { | 1446 } else if (IsEvalOrArguments(local_name)) { |
1445 *ok = false; | 1447 *ok = false; |
1446 ReportMessage(MessageTemplate::kStrictEvalArguments); | 1448 ReportMessage(MessageTemplate::kStrictEvalArguments); |
1447 return NULL; | 1449 return NULL; |
1448 } else if (is_strong(language_mode()) && IsUndefined(local_name)) { | 1450 } else if (is_strong(language_mode()) && IsUndefined(local_name)) { |
1449 *ok = false; | 1451 *ok = false; |
1450 ReportMessage(MessageTemplate::kStrongUndefined); | 1452 ReportMessage(MessageTemplate::kStrongUndefined); |
(...skipping 5449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6900 new_body->statements()->Add(loop->body(), zone); | 6902 new_body->statements()->Add(loop->body(), zone); |
6901 new_body->statements()->Add(set_completion_normal, zone); | 6903 new_body->statements()->Add(set_completion_normal, zone); |
6902 | 6904 |
6903 loop->set_body(new_body); | 6905 loop->set_body(new_body); |
6904 return final_loop; | 6906 return final_loop; |
6905 } | 6907 } |
6906 | 6908 |
6907 | 6909 |
6908 } // namespace internal | 6910 } // namespace internal |
6909 } // namespace v8 | 6911 } // namespace v8 |
OLD | NEW |