| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // Enter 'scope' with the given parsing mode. | 735 // Enter 'scope' with the given parsing mode. |
| 736 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 736 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
| 737 FunctionState function_state(&function_state_, &scope_state_, scope, | 737 FunctionState function_state(&function_state_, &scope_state_, scope, |
| 738 kNormalFunction); | 738 kNormalFunction); |
| 739 | 739 |
| 740 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 740 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 741 bool ok = true; | 741 bool ok = true; |
| 742 int beg_pos = scanner()->location().beg_pos; | 742 int beg_pos = scanner()->location().beg_pos; |
| 743 parsing_module_ = info->is_module(); | 743 parsing_module_ = info->is_module(); |
| 744 if (parsing_module_) { | 744 if (parsing_module_) { |
| 745 // Declare the special module parameter. | |
| 746 auto name = ast_value_factory()->empty_string(); | |
| 747 bool is_duplicate; | |
| 748 bool is_rest = false; | |
| 749 bool is_optional = false; | |
| 750 auto var = scope->DeclareParameter(name, VAR, is_optional, is_rest, | |
| 751 &is_duplicate, ast_value_factory()); | |
| 752 DCHECK(!is_duplicate); | |
| 753 var->AllocateTo(VariableLocation::PARAMETER, 0); | |
| 754 | |
| 755 ParseModuleItemList(body, &ok); | 745 ParseModuleItemList(body, &ok); |
| 756 ok = ok && | 746 ok = ok && |
| 757 module()->Validate(this->scope()->AsModuleScope(), | 747 module()->Validate(this->scope()->AsModuleScope(), |
| 758 &pending_error_handler_, zone()); | 748 &pending_error_handler_, zone()); |
| 759 } else { | 749 } else { |
| 760 // Don't count the mode in the use counters--give the program a chance | 750 // Don't count the mode in the use counters--give the program a chance |
| 761 // to enable script-wide strict mode below. | 751 // to enable script-wide strict mode below. |
| 762 this->scope()->SetLanguageMode(info->language_mode()); | 752 this->scope()->SetLanguageMode(info->language_mode()); |
| 763 ParseStatementList(body, Token::EOS, &ok); | 753 ParseStatementList(body, Token::EOS, &ok); |
| 764 } | 754 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 788 !body->at(0)->IsExpressionStatement() || | 778 !body->at(0)->IsExpressionStatement() || |
| 789 !body->at(0)->AsExpressionStatement()-> | 779 !body->at(0)->AsExpressionStatement()-> |
| 790 expression()->IsFunctionLiteral()) { | 780 expression()->IsFunctionLiteral()) { |
| 791 ReportMessage(MessageTemplate::kSingleFunctionLiteral); | 781 ReportMessage(MessageTemplate::kSingleFunctionLiteral); |
| 792 ok = false; | 782 ok = false; |
| 793 } | 783 } |
| 794 } | 784 } |
| 795 | 785 |
| 796 if (ok) { | 786 if (ok) { |
| 797 RewriteDestructuringAssignments(); | 787 RewriteDestructuringAssignments(); |
| 798 int parameter_count = parsing_module_ ? 1 : 0; | |
| 799 result = factory()->NewScriptOrEvalFunctionLiteral( | 788 result = factory()->NewScriptOrEvalFunctionLiteral( |
| 800 scope, body, function_state.materialized_literal_count(), | 789 scope, body, function_state.materialized_literal_count(), |
| 801 function_state.expected_property_count(), parameter_count); | 790 function_state.expected_property_count()); |
| 802 } | 791 } |
| 803 } | 792 } |
| 804 | 793 |
| 805 // Make sure the target stack is empty. | 794 // Make sure the target stack is empty. |
| 806 DCHECK(target_stack_ == NULL); | 795 DCHECK(target_stack_ == NULL); |
| 807 | 796 |
| 808 return result; | 797 return result; |
| 809 } | 798 } |
| 810 | 799 |
| 811 | 800 |
| (...skipping 4875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5687 node->Print(Isolate::Current()); | 5676 node->Print(Isolate::Current()); |
| 5688 } | 5677 } |
| 5689 #endif // DEBUG | 5678 #endif // DEBUG |
| 5690 | 5679 |
| 5691 #undef CHECK_OK | 5680 #undef CHECK_OK |
| 5692 #undef CHECK_OK_VOID | 5681 #undef CHECK_OK_VOID |
| 5693 #undef CHECK_FAILED | 5682 #undef CHECK_FAILED |
| 5694 | 5683 |
| 5695 } // namespace internal | 5684 } // namespace internal |
| 5696 } // namespace v8 | 5685 } // namespace v8 |
| OLD | NEW |