Chromium Code Reviews| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 top_unresolved_(scope->unresolved_), | 105 top_unresolved_(scope->unresolved_), |
| 106 top_temp_(scope->GetClosureScope()->temps()->length()) {} | 106 top_temp_(scope->GetClosureScope()->temps()->length()) {} |
| 107 | 107 |
| 108 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, | 108 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, |
| 109 ScopeType scope_type, | 109 ScopeType scope_type, |
| 110 FunctionKind function_kind) | 110 FunctionKind function_kind) |
| 111 : Scope(zone, outer_scope, scope_type), | 111 : Scope(zone, outer_scope, scope_type), |
| 112 function_kind_(function_kind), | 112 function_kind_(function_kind), |
| 113 temps_(4, zone), | 113 temps_(4, zone), |
| 114 params_(4, zone), | 114 params_(4, zone), |
| 115 sloppy_block_function_map_(zone), | 115 sloppy_block_function_map_(zone) { |
| 116 module_descriptor_(scope_type == MODULE_SCOPE ? new (zone) | |
| 117 ModuleDescriptor(zone) | |
| 118 : NULL) { | |
| 119 SetDefaults(); | 116 SetDefaults(); |
| 117 if (scope_type == MODULE_SCOPE) { | |
| 118 module_descriptor_ = new (zone) ModuleDescriptor(zone); | |
| 119 language_mode_ = STRICT; | |
| 120 } | |
| 120 } | 121 } |
| 121 | 122 |
| 122 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 123 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
| 123 Handle<ScopeInfo> scope_info) | 124 Handle<ScopeInfo> scope_info) |
| 124 : zone_(zone), | 125 : zone_(zone), |
| 125 outer_scope_(nullptr), | 126 outer_scope_(nullptr), |
| 126 variables_(zone), | 127 variables_(zone), |
| 127 decls_(0, zone), | 128 decls_(0, zone), |
| 128 scope_info_(scope_info), | 129 scope_info_(scope_info), |
| 129 scope_type_(scope_type), | 130 scope_type_(scope_type), |
| 130 already_resolved_(true) { | 131 already_resolved_(true) { |
| 131 SetDefaults(); | 132 SetDefaults(); |
| 132 if (!scope_info.is_null()) { | 133 if (scope_type == WITH_SCOPE) { |
| 134 DCHECK(scope_info.is_null()); | |
| 135 } else { | |
| 133 scope_calls_eval_ = scope_info->CallsEval(); | 136 scope_calls_eval_ = scope_info->CallsEval(); |
| 134 language_mode_ = scope_info->language_mode(); | 137 language_mode_ = scope_info->language_mode(); |
| 135 num_heap_slots_ = scope_info_->ContextLength(); | 138 num_heap_slots_ = scope_info_->ContextLength(); |
|
neis
2016/08/16 09:21:36
Can you make these uniform (scope_info_ vs scope_i
| |
| 136 } | 139 } |
| 140 | |
| 137 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 141 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
| 138 num_heap_slots_ = Max(num_heap_slots_, | 142 num_heap_slots_ = Max(num_heap_slots_, |
| 139 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 143 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
| 140 if (inner_scope != nullptr) AddInnerScope(inner_scope); | 144 if (inner_scope != nullptr) AddInnerScope(inner_scope); |
| 141 } | 145 } |
| 142 | 146 |
| 143 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, | 147 DeclarationScope::DeclarationScope(Zone* zone, Scope* inner_scope, |
| 144 ScopeType scope_type, | 148 ScopeType scope_type, |
| 145 Handle<ScopeInfo> scope_info) | 149 Handle<ScopeInfo> scope_info) |
| 146 : Scope(zone, inner_scope, scope_type, scope_info), | 150 : Scope(zone, inner_scope, scope_type, scope_info), |
| 147 function_kind_(scope_info.is_null() ? kNormalFunction | 151 function_kind_(scope_info->function_kind()), |
| 148 : scope_info->function_kind()), | |
| 149 temps_(0, zone), | 152 temps_(0, zone), |
| 150 params_(0, zone), | 153 params_(0, zone), |
| 151 sloppy_block_function_map_(zone), | 154 sloppy_block_function_map_(zone) { |
| 152 module_descriptor_(nullptr) { | |
| 153 SetDefaults(); | 155 SetDefaults(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 Scope::Scope(Zone* zone, Scope* inner_scope, | 158 Scope::Scope(Zone* zone, Scope* inner_scope, |
| 157 const AstRawString* catch_variable_name) | 159 const AstRawString* catch_variable_name) |
| 158 : zone_(zone), | 160 : zone_(zone), |
| 159 outer_scope_(nullptr), | 161 outer_scope_(nullptr), |
| 160 variables_(zone), | 162 variables_(zone), |
| 161 decls_(0, zone), | 163 decls_(0, zone), |
| 162 scope_type_(CATCH_SCOPE), | 164 scope_type_(CATCH_SCOPE), |
| 163 already_resolved_(true) { | 165 already_resolved_(true) { |
| 164 SetDefaults(); | 166 SetDefaults(); |
| 165 if (inner_scope != nullptr) AddInnerScope(inner_scope); | 167 if (inner_scope != nullptr) AddInnerScope(inner_scope); |
| 166 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 168 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 167 Variable* variable = | 169 Variable* variable = |
| 168 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, | 170 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, |
| 169 kCreatedInitialized); | 171 kCreatedInitialized); |
| 170 AllocateHeapSlot(variable); | 172 AllocateHeapSlot(variable); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void DeclarationScope::SetDefaults() { | 175 void DeclarationScope::SetDefaults() { |
| 174 is_declaration_scope_ = true; | 176 is_declaration_scope_ = true; |
| 175 has_simple_parameters_ = true; | 177 has_simple_parameters_ = true; |
| 176 receiver_ = nullptr; | 178 receiver_ = nullptr; |
| 177 new_target_ = nullptr; | 179 new_target_ = nullptr; |
| 178 function_ = nullptr; | 180 function_ = nullptr; |
| 179 arguments_ = nullptr; | 181 arguments_ = nullptr; |
| 180 this_function_ = nullptr; | 182 this_function_ = nullptr; |
| 181 arity_ = 0; | 183 arity_ = 0; |
| 182 rest_parameter_ = NULL; | 184 rest_parameter_ = nullptr; |
| 183 rest_index_ = -1; | 185 rest_index_ = -1; |
| 186 module_descriptor_ = nullptr; | |
| 184 } | 187 } |
| 185 | 188 |
| 186 void Scope::SetDefaults() { | 189 void Scope::SetDefaults() { |
| 187 #ifdef DEBUG | 190 #ifdef DEBUG |
| 188 scope_name_ = nullptr; | 191 scope_name_ = nullptr; |
| 189 #endif | 192 #endif |
| 190 inner_scope_ = nullptr; | 193 inner_scope_ = nullptr; |
| 191 sibling_ = nullptr; | 194 sibling_ = nullptr; |
| 192 unresolved_ = nullptr; | 195 unresolved_ = nullptr; |
| 193 dynamics_ = nullptr; | 196 dynamics_ = nullptr; |
| 194 | 197 |
| 195 start_position_ = kNoSourcePosition; | 198 start_position_ = kNoSourcePosition; |
| 196 end_position_ = kNoSourcePosition; | 199 end_position_ = kNoSourcePosition; |
| 197 | 200 |
| 198 num_stack_slots_ = 0; | 201 num_stack_slots_ = 0; |
| 199 num_heap_slots_ = 0; | 202 num_heap_slots_ = 0; |
| 200 num_global_slots_ = 0; | 203 num_global_slots_ = 0; |
| 201 | 204 |
| 202 language_mode_ = is_module_scope() ? STRICT : SLOPPY; | 205 language_mode_ = SLOPPY; |
| 203 | 206 |
| 204 scope_inside_with_ = false; | 207 scope_inside_with_ = false; |
| 205 scope_calls_eval_ = false; | 208 scope_calls_eval_ = false; |
| 206 scope_uses_super_property_ = false; | 209 scope_uses_super_property_ = false; |
| 207 has_arguments_parameter_ = false; | 210 has_arguments_parameter_ = false; |
| 208 asm_module_ = false; | 211 asm_module_ = false; |
| 209 asm_function_ = false; | 212 asm_function_ = false; |
| 210 scope_nonlinear_ = false; | 213 scope_nonlinear_ = false; |
| 211 is_hidden_ = false; | 214 is_hidden_ = false; |
| 212 is_debug_evaluate_scope_ = false; | 215 is_debug_evaluate_scope_ = false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 229 DeclarationScope* script_scope, | 232 DeclarationScope* script_scope, |
| 230 AstValueFactory* ast_value_factory, | 233 AstValueFactory* ast_value_factory, |
| 231 DeserializationMode deserialization_mode) { | 234 DeserializationMode deserialization_mode) { |
| 232 // Reconstruct the outer scope chain from a closure's context chain. | 235 // Reconstruct the outer scope chain from a closure's context chain. |
| 233 Scope* current_scope = nullptr; | 236 Scope* current_scope = nullptr; |
| 234 Scope* innermost_scope = nullptr; | 237 Scope* innermost_scope = nullptr; |
| 235 while (!context->IsNativeContext()) { | 238 while (!context->IsNativeContext()) { |
| 236 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { | 239 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { |
| 237 // For scope analysis, debug-evaluate is equivalent to a with scope. | 240 // For scope analysis, debug-evaluate is equivalent to a with scope. |
| 238 Scope* with_scope = new (zone) | 241 Scope* with_scope = new (zone) |
| 239 Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>::null()); | 242 Scope(zone, current_scope, WITH_SCOPE, Handle<ScopeInfo>()); |
| 240 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the | 243 // TODO(yangguo): Remove once debug-evaluate properly keeps track of the |
| 241 // function scope in which we are evaluating. | 244 // function scope in which we are evaluating. |
| 242 if (context->IsDebugEvaluateContext()) { | 245 if (context->IsDebugEvaluateContext()) { |
| 243 with_scope->set_is_debug_evaluate_scope(); | 246 with_scope->set_is_debug_evaluate_scope(); |
| 244 } | 247 } |
| 245 current_scope = with_scope; | 248 current_scope = with_scope; |
| 246 // All the inner scopes are inside a with. | 249 // All the inner scopes are inside a with. |
| 247 for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) { | 250 for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) { |
| 248 s->scope_inside_with_ = true; | 251 s->scope_inside_with_ = true; |
| 249 } | 252 } |
| 250 } else if (context->IsScriptContext()) { | 253 } else if (context->IsScriptContext()) { |
| 251 ScopeInfo* scope_info = context->scope_info(); | 254 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); |
| 252 current_scope = new (zone) DeclarationScope( | 255 current_scope = new (zone) |
| 253 zone, current_scope, SCRIPT_SCOPE, Handle<ScopeInfo>(scope_info)); | 256 DeclarationScope(zone, current_scope, SCRIPT_SCOPE, scope_info); |
| 254 } else if (context->IsFunctionContext()) { | 257 } else if (context->IsFunctionContext()) { |
| 255 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); | 258 Handle<ScopeInfo> scope_info(context->closure()->shared()->scope_info(), |
| 256 current_scope = new (zone) DeclarationScope( | 259 isolate); |
| 257 zone, current_scope, FUNCTION_SCOPE, Handle<ScopeInfo>(scope_info)); | 260 current_scope = new (zone) |
| 261 DeclarationScope(zone, current_scope, FUNCTION_SCOPE, scope_info); | |
| 258 if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true; | 262 if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true; |
| 259 if (scope_info->IsAsmModule()) current_scope->asm_module_ = true; | 263 if (scope_info->IsAsmModule()) current_scope->asm_module_ = true; |
| 260 } else if (context->IsBlockContext()) { | 264 } else if (context->IsBlockContext()) { |
| 261 ScopeInfo* scope_info = context->scope_info(); | 265 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); |
| 262 if (scope_info->is_declaration_scope()) { | 266 if (scope_info->is_declaration_scope()) { |
| 263 current_scope = new (zone) DeclarationScope( | 267 current_scope = new (zone) |
| 264 zone, current_scope, BLOCK_SCOPE, Handle<ScopeInfo>(scope_info)); | 268 DeclarationScope(zone, current_scope, BLOCK_SCOPE, scope_info); |
| 265 } else { | 269 } else { |
| 266 current_scope = new (zone) Scope(zone, current_scope, BLOCK_SCOPE, | 270 current_scope = |
| 267 Handle<ScopeInfo>(scope_info)); | 271 new (zone) Scope(zone, current_scope, BLOCK_SCOPE, scope_info); |
| 268 } | 272 } |
| 269 } else { | 273 } else { |
| 270 DCHECK(context->IsCatchContext()); | 274 DCHECK(context->IsCatchContext()); |
| 271 String* name = context->catch_name(); | 275 String* name = context->catch_name(); |
| 272 current_scope = | 276 current_scope = |
| 273 new (zone) Scope(zone, current_scope, | 277 new (zone) Scope(zone, current_scope, |
| 274 ast_value_factory->GetString(handle(name, isolate))); | 278 ast_value_factory->GetString(handle(name, isolate))); |
| 275 } | 279 } |
| 276 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { | 280 if (deserialization_mode == DeserializationMode::kDeserializeOffHeap) { |
| 277 current_scope->DeserializeScopeInfo(isolate, ast_value_factory); | 281 current_scope->DeserializeScopeInfo(isolate, ast_value_factory); |
| (...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1772 function != nullptr && function->IsContextSlot(); | 1776 function != nullptr && function->IsContextSlot(); |
| 1773 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1777 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1774 (is_function_var_in_context ? 1 : 0); | 1778 (is_function_var_in_context ? 1 : 0); |
| 1775 } | 1779 } |
| 1776 | 1780 |
| 1777 | 1781 |
| 1778 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1782 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1779 | 1783 |
| 1780 } // namespace internal | 1784 } // namespace internal |
| 1781 } // namespace v8 | 1785 } // namespace v8 |
| OLD | NEW |