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 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 | 1483 |
1484 | 1484 |
1485 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { | 1485 void Scope::AllocateDeclaredGlobal(Isolate* isolate, Variable* var) { |
1486 DCHECK(var->scope() == this); | 1486 DCHECK(var->scope() == this); |
1487 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || | 1487 DCHECK(!var->IsVariable(isolate->factory()->dot_result_string()) || |
1488 !var->IsStackLocal()); | 1488 !var->IsStackLocal()); |
1489 if (var->IsUnallocated()) { | 1489 if (var->IsUnallocated()) { |
1490 if (var->IsStaticGlobalObjectProperty()) { | 1490 if (var->IsStaticGlobalObjectProperty()) { |
1491 DCHECK_EQ(-1, var->index()); | 1491 DCHECK_EQ(-1, var->index()); |
1492 DCHECK(var->name()->IsString()); | 1492 DCHECK(var->name()->IsString()); |
1493 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_); | 1493 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_++); |
1494 num_global_slots_++; | 1494 num_global_slots_++; |
1495 // Each global variable occupies two slots in the context: for reads | |
1496 // and writes. | |
1497 num_heap_slots_ += 2; | |
1498 } else { | 1495 } else { |
1499 // There must be only DYNAMIC_GLOBAL in the script scope. | 1496 // There must be only DYNAMIC_GLOBAL in the script scope. |
1500 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); | 1497 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
1501 } | 1498 } |
1502 } | 1499 } |
1503 } | 1500 } |
1504 | 1501 |
1505 | 1502 |
1506 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { | 1503 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
1507 // All variables that have no rewrite yet are non-parameter locals. | 1504 // All variables that have no rewrite yet are non-parameter locals. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 int Scope::StackLocalCount() const { | 1614 int Scope::StackLocalCount() const { |
1618 return num_stack_slots() - | 1615 return num_stack_slots() - |
1619 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1616 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1620 } | 1617 } |
1621 | 1618 |
1622 | 1619 |
1623 int Scope::ContextLocalCount() const { | 1620 int Scope::ContextLocalCount() const { |
1624 if (num_heap_slots() == 0) return 0; | 1621 if (num_heap_slots() == 0) return 0; |
1625 bool is_function_var_in_context = | 1622 bool is_function_var_in_context = |
1626 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1623 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1627 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1624 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1628 2 * num_global_slots() - (is_function_var_in_context ? 1 : 0); | 1625 (is_function_var_in_context ? 1 : 0); |
1629 } | 1626 } |
1630 | 1627 |
1631 | 1628 |
1632 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1629 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1630 |
1633 } // namespace internal | 1631 } // namespace internal |
1634 } // namespace v8 | 1632 } // namespace v8 |
OLD | NEW |