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