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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1610 // If result_saved is true the result is on top of the stack. If | 1610 // If result_saved is true the result is on top of the stack. If |
| 1611 // result_saved is false the result is in eax. | 1611 // result_saved is false the result is in eax. |
| 1612 bool result_saved = false; | 1612 bool result_saved = false; |
| 1613 | 1613 |
| 1614 // Mark all computed expressions that are bound to a key that | 1614 // Mark all computed expressions that are bound to a key that |
| 1615 // is shadowed by a later occurrence of the same key. For the | 1615 // is shadowed by a later occurrence of the same key. For the |
| 1616 // marked expressions, no store code is emitted. | 1616 // marked expressions, no store code is emitted. |
| 1617 expr->CalculateEmitStore(zone()); | 1617 expr->CalculateEmitStore(zone()); |
| 1618 | 1618 |
| 1619 AccessorTable accessor_table(zone()); | 1619 AccessorTable accessor_table(zone()); |
| 1620 for (int i = 0; i < expr->properties()->length(); i++) { | 1620 int property_index = 0; |
| 1621 ObjectLiteral::Property* property = expr->properties()->at(i); | 1621 for (; property_index < expr->properties()->length(); property_index++) { |
| 1622 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
| 1623 if (property->is_computed_name()) break; | |
| 1622 if (property->IsCompileTimeValue()) continue; | 1624 if (property->IsCompileTimeValue()) continue; |
| 1623 | 1625 |
| 1624 Literal* key = property->key(); | 1626 Literal* key = property->key()->AsLiteral(); |
| 1625 Expression* value = property->value(); | 1627 Expression* value = property->value(); |
| 1626 if (!result_saved) { | 1628 if (!result_saved) { |
| 1627 __ push(eax); // Save result on the stack | 1629 __ push(eax); // Save result on the stack |
| 1628 result_saved = true; | 1630 result_saved = true; |
| 1629 } | 1631 } |
| 1630 switch (property->kind()) { | 1632 switch (property->kind()) { |
| 1631 case ObjectLiteral::Property::CONSTANT: | 1633 case ObjectLiteral::Property::CONSTANT: |
| 1632 UNREACHABLE(); | 1634 UNREACHABLE(); |
| 1633 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 1635 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1634 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); | 1636 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1694 __ push(Operand(esp, 0)); // Duplicate receiver. | 1696 __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1695 VisitForStackValue(it->first); | 1697 VisitForStackValue(it->first); |
| 1696 EmitAccessor(it->second->getter); | 1698 EmitAccessor(it->second->getter); |
| 1697 EmitSetHomeObjectIfNeeded(it->second->getter, 2); | 1699 EmitSetHomeObjectIfNeeded(it->second->getter, 2); |
| 1698 EmitAccessor(it->second->setter); | 1700 EmitAccessor(it->second->setter); |
| 1699 EmitSetHomeObjectIfNeeded(it->second->setter, 3); | 1701 EmitSetHomeObjectIfNeeded(it->second->setter, 3); |
| 1700 __ push(Immediate(Smi::FromInt(NONE))); | 1702 __ push(Immediate(Smi::FromInt(NONE))); |
| 1701 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); | 1703 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); |
| 1702 } | 1704 } |
| 1703 | 1705 |
| 1706 // Object literals have two parts. The "static" part on the left contains no | |
| 1707 // computed property names, and so we can compute its map ahead of time; see | |
| 1708 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
| 1709 // starts with the first computed property name, and continues with all | |
| 1710 // properties to its right. All the code from above initializes the static | |
| 1711 // component of the object literal, and arranges for the map of the result to | |
| 1712 // reflect the static order in which the keys appear. For the dynamic | |
| 1713 // properties, we compile them into a series of "SetOwnProperty" runtime | |
| 1714 // calls. This will preserve insertion order. | |
| 1715 for (; property_index < expr->properties()->length(); property_index++) { | |
| 1716 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
| 1717 | |
| 1718 Expression* key = property->key(); | |
| 1719 Expression* value = property->value(); | |
| 1720 if (!result_saved) { | |
| 1721 __ push(eax); // Save result on the stack | |
| 1722 result_saved = true; | |
| 1723 } | |
| 1724 | |
| 1725 switch (property->kind()) { | |
| 1726 case ObjectLiteral::Property::CONSTANT: | |
| 1727 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
| 1728 case ObjectLiteral::Property::COMPUTED: | |
| 1729 __ push(Operand(esp, 0)); // Duplicate receiver. | |
| 1730 VisitForStackValue(key); | |
| 1731 // TODO(arv): ToName for computed properties. | |
|
arv (Not doing code reviews)
2014/12/10 23:38:13
todo is done ;-)
| |
| 1732 if (property->is_computed_name()) { | |
| 1733 __ InvokeBuiltin(Builtins::TO_NAME, CALL_FUNCTION); | |
|
Dmitry Lomov (no reviews)
2014/12/11 12:34:35
You can probably just call runtime function here,
arv (Not doing code reviews)
2014/12/11 15:47:24
It is not clear to me why that is preferred?
Dmitry Lomov (no reviews)
2014/12/11 16:01:15
Saves you adding a builtin just for this case
| |
| 1734 __ push(eax); | |
| 1735 } | |
| 1736 VisitForStackValue(value); | |
| 1737 if (property->emit_store()) { | |
| 1738 __ push(Immediate(Smi::FromInt(NONE))); | |
| 1739 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4); | |
| 1740 } else { | |
| 1741 __ Drop(3); | |
| 1742 } | |
| 1743 break; | |
| 1744 case ObjectLiteral::Property::PROTOTYPE: | |
| 1745 DCHECK(!property->is_computed_name()); | |
| 1746 __ push(Operand(esp, 0)); // Duplicate receiver. | |
| 1747 VisitForStackValue(value); | |
| 1748 if (property->emit_store()) { | |
| 1749 __ CallRuntime(Runtime::kInternalSetPrototype, 2); | |
| 1750 } else { | |
| 1751 __ Drop(2); | |
| 1752 } | |
| 1753 break; | |
| 1754 | |
| 1755 case ObjectLiteral::Property::GETTER: | |
| 1756 __ push(Operand(esp, 0)); // Duplicate receiver. | |
| 1757 VisitForStackValue(key); | |
| 1758 VisitForStackValue(value); | |
| 1759 __ CallRuntime(Runtime::kDefineClassGetter, 3); | |
|
arv (Not doing code reviews)
2014/12/10 23:38:13
I'll rename these two and move them to runtime-obj
arv (Not doing code reviews)
2014/12/11 23:10:33
Done.
| |
| 1760 break; | |
| 1761 | |
| 1762 case ObjectLiteral::Property::SETTER: | |
| 1763 __ push(Operand(esp, 0)); // Duplicate receiver. | |
| 1764 VisitForStackValue(key); | |
| 1765 VisitForStackValue(value); | |
| 1766 __ CallRuntime(Runtime::kDefineClassSetter, 3); | |
| 1767 break; | |
| 1768 } | |
| 1769 } | |
| 1770 | |
| 1704 if (expr->has_function()) { | 1771 if (expr->has_function()) { |
| 1705 DCHECK(result_saved); | 1772 DCHECK(result_saved); |
| 1706 __ push(Operand(esp, 0)); | 1773 __ push(Operand(esp, 0)); |
| 1707 __ CallRuntime(Runtime::kToFastProperties, 1); | 1774 __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1708 } | 1775 } |
| 1709 | 1776 |
| 1710 if (result_saved) { | 1777 if (result_saved) { |
| 1711 context()->PlugTOS(); | 1778 context()->PlugTOS(); |
| 1712 } else { | 1779 } else { |
| 1713 context()->Plug(eax); | 1780 context()->Plug(eax); |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2387 __ push(eax); | 2454 __ push(eax); |
| 2388 | 2455 |
| 2389 // No access check is needed here since the constructor is created by the | 2456 // No access check is needed here since the constructor is created by the |
| 2390 // class literal. | 2457 // class literal. |
| 2391 Register scratch = ebx; | 2458 Register scratch = ebx; |
| 2392 __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); | 2459 __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2393 __ Push(scratch); | 2460 __ Push(scratch); |
| 2394 | 2461 |
| 2395 for (int i = 0; i < lit->properties()->length(); i++) { | 2462 for (int i = 0; i < lit->properties()->length(); i++) { |
| 2396 ObjectLiteral::Property* property = lit->properties()->at(i); | 2463 ObjectLiteral::Property* property = lit->properties()->at(i); |
| 2397 Literal* key = property->key()->AsLiteral(); | 2464 Expression* key = property->key(); |
| 2398 Expression* value = property->value(); | 2465 Expression* value = property->value(); |
| 2399 DCHECK(key != NULL); | 2466 DCHECK(key != NULL); |
| 2400 | 2467 |
| 2401 if (property->is_static()) { | 2468 if (property->is_static()) { |
| 2402 __ push(Operand(esp, kPointerSize)); // constructor | 2469 __ push(Operand(esp, kPointerSize)); // constructor |
| 2403 } else { | 2470 } else { |
| 2404 __ push(Operand(esp, 0)); // prototype | 2471 __ push(Operand(esp, 0)); // prototype |
| 2405 } | 2472 } |
| 2406 VisitForStackValue(key); | 2473 VisitForStackValue(key); |
| 2407 VisitForStackValue(value); | 2474 VisitForStackValue(value); |
| (...skipping 2768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5176 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5243 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5177 Assembler::target_address_at(call_target_address, | 5244 Assembler::target_address_at(call_target_address, |
| 5178 unoptimized_code)); | 5245 unoptimized_code)); |
| 5179 return OSR_AFTER_STACK_CHECK; | 5246 return OSR_AFTER_STACK_CHECK; |
| 5180 } | 5247 } |
| 5181 | 5248 |
| 5182 | 5249 |
| 5183 } } // namespace v8::internal | 5250 } } // namespace v8::internal |
| 5184 | 5251 |
| 5185 #endif // V8_TARGET_ARCH_IA32 | 5252 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |