Chromium Code Reviews| 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1570 | 1570 |
| 1571 // The same parameter may occur multiple times in the parameters_ list. | 1571 // The same parameter may occur multiple times in the parameters_ list. |
| 1572 // If it does, and if it is not copied into the context object, it must | 1572 // If it does, and if it is not copied into the context object, it must |
| 1573 // receive the highest parameter index for that parameter; thus iteration | 1573 // receive the highest parameter index for that parameter; thus iteration |
| 1574 // order is relevant! | 1574 // order is relevant! |
| 1575 for (int i = params_.length() - 1; i >= 0; --i) { | 1575 for (int i = params_.length() - 1; i >= 0; --i) { |
| 1576 Variable* var = params_[i]; | 1576 Variable* var = params_[i]; |
| 1577 if (var == rest_parameter_) continue; | 1577 if (var == rest_parameter_) continue; |
| 1578 | 1578 |
| 1579 DCHECK(var->scope() == this); | 1579 DCHECK(var->scope() == this); |
| 1580 if (uses_sloppy_arguments || has_forced_context_allocation()) { | 1580 if (uses_sloppy_arguments) { |
| 1581 // Force context allocation of the parameter. | 1581 // Force context allocation of the parameter. |
|
neis
2016/08/09 07:15:26
Maybe remove the comment too as it doesn't add any
adamk
2016/08/09 16:29:11
Done.
| |
| 1582 var->ForceContextAllocation(); | 1582 var->ForceContextAllocation(); |
| 1583 } | 1583 } |
| 1584 AllocateParameter(var, i); | 1584 AllocateParameter(var, i); |
| 1585 } | 1585 } |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 void DeclarationScope::AllocateParameter(Variable* var, int index) { | 1588 void DeclarationScope::AllocateParameter(Variable* var, int index) { |
| 1589 if (MustAllocate(var)) { | 1589 if (MustAllocate(var)) { |
| 1590 if (MustAllocateInContext(var)) { | 1590 if (MustAllocateInContext(var)) { |
| 1591 DCHECK(var->IsUnallocated() || var->IsContextSlot()); | 1591 DCHECK(var->IsUnallocated() || var->IsContextSlot()); |
| 1592 if (var->IsUnallocated()) { | 1592 if (var->IsUnallocated()) { |
| 1593 AllocateHeapSlot(var); | 1593 AllocateHeapSlot(var); |
| 1594 } | 1594 } |
| 1595 } else { | 1595 } else { |
| 1596 DCHECK(var->IsUnallocated() || var->IsParameter()); | 1596 DCHECK(var->IsUnallocated() || var->IsParameter()); |
| 1597 if (var->IsUnallocated()) { | 1597 if (var->IsUnallocated()) { |
| 1598 var->AllocateTo(VariableLocation::PARAMETER, index); | 1598 var->AllocateTo(VariableLocation::PARAMETER, index); |
| 1599 } | 1599 } |
| 1600 } | 1600 } |
| 1601 } else { | 1601 } else { |
| 1602 DCHECK(!var->IsGlobalSlot()); | 1602 DCHECK(!var->IsGlobalSlot()); |
| 1603 } | 1603 } |
| 1604 } | 1604 } |
| 1605 | 1605 |
| 1606 void DeclarationScope::AllocateReceiver() { | 1606 void DeclarationScope::AllocateReceiver() { |
| 1607 if (!has_this_declaration()) return; | 1607 if (!has_this_declaration()) return; |
| 1608 DCHECK_NOT_NULL(receiver()); | 1608 DCHECK_NOT_NULL(receiver()); |
| 1609 DCHECK_EQ(receiver()->scope(), this); | 1609 DCHECK_EQ(receiver()->scope(), this); |
| 1610 | |
| 1611 if (has_forced_context_allocation()) { | |
| 1612 // Force context allocation of the receiver. | |
| 1613 receiver()->ForceContextAllocation(); | |
| 1614 } | |
| 1615 AllocateParameter(receiver(), -1); | 1610 AllocateParameter(receiver(), -1); |
| 1616 } | 1611 } |
| 1617 | 1612 |
| 1618 void Scope::AllocateNonParameterLocal(Variable* var, | 1613 void Scope::AllocateNonParameterLocal(Variable* var, |
| 1619 AstValueFactory* ast_value_factory) { | 1614 AstValueFactory* ast_value_factory) { |
| 1620 DCHECK(var->scope() == this); | 1615 DCHECK(var->scope() == this); |
| 1621 DCHECK(var->raw_name() != ast_value_factory->dot_result_string() || | 1616 DCHECK(var->raw_name() != ast_value_factory->dot_result_string() || |
| 1622 !var->IsStackLocal()); | 1617 !var->IsStackLocal()); |
| 1623 if (var->IsUnallocated() && MustAllocate(var)) { | 1618 if (var->IsUnallocated() && MustAllocate(var)) { |
| 1624 if (MustAllocateInContext(var)) { | 1619 if (MustAllocateInContext(var)) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1782 function != NULL && function->proxy()->var()->IsContextSlot(); | 1777 function != NULL && function->proxy()->var()->IsContextSlot(); |
| 1783 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1778 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1784 (is_function_var_in_context ? 1 : 0); | 1779 (is_function_var_in_context ? 1 : 0); |
| 1785 } | 1780 } |
| 1786 | 1781 |
| 1787 | 1782 |
| 1788 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1783 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1789 | 1784 |
| 1790 } // namespace internal | 1785 } // namespace internal |
| 1791 } // namespace v8 | 1786 } // namespace v8 |
| OLD | NEW |