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