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) | 80 Scope::Scope(Zone* zone, ScopeType scope_type) |
81 : zone_(zone), | 81 : zone_(zone), |
82 outer_scope_(nullptr), | 82 outer_scope_(nullptr), |
83 variables_(zone), | 83 variables_(zone), |
84 ordered_variables_(4, zone), | 84 ordered_variables_(4, zone), |
85 decls_(4, zone), | 85 decls_(4, zone), |
86 scope_type_(SCRIPT_SCOPE) { | 86 scope_type_(scope_type) { |
87 DCHECK(scope_type == SCRIPT_SCOPE || scope_type == WITH_SCOPE); | |
87 SetDefaults(); | 88 SetDefaults(); |
89 #ifdef DEBUG | |
90 if (scope_type == WITH_SCOPE) { | |
91 already_resolved_ = true; | |
92 } | |
93 #endif | |
88 } | 94 } |
89 | 95 |
90 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 96 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
91 : zone_(zone), | 97 : zone_(zone), |
92 outer_scope_(outer_scope), | 98 outer_scope_(outer_scope), |
93 variables_(zone), | 99 variables_(zone), |
94 ordered_variables_(4, zone), | 100 ordered_variables_(4, zone), |
95 decls_(4, zone), | 101 decls_(4, zone), |
96 scope_type_(scope_type) { | 102 scope_type_(scope_type) { |
97 DCHECK_NE(SCRIPT_SCOPE, scope_type); | 103 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 | 145 |
140 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 146 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
141 Handle<ScopeInfo> scope_info) | 147 Handle<ScopeInfo> scope_info) |
142 : zone_(zone), | 148 : zone_(zone), |
143 outer_scope_(nullptr), | 149 outer_scope_(nullptr), |
144 variables_(zone), | 150 variables_(zone), |
145 ordered_variables_(0, zone), | 151 ordered_variables_(0, zone), |
146 decls_(0, zone), | 152 decls_(0, zone), |
147 scope_info_(scope_info), | 153 scope_info_(scope_info), |
148 scope_type_(scope_type) { | 154 scope_type_(scope_type) { |
155 DCHECK(!scope_info.is_null()); | |
149 SetDefaults(); | 156 SetDefaults(); |
150 #ifdef DEBUG | 157 #ifdef DEBUG |
151 already_resolved_ = true; | 158 already_resolved_ = true; |
152 #endif | 159 #endif |
153 if (scope_type == WITH_SCOPE) { | 160 if (scope_info->CallsEval()) RecordEvalCall(); |
154 DCHECK(scope_info.is_null()); | 161 set_language_mode(scope_info->language_mode()); |
155 } else { | 162 num_heap_slots_ = scope_info->ContextLength(); |
156 if (scope_info->CallsEval()) RecordEvalCall(); | |
157 set_language_mode(scope_info->language_mode()); | |
158 num_heap_slots_ = scope_info->ContextLength(); | |
159 } | |
160 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); | 163 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); |
161 | 164 |
162 if (inner_scope != nullptr) AddInnerScope(inner_scope); | 165 if (inner_scope != nullptr) AddInnerScope(inner_scope); |
163 } | 166 } |
164 | 167 |
165 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, | 168 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, |
166 ScopeType scope_type, | 169 ScopeType scope_type, |
167 Handle<ScopeInfo> scope_info) | 170 Handle<ScopeInfo> scope_info) |
168 : Scope(zone, inner_scope, scope_type, scope_info), | 171 : Scope(zone, inner_scope, scope_type, scope_info), |
169 function_kind_(scope_info->function_kind()), | 172 function_kind_(scope_info->function_kind()), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 Context* context, | 260 Context* context, |
258 DeclarationScope* script_scope, | 261 DeclarationScope* script_scope, |
259 AstValueFactory* ast_value_factory, | 262 AstValueFactory* ast_value_factory, |
260 DeserializationMode deserialization_mode) { | 263 DeserializationMode deserialization_mode) { |
261 // Reconstruct the outer scope chain from a closure's context chain. | 264 // Reconstruct the outer scope chain from a closure's context chain. |
262 Scope* current_scope = nullptr; | 265 Scope* current_scope = nullptr; |
263 Scope* innermost_scope = nullptr; | 266 Scope* innermost_scope = nullptr; |
264 while (!context->IsNativeContext()) { | 267 while (!context->IsNativeContext()) { |
265 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { | 268 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { |
266 // For scope analysis, debug-evaluate is equivalent to a with scope. | 269 // For scope analysis, debug-evaluate is equivalent to a with scope. |
267 Scope* with_scope = new (zone) | 270 Scope* with_scope = new (zone) Scope(zone, WITH_SCOPE); |
268 Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>()); | 271 if (current_scope != nullptr) { |
272 with_scope->AddInnerScope(current_scope); | |
Toon Verwaest
2016/08/23 12:33:27
Perhaps we should just pull this out of the other
| |
273 } | |
274 | |
269 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the | 275 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the |
270 // function scope in which we are evaluating. | 276 // function scope in which we are evaluating. |
271 if (context->IsDebugEvaluateContext()) { | 277 if (context->IsDebugEvaluateContext()) { |
272 with_scope->set_is_debug_evaluate_scope(); | 278 with_scope->set_is_debug_evaluate_scope(); |
273 } | 279 } |
274 current_scope = with_scope; | 280 current_scope = with_scope; |
275 } else if (context->IsScriptContext()) { | 281 } else if (context->IsScriptContext()) { |
276 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); | 282 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); |
277 DCHECK_EQ(scope_info->scope_type(), SCRIPT_SCOPE); | 283 DCHECK_EQ(scope_info->scope_type(), SCRIPT_SCOPE); |
278 current_scope = new (zone) | 284 current_scope = new (zone) |
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1734 function != nullptr && function->IsContextSlot(); | 1740 function != nullptr && function->IsContextSlot(); |
1735 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1741 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1736 (is_function_var_in_context ? 1 : 0); | 1742 (is_function_var_in_context ? 1 : 0); |
1737 } | 1743 } |
1738 | 1744 |
1739 | 1745 |
1740 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1746 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1741 | 1747 |
1742 } // namespace internal | 1748 } // namespace internal |
1743 } // namespace v8 | 1749 } // namespace v8 |
OLD | NEW |