| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 bool is_duplicate; | 699 bool is_duplicate; |
| 700 bool is_rest = false; | 700 bool is_rest = false; |
| 701 bool is_optional = false; | 701 bool is_optional = false; |
| 702 auto var = | 702 auto var = |
| 703 scope->DeclareParameter(name, VAR, is_optional, is_rest, | 703 scope->DeclareParameter(name, VAR, is_optional, is_rest, |
| 704 &is_duplicate, ast_value_factory(), beg_pos); | 704 &is_duplicate, ast_value_factory(), beg_pos); |
| 705 DCHECK(!is_duplicate); | 705 DCHECK(!is_duplicate); |
| 706 var->AllocateTo(VariableLocation::PARAMETER, 0); | 706 var->AllocateTo(VariableLocation::PARAMETER, 0); |
| 707 | 707 |
| 708 PrepareGeneratorVariables(); | 708 PrepareGeneratorVariables(); |
| 709 scope->ForceContextAllocation(); | |
| 710 Expression* initial_yield = | 709 Expression* initial_yield = |
| 711 BuildInitialYield(kNoSourcePosition, kGeneratorFunction); | 710 BuildInitialYield(kNoSourcePosition, kGeneratorFunction); |
| 712 body->Add( | 711 body->Add( |
| 713 factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), | 712 factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), |
| 714 zone()); | 713 zone()); |
| 715 | 714 |
| 716 ParseModuleItemList(body, &ok); | 715 ParseModuleItemList(body, &ok); |
| 717 ok = ok && | 716 ok = ok && |
| 718 module()->Validate(this->scope()->AsModuleScope(), | 717 module()->Validate(this->scope()->AsModuleScope(), |
| 719 &pending_error_handler_, zone()); | 718 &pending_error_handler_, zone()); |
| (...skipping 1805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 DeclareFormalParameters(parameters->scope, parameters->params); | 2524 DeclareFormalParameters(parameters->scope, parameters->params); |
| 2526 if (!this->classifier() | 2525 if (!this->classifier() |
| 2527 ->is_valid_formal_parameter_list_without_duplicates()) { | 2526 ->is_valid_formal_parameter_list_without_duplicates()) { |
| 2528 *duplicate_loc = | 2527 *duplicate_loc = |
| 2529 this->classifier()->duplicate_formal_parameter_error().location; | 2528 this->classifier()->duplicate_formal_parameter_error().location; |
| 2530 } | 2529 } |
| 2531 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); | 2530 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); |
| 2532 } | 2531 } |
| 2533 | 2532 |
| 2534 void Parser::PrepareGeneratorVariables() { | 2533 void Parser::PrepareGeneratorVariables() { |
| 2535 // The code produced for generators relies on forced context allocation of | 2534 // For generators, allocating variables in contexts is currently a win because |
| 2536 // parameters (it does not restore the frame's parameters upon resume). | 2535 // it minimizes the work needed to suspend and resume an activation. The |
| 2537 function_state_->scope()->ForceContextAllocationForParameters(); | 2536 // code produced for generators relies on this forced context allocation (it |
| 2537 // does not restore the frame's parameters upon resume). |
| 2538 function_state_->scope()->ForceContextAllocation(); |
| 2538 | 2539 |
| 2539 // Calling a generator returns a generator object. That object is stored | 2540 // Calling a generator returns a generator object. That object is stored |
| 2540 // in a temporary variable, a definition that is used by "yield" | 2541 // in a temporary variable, a definition that is used by "yield" |
| 2541 // expressions. | 2542 // expressions. |
| 2542 function_state_->scope()->DeclareGeneratorObjectVar( | 2543 function_state_->scope()->DeclareGeneratorObjectVar( |
| 2543 ast_value_factory()->dot_generator_object_string()); | 2544 ast_value_factory()->dot_generator_object_string()); |
| 2544 } | 2545 } |
| 2545 | 2546 |
| 2546 FunctionLiteral* Parser::ParseFunctionLiteral( | 2547 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 2547 const AstRawString* function_name, Scanner::Location function_name_location, | 2548 const AstRawString* function_name, Scanner::Location function_name_location, |
| (...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5142 literal->SetShouldEagerCompile(); | 5143 literal->SetShouldEagerCompile(); |
| 5143 } | 5144 } |
| 5144 } | 5145 } |
| 5145 | 5146 |
| 5146 #undef CHECK_OK | 5147 #undef CHECK_OK |
| 5147 #undef CHECK_OK_VOID | 5148 #undef CHECK_OK_VOID |
| 5148 #undef CHECK_FAILED | 5149 #undef CHECK_FAILED |
| 5149 | 5150 |
| 5150 } // namespace internal | 5151 } // namespace internal |
| 5151 } // namespace v8 | 5152 } // namespace v8 |
| OLD | NEW |