| 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/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/parser.h" | 10 #include "src/parser.h" |
| (...skipping 1452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1463 | 1463 |
| 1464 | 1464 |
| 1465 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { | 1465 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { |
| 1466 DCHECK(var->scope() == this); | 1466 DCHECK(var->scope() == this); |
| 1467 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || | 1467 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || |
| 1468 !var->IsStackLocal()); | 1468 !var->IsStackLocal()); |
| 1469 if (var->IsUnallocated()) { | 1469 if (var->IsUnallocated()) { |
| 1470 if (var->IsStaticGlobalObjectProperty()) { | 1470 if (var->IsStaticGlobalObjectProperty()) { |
| 1471 DCHECK_EQ(-1, var->index()); | 1471 DCHECK_EQ(-1, var->index()); |
| 1472 DCHECK(var->name()->IsString()); | 1472 DCHECK(var->name()->IsString()); |
| 1473 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_); | 1473 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_++); |
| 1474 num_global_slots_++; | 1474 num_global_slots_++; |
| 1475 // Each global variable occupies two slots in the context: for reads | |
| 1476 // and writes. | |
| 1477 num_heap_slots_ += 2; | |
| 1478 } else { | 1475 } else { |
| 1479 // There must be only DYNAMIC_GLOBAL in the script scope. | 1476 // There must be only DYNAMIC_GLOBAL in the script scope. |
| 1480 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); | 1477 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
| 1481 } | 1478 } |
| 1482 } | 1479 } |
| 1483 } | 1480 } |
| 1484 | 1481 |
| 1485 | 1482 |
| 1486 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { | 1483 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
| 1487 // All variables that have no rewrite yet are non-parameter locals. | 1484 // All variables that have no rewrite yet are non-parameter locals. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 int Scope::StackLocalCount() const { | 1590 int Scope::StackLocalCount() const { |
| 1594 return num_stack_slots() - | 1591 return num_stack_slots() - |
| 1595 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1592 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1596 } | 1593 } |
| 1597 | 1594 |
| 1598 | 1595 |
| 1599 int Scope::ContextLocalCount() const { | 1596 int Scope::ContextLocalCount() const { |
| 1600 if (num_heap_slots() == 0) return 0; | 1597 if (num_heap_slots() == 0) return 0; |
| 1601 bool is_function_var_in_context = | 1598 bool is_function_var_in_context = |
| 1602 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1599 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1603 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1600 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1604 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); | 1601 (is_function_var_in_context ? 1 : 0); |
| 1605 } | 1602 } |
| 1606 | 1603 |
| 1607 | 1604 |
| 1608 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1605 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1606 |
| 1609 } // namespace internal | 1607 } // namespace internal |
| 1610 } // namespace v8 | 1608 } // namespace v8 |
| OLD | NEW |