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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 85 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
86 ZoneAllocationPolicy(zone)); | 86 ZoneAllocationPolicy(zone)); |
87 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); | 87 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); |
88 p->value = stmt; | 88 p->value = stmt; |
89 } | 89 } |
90 | 90 |
91 | 91 |
92 // ---------------------------------------------------------------------------- | 92 // ---------------------------------------------------------------------------- |
93 // Implementation of Scope | 93 // Implementation of Scope |
94 | 94 |
95 Scope::Scope(Zone* zone, ScopeType scope_type) | 95 Scope::Scope(Zone* zone) |
96 : zone_(zone), | 96 : zone_(zone), |
97 outer_scope_(nullptr), | 97 outer_scope_(nullptr), |
98 variables_(zone), | 98 variables_(zone), |
99 locals_(4, zone), | 99 locals_(4, zone), |
100 decls_(4, zone), | 100 decls_(4, zone), |
101 scope_type_(scope_type) { | 101 scope_type_(SCRIPT_SCOPE) { |
102 DCHECK(scope_type == SCRIPT_SCOPE || scope_type == WITH_SCOPE); | |
103 SetDefaults(); | 102 SetDefaults(); |
104 #ifdef DEBUG | |
105 if (scope_type == WITH_SCOPE) { | |
106 already_resolved_ = true; | |
107 } | |
108 #endif | |
109 } | 103 } |
110 | 104 |
111 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 105 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
112 : zone_(zone), | 106 : zone_(zone), |
113 outer_scope_(outer_scope), | 107 outer_scope_(outer_scope), |
114 variables_(zone), | 108 variables_(zone), |
115 locals_(4, zone), | 109 locals_(4, zone), |
116 decls_(4, zone), | 110 decls_(4, zone), |
117 scope_type_(scope_type) { | 111 scope_type_(scope_type) { |
118 DCHECK_NE(SCRIPT_SCOPE, scope_type); | 112 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 DeclarationScope* script_scope, | 312 DeclarationScope* script_scope, |
319 AstValueFactory* ast_value_factory, | 313 AstValueFactory* ast_value_factory, |
320 DeserializationMode deserialization_mode) { | 314 DeserializationMode deserialization_mode) { |
321 // Reconstruct the outer scope chain from a closure's context chain. | 315 // Reconstruct the outer scope chain from a closure's context chain. |
322 Scope* current_scope = nullptr; | 316 Scope* current_scope = nullptr; |
323 Scope* innermost_scope = nullptr; | 317 Scope* innermost_scope = nullptr; |
324 Scope* outer_scope = nullptr; | 318 Scope* outer_scope = nullptr; |
325 while (!context->IsNativeContext()) { | 319 while (!context->IsNativeContext()) { |
326 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { | 320 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { |
327 // For scope analysis, debug-evaluate is equivalent to a with scope. | 321 // For scope analysis, debug-evaluate is equivalent to a with scope. |
328 outer_scope = new (zone) Scope(zone, WITH_SCOPE); | 322 outer_scope = new (zone) |
| 323 Scope(zone, WITH_SCOPE, Handle<ScopeInfo>(context->scope_info())); |
329 | 324 |
330 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the | 325 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the |
331 // function scope in which we are evaluating. | 326 // function scope in which we are evaluating. |
332 if (context->IsDebugEvaluateContext()) { | 327 if (context->IsDebugEvaluateContext()) { |
333 outer_scope->set_is_debug_evaluate_scope(); | 328 outer_scope->set_is_debug_evaluate_scope(); |
334 } | 329 } |
335 } else if (context->IsScriptContext()) { | 330 } else if (context->IsScriptContext()) { |
336 // If we reach a script context, it's the outermost context with scope | 331 // If we reach a script context, it's the outermost context with scope |
337 // info. The next context will be the native context. Install the scope | 332 // info. The next context will be the native context. Install the scope |
338 // info of this script context onto the existing script scope to avoid | 333 // info of this script context onto the existing script scope to avoid |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 Variable* function = | 1712 Variable* function = |
1718 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1713 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1719 bool is_function_var_in_context = | 1714 bool is_function_var_in_context = |
1720 function != nullptr && function->IsContextSlot(); | 1715 function != nullptr && function->IsContextSlot(); |
1721 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1716 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1722 (is_function_var_in_context ? 1 : 0); | 1717 (is_function_var_in_context ? 1 : 0); |
1723 } | 1718 } |
1724 | 1719 |
1725 } // namespace internal | 1720 } // namespace internal |
1726 } // namespace v8 | 1721 } // namespace v8 |
OLD | NEW |