| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/scopes.h" | 7 #include "src/scopes.h" |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 | 142 |
| 143 void Scope::SetDefaults(ScopeType scope_type, | 143 void Scope::SetDefaults(ScopeType scope_type, |
| 144 Scope* outer_scope, | 144 Scope* outer_scope, |
| 145 Handle<ScopeInfo> scope_info) { | 145 Handle<ScopeInfo> scope_info) { |
| 146 outer_scope_ = outer_scope; | 146 outer_scope_ = outer_scope; |
| 147 scope_type_ = scope_type; | 147 scope_type_ = scope_type; |
| 148 scope_name_ = ast_value_factory_->empty_string(); | 148 scope_name_ = ast_value_factory_->empty_string(); |
| 149 dynamics_ = NULL; | 149 dynamics_ = NULL; |
| 150 receiver_ = NULL; | 150 receiver_ = NULL; |
| 151 new_target_ = nullptr; | |
| 152 function_ = NULL; | 151 function_ = NULL; |
| 153 arguments_ = NULL; | 152 arguments_ = NULL; |
| 154 illegal_redecl_ = NULL; | 153 illegal_redecl_ = NULL; |
| 155 scope_inside_with_ = false; | 154 scope_inside_with_ = false; |
| 156 scope_contains_with_ = false; | 155 scope_contains_with_ = false; |
| 157 scope_calls_eval_ = false; | 156 scope_calls_eval_ = false; |
| 158 scope_uses_arguments_ = false; | 157 scope_uses_arguments_ = false; |
| 159 scope_uses_super_property_ = false; | 158 scope_uses_super_property_ = false; |
| 160 scope_uses_super_constructor_call_ = false; | 159 scope_uses_super_constructor_call_ = false; |
| 161 scope_uses_this_ = false; | 160 scope_uses_this_ = false; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 PrintF("global : "); | 280 PrintF("global : "); |
| 282 top->interface()->Print(); | 281 top->interface()->Print(); |
| 283 } | 282 } |
| 284 #endif | 283 #endif |
| 285 | 284 |
| 286 info->PrepareForCompilation(scope); | 285 info->PrepareForCompilation(scope); |
| 287 return true; | 286 return true; |
| 288 } | 287 } |
| 289 | 288 |
| 290 | 289 |
| 291 void Scope::Initialize(bool subclass_constructor) { | 290 void Scope::Initialize(bool uninitialized_this) { |
| 292 DCHECK(!already_resolved()); | 291 DCHECK(!already_resolved()); |
| 293 | 292 |
| 294 // Add this scope as a new inner scope of the outer scope. | 293 // Add this scope as a new inner scope of the outer scope. |
| 295 if (outer_scope_ != NULL) { | 294 if (outer_scope_ != NULL) { |
| 296 outer_scope_->inner_scopes_.Add(this, zone()); | 295 outer_scope_->inner_scopes_.Add(this, zone()); |
| 297 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 296 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
| 298 } else { | 297 } else { |
| 299 scope_inside_with_ = is_with_scope(); | 298 scope_inside_with_ = is_with_scope(); |
| 300 } | 299 } |
| 301 | 300 |
| 302 // Declare convenience variables. | 301 // Declare convenience variables. |
| 303 // Declare and allocate receiver (even for the script scope, and even | 302 // Declare and allocate receiver (even for the script scope, and even |
| 304 // if naccesses_ == 0). | 303 // if naccesses_ == 0). |
| 305 // NOTE: When loading parameters in the script scope, we must take | 304 // NOTE: When loading parameters in the script scope, we must take |
| 306 // care not to access them as properties of the global object, but | 305 // care not to access them as properties of the global object, but |
| 307 // instead load them directly from the stack. Currently, the only | 306 // instead load them directly from the stack. Currently, the only |
| 308 // such parameter is 'this' which is passed on the stack when | 307 // such parameter is 'this' which is passed on the stack when |
| 309 // invoking scripts | 308 // invoking scripts |
| 310 if (is_declaration_scope()) { | 309 if (is_declaration_scope()) { |
| 311 DCHECK(!subclass_constructor || is_function_scope()); | 310 DCHECK(!uninitialized_this || is_function_scope()); |
| 312 DCHECK(FLAG_experimental_classes || !subclass_constructor); | 311 DCHECK(FLAG_experimental_classes || !uninitialized_this); |
| 313 Variable* var = variables_.Declare( | 312 Variable* var = variables_.Declare( |
| 314 this, ast_value_factory_->this_string(), | 313 this, ast_value_factory_->this_string(), |
| 315 subclass_constructor ? CONST : VAR, false, Variable::THIS, | 314 uninitialized_this ? CONST : VAR, false, Variable::THIS, |
| 316 subclass_constructor ? kNeedsInitialization : kCreatedInitialized); | 315 uninitialized_this ? kNeedsInitialization : kCreatedInitialized); |
| 317 var->AllocateTo(Variable::PARAMETER, -1); | 316 var->AllocateTo(Variable::PARAMETER, -1); |
| 318 receiver_ = var; | 317 receiver_ = var; |
| 319 | |
| 320 if (subclass_constructor) { | |
| 321 new_target_ = variables_.Declare( | |
| 322 this, ast_value_factory_->new_target_string(), CONST, false, | |
| 323 Variable::NEW_TARGET, kCreatedInitialized); | |
| 324 new_target_->AllocateTo(Variable::PARAMETER, -2); | |
| 325 new_target_->set_is_used(); | |
| 326 } | |
| 327 } else { | 318 } else { |
| 328 DCHECK(outer_scope() != NULL); | 319 DCHECK(outer_scope() != NULL); |
| 329 receiver_ = outer_scope()->receiver(); | 320 receiver_ = outer_scope()->receiver(); |
| 330 } | 321 } |
| 331 | 322 |
| 332 if (is_function_scope()) { | 323 if (is_function_scope()) { |
| 333 // Declare 'arguments' variable which exists in all functions. | 324 // Declare 'arguments' variable which exists in all functions. |
| 334 // Note that it might never be accessed, in which case it won't be | 325 // Note that it might never be accessed, in which case it won't be |
| 335 // allocated during variable allocation. | 326 // allocated during variable allocation. |
| 336 variables_.Declare(this, | 327 variables_.Declare(this, |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 inner->asm_function_ = true; | 1194 inner->asm_function_ = true; |
| 1204 } | 1195 } |
| 1205 } | 1196 } |
| 1206 } | 1197 } |
| 1207 | 1198 |
| 1208 | 1199 |
| 1209 bool Scope::MustAllocate(Variable* var) { | 1200 bool Scope::MustAllocate(Variable* var) { |
| 1210 // Give var a read/write use if there is a chance it might be accessed | 1201 // Give var a read/write use if there is a chance it might be accessed |
| 1211 // via an eval() call. This is only possible if the variable has a | 1202 // via an eval() call. This is only possible if the variable has a |
| 1212 // visible name. | 1203 // visible name. |
| 1213 if ((var->is_this() || var->is_new_target() || !var->raw_name()->IsEmpty()) && | 1204 if ((var->is_this() || !var->raw_name()->IsEmpty()) && |
| 1214 (var->has_forced_context_allocation() || scope_calls_eval_ || | 1205 (var->has_forced_context_allocation() || |
| 1215 inner_scope_calls_eval_ || scope_contains_with_ || is_catch_scope() || | 1206 scope_calls_eval_ || |
| 1216 is_block_scope() || is_module_scope() || is_script_scope())) { | 1207 inner_scope_calls_eval_ || |
| 1208 scope_contains_with_ || |
| 1209 is_catch_scope() || |
| 1210 is_block_scope() || |
| 1211 is_module_scope() || |
| 1212 is_script_scope())) { |
| 1217 var->set_is_used(); | 1213 var->set_is_used(); |
| 1218 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); | 1214 if (scope_calls_eval_ || inner_scope_calls_eval_) var->set_maybe_assigned(); |
| 1219 } | 1215 } |
| 1220 // Global variables do not need to be allocated. | 1216 // Global variables do not need to be allocated. |
| 1221 return !var->IsGlobalObjectProperty() && var->is_used(); | 1217 return !var->IsGlobalObjectProperty() && var->is_used(); |
| 1222 } | 1218 } |
| 1223 | 1219 |
| 1224 | 1220 |
| 1225 bool Scope::MustAllocateInContext(Variable* var) { | 1221 bool Scope::MustAllocateInContext(Variable* var) { |
| 1226 // If var is accessed from an inner scope, or if there is a possibility | 1222 // If var is accessed from an inner scope, or if there is a possibility |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 } | 1433 } |
| 1438 | 1434 |
| 1439 | 1435 |
| 1440 int Scope::ContextLocalCount() const { | 1436 int Scope::ContextLocalCount() const { |
| 1441 if (num_heap_slots() == 0) return 0; | 1437 if (num_heap_slots() == 0) return 0; |
| 1442 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1438 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1443 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1439 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1444 } | 1440 } |
| 1445 | 1441 |
| 1446 } } // namespace v8::internal | 1442 } } // namespace v8::internal |
| OLD | NEW |