| 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_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 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 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 // If result_saved is true the result is on top of the stack. If | 1644 // If result_saved is true the result is on top of the stack. If |
| 1645 // result_saved is false the result is in rax. | 1645 // result_saved is false the result is in rax. |
| 1646 bool result_saved = false; | 1646 bool result_saved = false; |
| 1647 | 1647 |
| 1648 // Mark all computed expressions that are bound to a key that | 1648 // Mark all computed expressions that are bound to a key that |
| 1649 // is shadowed by a later occurrence of the same key. For the | 1649 // is shadowed by a later occurrence of the same key. For the |
| 1650 // marked expressions, no store code is emitted. | 1650 // marked expressions, no store code is emitted. |
| 1651 expr->CalculateEmitStore(zone()); | 1651 expr->CalculateEmitStore(zone()); |
| 1652 | 1652 |
| 1653 AccessorTable accessor_table(zone()); | 1653 AccessorTable accessor_table(zone()); |
| 1654 int property_index = 0; | 1654 for (int i = 0; i < expr->properties()->length(); i++) { |
| 1655 for (; property_index < expr->properties()->length(); property_index++) { | 1655 ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1656 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
| 1657 if (property->is_computed_name()) break; | |
| 1658 if (property->IsCompileTimeValue()) continue; | 1656 if (property->IsCompileTimeValue()) continue; |
| 1659 | 1657 |
| 1660 Literal* key = property->key()->AsLiteral(); | 1658 Literal* key = property->key(); |
| 1661 Expression* value = property->value(); | 1659 Expression* value = property->value(); |
| 1662 if (!result_saved) { | 1660 if (!result_saved) { |
| 1663 __ Push(rax); // Save result on the stack | 1661 __ Push(rax); // Save result on the stack |
| 1664 result_saved = true; | 1662 result_saved = true; |
| 1665 } | 1663 } |
| 1666 switch (property->kind()) { | 1664 switch (property->kind()) { |
| 1667 case ObjectLiteral::Property::CONSTANT: | 1665 case ObjectLiteral::Property::CONSTANT: |
| 1668 UNREACHABLE(); | 1666 UNREACHABLE(); |
| 1669 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 1667 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1670 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); | 1668 DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 __ Push(Operand(rsp, 0)); // Duplicate receiver. | 1728 __ Push(Operand(rsp, 0)); // Duplicate receiver. |
| 1731 VisitForStackValue(it->first); | 1729 VisitForStackValue(it->first); |
| 1732 EmitAccessor(it->second->getter); | 1730 EmitAccessor(it->second->getter); |
| 1733 EmitSetHomeObjectIfNeeded(it->second->getter, 2); | 1731 EmitSetHomeObjectIfNeeded(it->second->getter, 2); |
| 1734 EmitAccessor(it->second->setter); | 1732 EmitAccessor(it->second->setter); |
| 1735 EmitSetHomeObjectIfNeeded(it->second->setter, 3); | 1733 EmitSetHomeObjectIfNeeded(it->second->setter, 3); |
| 1736 __ Push(Smi::FromInt(NONE)); | 1734 __ Push(Smi::FromInt(NONE)); |
| 1737 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); | 1735 __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); |
| 1738 } | 1736 } |
| 1739 | 1737 |
| 1740 // Object literals have two parts. The "static" part on the left contains no | |
| 1741 // computed property names, and so we can compute its map ahead of time; see | |
| 1742 // runtime.cc::CreateObjectLiteralBoilerplate. The second "dynamic" part | |
| 1743 // starts with the first computed property name, and continues with all | |
| 1744 // properties to its right. All the code from above initializes the static | |
| 1745 // component of the object literal, and arranges for the map of the result to | |
| 1746 // reflect the static order in which the keys appear. For the dynamic | |
| 1747 // properties, we compile them into a series of "SetOwnProperty" runtime | |
| 1748 // calls. This will preserve insertion order. | |
| 1749 for (; property_index < expr->properties()->length(); property_index++) { | |
| 1750 ObjectLiteral::Property* property = expr->properties()->at(property_index); | |
| 1751 | |
| 1752 Expression* value = property->value(); | |
| 1753 if (!result_saved) { | |
| 1754 __ Push(rax); // Save result on the stack | |
| 1755 result_saved = true; | |
| 1756 } | |
| 1757 | |
| 1758 __ Push(Operand(rsp, 0)); // Duplicate receiver. | |
| 1759 | |
| 1760 if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { | |
| 1761 DCHECK(!property->is_computed_name()); | |
| 1762 VisitForStackValue(value); | |
| 1763 if (property->emit_store()) { | |
| 1764 __ CallRuntime(Runtime::kInternalSetPrototype, 2); | |
| 1765 } else { | |
| 1766 __ Drop(2); | |
| 1767 } | |
| 1768 } else { | |
| 1769 EmitPropertyKey(property); | |
| 1770 VisitForStackValue(value); | |
| 1771 | |
| 1772 switch (property->kind()) { | |
| 1773 case ObjectLiteral::Property::CONSTANT: | |
| 1774 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | |
| 1775 case ObjectLiteral::Property::COMPUTED: | |
| 1776 if (property->emit_store()) { | |
| 1777 __ Push(Smi::FromInt(NONE)); | |
| 1778 __ CallRuntime(Runtime::kDefineDataPropertyUnchecked, 4); | |
| 1779 } else { | |
| 1780 __ Drop(3); | |
| 1781 } | |
| 1782 break; | |
| 1783 | |
| 1784 case ObjectLiteral::Property::PROTOTYPE: | |
| 1785 UNREACHABLE(); | |
| 1786 break; | |
| 1787 | |
| 1788 case ObjectLiteral::Property::GETTER: | |
| 1789 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3); | |
| 1790 break; | |
| 1791 | |
| 1792 case ObjectLiteral::Property::SETTER: | |
| 1793 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3); | |
| 1794 break; | |
| 1795 } | |
| 1796 } | |
| 1797 } | |
| 1798 | |
| 1799 if (expr->has_function()) { | 1738 if (expr->has_function()) { |
| 1800 DCHECK(result_saved); | 1739 DCHECK(result_saved); |
| 1801 __ Push(Operand(rsp, 0)); | 1740 __ Push(Operand(rsp, 0)); |
| 1802 __ CallRuntime(Runtime::kToFastProperties, 1); | 1741 __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1803 } | 1742 } |
| 1804 | 1743 |
| 1805 if (result_saved) { | 1744 if (result_saved) { |
| 1806 context()->PlugTOS(); | 1745 context()->PlugTOS(); |
| 1807 } else { | 1746 } else { |
| 1808 context()->Plug(rax); | 1747 context()->Plug(rax); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 __ Push(rax); | 2386 __ Push(rax); |
| 2448 | 2387 |
| 2449 // No access check is needed here since the constructor is created by the | 2388 // No access check is needed here since the constructor is created by the |
| 2450 // class literal. | 2389 // class literal. |
| 2451 Register scratch = rbx; | 2390 Register scratch = rbx; |
| 2452 __ movp(scratch, FieldOperand(rax, JSFunction::kPrototypeOrInitialMapOffset)); | 2391 __ movp(scratch, FieldOperand(rax, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2453 __ Push(scratch); | 2392 __ Push(scratch); |
| 2454 | 2393 |
| 2455 for (int i = 0; i < lit->properties()->length(); i++) { | 2394 for (int i = 0; i < lit->properties()->length(); i++) { |
| 2456 ObjectLiteral::Property* property = lit->properties()->at(i); | 2395 ObjectLiteral::Property* property = lit->properties()->at(i); |
| 2396 Literal* key = property->key()->AsLiteral(); |
| 2457 Expression* value = property->value(); | 2397 Expression* value = property->value(); |
| 2398 DCHECK(key != NULL); |
| 2458 | 2399 |
| 2459 if (property->is_static()) { | 2400 if (property->is_static()) { |
| 2460 __ Push(Operand(rsp, kPointerSize)); // constructor | 2401 __ Push(Operand(rsp, kPointerSize)); // constructor |
| 2461 } else { | 2402 } else { |
| 2462 __ Push(Operand(rsp, 0)); // prototype | 2403 __ Push(Operand(rsp, 0)); // prototype |
| 2463 } | 2404 } |
| 2464 EmitPropertyKey(property); | 2405 VisitForStackValue(key); |
| 2465 VisitForStackValue(value); | 2406 VisitForStackValue(value); |
| 2466 EmitSetHomeObjectIfNeeded(value, 2); | 2407 EmitSetHomeObjectIfNeeded(value, 2); |
| 2467 | 2408 |
| 2468 switch (property->kind()) { | 2409 switch (property->kind()) { |
| 2469 case ObjectLiteral::Property::CONSTANT: | 2410 case ObjectLiteral::Property::CONSTANT: |
| 2470 case ObjectLiteral::Property::MATERIALIZED_LITERAL: | 2411 case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 2471 case ObjectLiteral::Property::COMPUTED: | 2412 case ObjectLiteral::Property::COMPUTED: |
| 2472 case ObjectLiteral::Property::PROTOTYPE: | 2413 case ObjectLiteral::Property::PROTOTYPE: |
| 2473 __ CallRuntime(Runtime::kDefineClassMethod, 3); | 2414 __ CallRuntime(Runtime::kDefineClassMethod, 3); |
| 2474 break; | 2415 break; |
| 2475 | 2416 |
| 2476 case ObjectLiteral::Property::GETTER: | 2417 case ObjectLiteral::Property::GETTER: |
| 2477 __ CallRuntime(Runtime::kDefineGetterPropertyUnchecked, 3); | 2418 __ CallRuntime(Runtime::kDefineClassGetter, 3); |
| 2478 break; | 2419 break; |
| 2479 | 2420 |
| 2480 case ObjectLiteral::Property::SETTER: | 2421 case ObjectLiteral::Property::SETTER: |
| 2481 __ CallRuntime(Runtime::kDefineSetterPropertyUnchecked, 3); | 2422 __ CallRuntime(Runtime::kDefineClassSetter, 3); |
| 2482 break; | 2423 break; |
| 2483 | 2424 |
| 2484 default: | 2425 default: |
| 2485 UNREACHABLE(); | 2426 UNREACHABLE(); |
| 2486 } | 2427 } |
| 2487 } | 2428 } |
| 2488 | 2429 |
| 2489 // prototype | 2430 // prototype |
| 2490 __ CallRuntime(Runtime::kToFastProperties, 1); | 2431 __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2491 | 2432 |
| (...skipping 2760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5252 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5193 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5253 Assembler::target_address_at(call_target_address, | 5194 Assembler::target_address_at(call_target_address, |
| 5254 unoptimized_code)); | 5195 unoptimized_code)); |
| 5255 return OSR_AFTER_STACK_CHECK; | 5196 return OSR_AFTER_STACK_CHECK; |
| 5256 } | 5197 } |
| 5257 | 5198 |
| 5258 | 5199 |
| 5259 } } // namespace v8::internal | 5200 } } // namespace v8::internal |
| 5260 | 5201 |
| 5261 #endif // V8_TARGET_ARCH_X64 | 5202 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |