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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 asm_module_ = false; | 290 asm_module_ = false; |
291 asm_function_ = false; | 291 asm_function_ = false; |
292 force_eager_compilation_ = false; | 292 force_eager_compilation_ = false; |
293 has_arguments_parameter_ = false; | 293 has_arguments_parameter_ = false; |
294 scope_uses_super_property_ = false; | 294 scope_uses_super_property_ = false; |
295 has_rest_ = false; | 295 has_rest_ = false; |
296 receiver_ = nullptr; | 296 receiver_ = nullptr; |
297 new_target_ = nullptr; | 297 new_target_ = nullptr; |
298 function_ = nullptr; | 298 function_ = nullptr; |
299 arguments_ = nullptr; | 299 arguments_ = nullptr; |
300 this_function_ = nullptr; | 300 rare_data_ = nullptr; |
301 should_eager_compile_ = false; | 301 should_eager_compile_ = false; |
302 was_lazily_parsed_ = false; | 302 was_lazily_parsed_ = false; |
303 #ifdef DEBUG | 303 #ifdef DEBUG |
304 DeclarationScope* outer_declaration_scope = | 304 DeclarationScope* outer_declaration_scope = |
305 outer_scope_ ? outer_scope_->GetDeclarationScope() : nullptr; | 305 outer_scope_ ? outer_scope_->GetDeclarationScope() : nullptr; |
306 is_being_lazily_parsed_ = | 306 is_being_lazily_parsed_ = |
307 outer_declaration_scope ? outer_declaration_scope->is_being_lazily_parsed_ | 307 outer_declaration_scope ? outer_declaration_scope->is_being_lazily_parsed_ |
308 : false; | 308 : false; |
309 #endif | 309 #endif |
310 } | 310 } |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 void DeclarationScope::DeclareDefaultFunctionVariables( | 675 void DeclarationScope::DeclareDefaultFunctionVariables( |
676 AstValueFactory* ast_value_factory) { | 676 AstValueFactory* ast_value_factory) { |
677 DCHECK(is_function_scope()); | 677 DCHECK(is_function_scope()); |
678 DCHECK(!is_arrow_scope()); | 678 DCHECK(!is_arrow_scope()); |
679 | 679 |
680 DeclareThis(ast_value_factory); | 680 DeclareThis(ast_value_factory); |
681 new_target_ = Declare(zone(), ast_value_factory->new_target_string(), CONST); | 681 new_target_ = Declare(zone(), ast_value_factory->new_target_string(), CONST); |
682 | 682 |
683 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || | 683 if (IsConciseMethod(function_kind_) || IsClassConstructor(function_kind_) || |
684 IsAccessorFunction(function_kind_)) { | 684 IsAccessorFunction(function_kind_)) { |
685 this_function_ = | 685 EnsureRareData()->this_function = |
686 Declare(zone(), ast_value_factory->this_function_string(), CONST); | 686 Declare(zone(), ast_value_factory->this_function_string(), CONST); |
687 } | 687 } |
688 } | 688 } |
689 | 689 |
690 Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) { | 690 Variable* DeclarationScope::DeclareFunctionVar(const AstRawString* name) { |
691 DCHECK(is_function_scope()); | 691 DCHECK(is_function_scope()); |
692 DCHECK_NULL(function_); | 692 DCHECK_NULL(function_); |
693 DCHECK_NULL(variables_.Lookup(name)); | 693 DCHECK_NULL(variables_.Lookup(name)); |
694 VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE | 694 VariableKind kind = is_sloppy(language_mode()) ? SLOPPY_FUNCTION_NAME_VARIABLE |
695 : NORMAL_VARIABLE; | 695 : NORMAL_VARIABLE; |
696 function_ = | 696 function_ = |
697 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); | 697 new (zone()) Variable(this, name, CONST, kind, kCreatedInitialized); |
698 if (calls_sloppy_eval()) { | 698 if (calls_sloppy_eval()) { |
699 NonLocal(name, DYNAMIC); | 699 NonLocal(name, DYNAMIC); |
700 } else { | 700 } else { |
701 variables_.Add(zone(), function_); | 701 variables_.Add(zone(), function_); |
702 } | 702 } |
703 return function_; | 703 return function_; |
704 } | 704 } |
705 | 705 |
| 706 Variable* DeclarationScope::DeclareGeneratorObjectVar( |
| 707 const AstRawString* name) { |
| 708 DCHECK(is_function_scope() || is_module_scope()); |
| 709 DCHECK_NULL(generator_object_var()); |
| 710 |
| 711 Variable* result = EnsureRareData()->generator_object = NewTemporary(name); |
| 712 result->set_is_used(); |
| 713 return result; |
| 714 } |
| 715 |
| 716 Variable* DeclarationScope::DeclarePromiseVar(const AstRawString* name) { |
| 717 DCHECK(is_function_scope()); |
| 718 DCHECK_NULL(promise_var()); |
| 719 Variable* result = EnsureRareData()->promise = NewTemporary(name); |
| 720 result->set_is_used(); |
| 721 return result; |
| 722 } |
| 723 |
706 bool Scope::HasBeenRemoved() const { | 724 bool Scope::HasBeenRemoved() const { |
707 if (sibling() == this) { | 725 if (sibling() == this) { |
708 DCHECK_NULL(inner_scope_); | 726 DCHECK_NULL(inner_scope_); |
709 DCHECK(is_block_scope()); | 727 DCHECK(is_block_scope()); |
710 return true; | 728 return true; |
711 } | 729 } |
712 return false; | 730 return false; |
713 } | 731 } |
714 | 732 |
715 Scope* Scope::GetUnremovedScope() { | 733 Scope* Scope::GetUnremovedScope() { |
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 AllocateNonParameterLocal(function_); | 2121 AllocateNonParameterLocal(function_); |
2104 } | 2122 } |
2105 | 2123 |
2106 DCHECK(!has_rest_ || !MustAllocate(rest_parameter()) || | 2124 DCHECK(!has_rest_ || !MustAllocate(rest_parameter()) || |
2107 !rest_parameter()->IsUnallocated()); | 2125 !rest_parameter()->IsUnallocated()); |
2108 | 2126 |
2109 if (new_target_ != nullptr && !MustAllocate(new_target_)) { | 2127 if (new_target_ != nullptr && !MustAllocate(new_target_)) { |
2110 new_target_ = nullptr; | 2128 new_target_ = nullptr; |
2111 } | 2129 } |
2112 | 2130 |
2113 if (this_function_ != nullptr && !MustAllocate(this_function_)) { | 2131 NullifyRareVariableIf(RareVariable::kThisFunction, |
2114 this_function_ = nullptr; | 2132 [=](Variable* var) { return !MustAllocate(var); }); |
2115 } | |
2116 } | 2133 } |
2117 | 2134 |
2118 void ModuleScope::AllocateModuleVariables() { | 2135 void ModuleScope::AllocateModuleVariables() { |
2119 for (const auto& it : module()->regular_imports()) { | 2136 for (const auto& it : module()->regular_imports()) { |
2120 Variable* var = LookupLocal(it.first); | 2137 Variable* var = LookupLocal(it.first); |
2121 var->AllocateTo(VariableLocation::MODULE, it.second->cell_index); | 2138 var->AllocateTo(VariableLocation::MODULE, it.second->cell_index); |
2122 DCHECK(!var->IsExport()); | 2139 DCHECK(!var->IsExport()); |
2123 } | 2140 } |
2124 | 2141 |
2125 for (const auto& it : module()->regular_exports()) { | 2142 for (const auto& it : module()->regular_exports()) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 Variable* function = | 2249 Variable* function = |
2233 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2250 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2234 bool is_function_var_in_context = | 2251 bool is_function_var_in_context = |
2235 function != nullptr && function->IsContextSlot(); | 2252 function != nullptr && function->IsContextSlot(); |
2236 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2253 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2237 (is_function_var_in_context ? 1 : 0); | 2254 (is_function_var_in_context ? 1 : 0); |
2238 } | 2255 } |
2239 | 2256 |
2240 } // namespace internal | 2257 } // namespace internal |
2241 } // namespace v8 | 2258 } // namespace v8 |
OLD | NEW |