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(); | |
709 Expression* initial_yield = | 710 Expression* initial_yield = |
710 BuildInitialYield(kNoSourcePosition, kGeneratorFunction); | 711 BuildInitialYield(kNoSourcePosition, kGeneratorFunction); |
711 body->Add( | 712 body->Add( |
712 factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), | 713 factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), |
713 zone()); | 714 zone()); |
714 | 715 |
715 ParseModuleItemList(body, &ok); | 716 ParseModuleItemList(body, &ok); |
716 ok = ok && | 717 ok = ok && |
717 module()->Validate(this->scope()->AsModuleScope(), | 718 module()->Validate(this->scope()->AsModuleScope(), |
718 &pending_error_handler_, zone()); | 719 &pending_error_handler_, zone()); |
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2526 if (!this->classifier() | 2527 if (!this->classifier() |
2527 ->is_valid_formal_parameter_list_without_duplicates()) { | 2528 ->is_valid_formal_parameter_list_without_duplicates()) { |
2528 *duplicate_loc = | 2529 *duplicate_loc = |
2529 this->classifier()->duplicate_formal_parameter_error().location; | 2530 this->classifier()->duplicate_formal_parameter_error().location; |
2530 } | 2531 } |
2531 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); | 2532 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); |
2532 } | 2533 } |
2533 | 2534 |
2534 void Parser::PrepareGeneratorVariables() { | 2535 void Parser::PrepareGeneratorVariables() { |
2535 // For generators, allocating variables in contexts is currently a win because | 2536 // For generators, allocating variables in contexts is currently a win because |
2536 // it minimizes the work needed to suspend and resume an activation. The | 2537 // it minimizes the work needed to suspend and resume an activation. The |
adamk
2017/05/23 20:20:38
This first sentence is now obsolete, and should be
Jarin
2017/05/24 05:03:27
Done.
| |
2537 // code produced for generators relies on this forced context allocation (it | 2538 // code produced for generators relies on this forced context allocation (it |
2538 // does not restore the frame's parameters upon resume). | 2539 // does not restore the frame's parameters upon resume). |
2539 function_state_->scope()->ForceContextAllocation(); | 2540 function_state_->scope()->ForceContextAllocationForParameters(); |
2540 | 2541 |
2541 // Calling a generator returns a generator object. That object is stored | 2542 // Calling a generator returns a generator object. That object is stored |
2542 // in a temporary variable, a definition that is used by "yield" | 2543 // in a temporary variable, a definition that is used by "yield" |
2543 // expressions. | 2544 // expressions. |
2544 function_state_->scope()->DeclareGeneratorObjectVar( | 2545 function_state_->scope()->DeclareGeneratorObjectVar( |
2545 ast_value_factory()->dot_generator_object_string()); | 2546 ast_value_factory()->dot_generator_object_string()); |
2546 } | 2547 } |
2547 | 2548 |
2548 FunctionLiteral* Parser::ParseFunctionLiteral( | 2549 FunctionLiteral* Parser::ParseFunctionLiteral( |
2549 const AstRawString* function_name, Scanner::Location function_name_location, | 2550 const AstRawString* function_name, Scanner::Location function_name_location, |
(...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5144 literal->SetShouldEagerCompile(); | 5145 literal->SetShouldEagerCompile(); |
5145 } | 5146 } |
5146 } | 5147 } |
5147 | 5148 |
5148 #undef CHECK_OK | 5149 #undef CHECK_OK |
5149 #undef CHECK_OK_VOID | 5150 #undef CHECK_OK_VOID |
5150 #undef CHECK_FAILED | 5151 #undef CHECK_FAILED |
5151 | 5152 |
5152 } // namespace internal | 5153 } // namespace internal |
5153 } // namespace v8 | 5154 } // namespace v8 |
OLD | NEW |