| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 PrintF("global : "); | 284 PrintF("global : "); |
| 285 top->interface()->Print(); | 285 top->interface()->Print(); |
| 286 } | 286 } |
| 287 #endif | 287 #endif |
| 288 | 288 |
| 289 info->PrepareForCompilation(scope); | 289 info->PrepareForCompilation(scope); |
| 290 return true; | 290 return true; |
| 291 } | 291 } |
| 292 | 292 |
| 293 | 293 |
| 294 void Scope::Initialize() { | 294 void Scope::Initialize(bool uninitialized_this) { |
| 295 DCHECK(!already_resolved()); | 295 DCHECK(!already_resolved()); |
| 296 | 296 |
| 297 // Add this scope as a new inner scope of the outer scope. | 297 // Add this scope as a new inner scope of the outer scope. |
| 298 if (outer_scope_ != NULL) { | 298 if (outer_scope_ != NULL) { |
| 299 outer_scope_->inner_scopes_.Add(this, zone()); | 299 outer_scope_->inner_scopes_.Add(this, zone()); |
| 300 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); | 300 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); |
| 301 } else { | 301 } else { |
| 302 scope_inside_with_ = is_with_scope(); | 302 scope_inside_with_ = is_with_scope(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 // Declare convenience variables. | 305 // Declare convenience variables. |
| 306 // Declare and allocate receiver (even for the script scope, and even | 306 // Declare and allocate receiver (even for the script scope, and even |
| 307 // if naccesses_ == 0). | 307 // if naccesses_ == 0). |
| 308 // NOTE: When loading parameters in the script scope, we must take | 308 // NOTE: When loading parameters in the script scope, we must take |
| 309 // care not to access them as properties of the global object, but | 309 // care not to access them as properties of the global object, but |
| 310 // instead load them directly from the stack. Currently, the only | 310 // instead load them directly from the stack. Currently, the only |
| 311 // such parameter is 'this' which is passed on the stack when | 311 // such parameter is 'this' which is passed on the stack when |
| 312 // invoking scripts | 312 // invoking scripts |
| 313 if (is_declaration_scope()) { | 313 if (is_declaration_scope()) { |
| 314 Variable* var = | 314 DCHECK(!uninitialized_this || is_function_scope()); |
| 315 variables_.Declare(this, | 315 DCHECK(FLAG_experimental_classes || !uninitialized_this); |
| 316 ast_value_factory_->this_string(), | 316 Variable* var = variables_.Declare( |
| 317 VAR, | 317 this, ast_value_factory_->this_string(), |
| 318 false, | 318 uninitialized_this ? CONST : VAR, false, Variable::THIS, |
| 319 Variable::THIS, | 319 uninitialized_this ? kNeedsInitialization : kCreatedInitialized); |
| 320 kCreatedInitialized); | |
| 321 var->AllocateTo(Variable::PARAMETER, -1); | 320 var->AllocateTo(Variable::PARAMETER, -1); |
| 322 receiver_ = var; | 321 receiver_ = var; |
| 323 } else { | 322 } else { |
| 324 DCHECK(outer_scope() != NULL); | 323 DCHECK(outer_scope() != NULL); |
| 325 receiver_ = outer_scope()->receiver(); | 324 receiver_ = outer_scope()->receiver(); |
| 326 } | 325 } |
| 327 | 326 |
| 328 if (is_function_scope()) { | 327 if (is_function_scope()) { |
| 329 // Declare 'arguments' variable which exists in all functions. | 328 // Declare 'arguments' variable which exists in all functions. |
| 330 // Note that it might never be accessed, in which case it won't be | 329 // Note that it might never be accessed, in which case it won't be |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 } | 1438 } |
| 1440 | 1439 |
| 1441 | 1440 |
| 1442 int Scope::ContextLocalCount() const { | 1441 int Scope::ContextLocalCount() const { |
| 1443 if (num_heap_slots() == 0) return 0; | 1442 if (num_heap_slots() == 0) return 0; |
| 1444 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1443 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1445 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1444 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1446 } | 1445 } |
| 1447 | 1446 |
| 1448 } } // namespace v8::internal | 1447 } } // namespace v8::internal |
| OLD | NEW |