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/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 70 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
71 ZoneAllocationPolicy(zone)); | 71 ZoneAllocationPolicy(zone)); |
72 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); | 72 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); |
73 p->value = stmt; | 73 p->value = stmt; |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 // ---------------------------------------------------------------------------- | 77 // ---------------------------------------------------------------------------- |
78 // Implementation of Scope | 78 // Implementation of Scope |
79 | 79 |
| 80 Scope::Scope(Zone* zone) |
| 81 : zone_(zone), |
| 82 outer_scope_(nullptr), |
| 83 variables_(zone), |
| 84 ordered_variables_(4, zone), |
| 85 decls_(4, zone), |
| 86 scope_type_(SCRIPT_SCOPE) { |
| 87 SetDefaults(); |
| 88 } |
| 89 |
80 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 90 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
81 : zone_(zone), | 91 : zone_(zone), |
82 outer_scope_(outer_scope), | 92 outer_scope_(outer_scope), |
83 variables_(zone), | 93 variables_(zone), |
84 ordered_variables_(4, zone), | 94 ordered_variables_(4, zone), |
85 decls_(4, zone), | 95 decls_(4, zone), |
86 scope_type_(scope_type) { | 96 scope_type_(scope_type) { |
| 97 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
87 SetDefaults(); | 98 SetDefaults(); |
88 if (outer_scope == nullptr) { | 99 set_language_mode(outer_scope->language_mode()); |
89 // If the outer scope is null, this cannot be a with scope. The outermost | 100 force_context_allocation_ = |
90 // scope must be a script scope. | 101 !is_function_scope() && outer_scope->has_forced_context_allocation(); |
91 DCHECK_EQ(SCRIPT_SCOPE, scope_type); | 102 outer_scope_->AddInnerScope(this); |
92 } else { | |
93 set_language_mode(outer_scope->language_mode()); | |
94 force_context_allocation_ = | |
95 !is_function_scope() && outer_scope->has_forced_context_allocation(); | |
96 outer_scope_->AddInnerScope(this); | |
97 } | |
98 } | 103 } |
99 | 104 |
100 Scope::Snapshot::Snapshot(Scope* scope) | 105 Scope::Snapshot::Snapshot(Scope* scope) |
101 : outer_scope_(scope), | 106 : outer_scope_(scope), |
102 top_inner_scope_(scope->inner_scope_), | 107 top_inner_scope_(scope->inner_scope_), |
103 top_unresolved_(scope->unresolved_), | 108 top_unresolved_(scope->unresolved_), |
104 top_temp_(scope->GetClosureScope()->temps()->length()) {} | 109 top_temp_(scope->GetClosureScope()->temps()->length()) {} |
105 | 110 |
| 111 DeclarationScope::DeclarationScope(Zone* zone) |
| 112 : Scope(zone), |
| 113 function_kind_(kNormalFunction), |
| 114 temps_(4, zone), |
| 115 params_(4, zone), |
| 116 sloppy_block_function_map_(zone) { |
| 117 SetDefaults(); |
| 118 } |
| 119 |
106 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, | 120 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, |
107 ScopeType scope_type, | 121 ScopeType scope_type, |
108 FunctionKind function_kind) | 122 FunctionKind function_kind) |
109 : Scope(zone, outer_scope, scope_type), | 123 : Scope(zone, outer_scope, scope_type), |
110 function_kind_(function_kind), | 124 function_kind_(function_kind), |
111 temps_(4, zone), | 125 temps_(4, zone), |
112 params_(4, zone), | 126 params_(4, zone), |
113 sloppy_block_function_map_(zone) { | 127 sloppy_block_function_map_(zone) { |
114 SetDefaults(); | 128 SetDefaults(); |
115 if (outer_scope != nullptr) asm_function_ = outer_scope_->IsAsmModule(); | 129 asm_function_ = outer_scope_->IsAsmModule(); |
116 } | 130 } |
117 | 131 |
118 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, | 132 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, |
119 AstValueFactory* ast_value_factory) | 133 AstValueFactory* ast_value_factory) |
120 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { | 134 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { |
121 module_descriptor_ = new (zone) ModuleDescriptor(zone); | 135 module_descriptor_ = new (zone) ModuleDescriptor(zone); |
122 set_language_mode(STRICT); | 136 set_language_mode(STRICT); |
123 DeclareThis(ast_value_factory); | 137 DeclareThis(ast_value_factory); |
124 } | 138 } |
125 | 139 |
(...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 function != nullptr && function->IsContextSlot(); | 1742 function != nullptr && function->IsContextSlot(); |
1729 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1743 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1730 (is_function_var_in_context ? 1 : 0); | 1744 (is_function_var_in_context ? 1 : 0); |
1731 } | 1745 } |
1732 | 1746 |
1733 | 1747 |
1734 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1748 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1735 | 1749 |
1736 } // namespace internal | 1750 } // namespace internal |
1737 } // namespace v8 | 1751 } // namespace v8 |
OLD | NEW |