| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 | 1663 |
| 1664 | 1664 |
| 1665 MaybeObject* StoreIC::Store(State state, | 1665 MaybeObject* StoreIC::Store(State state, |
| 1666 StrictModeFlag strict_mode, | 1666 StrictModeFlag strict_mode, |
| 1667 Handle<Object> object, | 1667 Handle<Object> object, |
| 1668 Handle<String> name, | 1668 Handle<String> name, |
| 1669 Handle<Object> value, | 1669 Handle<Object> value, |
| 1670 JSReceiver::StoreFromKeyed store_mode) { | 1670 JSReceiver::StoreFromKeyed store_mode) { |
| 1671 // Handle proxies. | 1671 // Handle proxies. |
| 1672 if (object->IsJSProxy()) { | 1672 if (object->IsJSProxy()) { |
| 1673 return JSReceiver::SetPropertyOrFail( | 1673 Handle<Object> result = JSReceiver::SetProperty( |
| 1674 Handle<JSReceiver>::cast(object), name, value, NONE, strict_mode); | 1674 Handle<JSReceiver>::cast(object), name, value, NONE, strict_mode); |
| 1675 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1676 return *result; |
| 1675 } | 1677 } |
| 1676 | 1678 |
| 1677 // If the object is undefined or null it's illegal to try to set any | 1679 // If the object is undefined or null it's illegal to try to set any |
| 1678 // properties on it; throw a TypeError in that case. | 1680 // properties on it; throw a TypeError in that case. |
| 1679 if (object->IsUndefined() || object->IsNull()) { | 1681 if (object->IsUndefined() || object->IsNull()) { |
| 1680 return TypeError("non_object_property_store", object, name); | 1682 return TypeError("non_object_property_store", object, name); |
| 1681 } | 1683 } |
| 1682 | 1684 |
| 1683 // The length property of string values is read-only. Throw in strict mode. | 1685 // The length property of string values is read-only. Throw in strict mode. |
| 1684 if (strict_mode == kStrictMode && object->IsString() && | 1686 if (strict_mode == kStrictMode && object->IsString() && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1702 uint32_t index; | 1704 uint32_t index; |
| 1703 if (name->AsArrayIndex(&index)) { | 1705 if (name->AsArrayIndex(&index)) { |
| 1704 Handle<Object> result = | 1706 Handle<Object> result = |
| 1705 JSObject::SetElement(receiver, index, value, NONE, strict_mode); | 1707 JSObject::SetElement(receiver, index, value, NONE, strict_mode); |
| 1706 RETURN_IF_EMPTY_HANDLE(isolate(), result); | 1708 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1707 return *value; | 1709 return *value; |
| 1708 } | 1710 } |
| 1709 | 1711 |
| 1710 // Observed objects are always modified through the runtime. | 1712 // Observed objects are always modified through the runtime. |
| 1711 if (FLAG_harmony_observation && receiver->map()->is_observed()) { | 1713 if (FLAG_harmony_observation && receiver->map()->is_observed()) { |
| 1712 return JSReceiver::SetPropertyOrFail( | 1714 Handle<Object> result = JSReceiver::SetProperty( |
| 1713 receiver, name, value, NONE, strict_mode, store_mode); | 1715 receiver, name, value, NONE, strict_mode, store_mode); |
| 1716 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1717 return *result; |
| 1714 } | 1718 } |
| 1715 | 1719 |
| 1716 // Use specialized code for setting the length of arrays with fast | 1720 // Use specialized code for setting the length of arrays with fast |
| 1717 // properties. Slow properties might indicate redefinition of the length | 1721 // properties. Slow properties might indicate redefinition of the length |
| 1718 // property. Note that when redefined using Object.freeze, it's possible | 1722 // property. Note that when redefined using Object.freeze, it's possible |
| 1719 // to have fast properties but a read-only length. | 1723 // to have fast properties but a read-only length. |
| 1720 if (use_ic && | 1724 if (use_ic && |
| 1721 receiver->IsJSArray() && | 1725 receiver->IsJSArray() && |
| 1722 name->Equals(isolate()->heap()->length_string()) && | 1726 name->Equals(isolate()->heap()->length_string()) && |
| 1723 Handle<JSArray>::cast(receiver)->AllowsSetElementsLength() && | 1727 Handle<JSArray>::cast(receiver)->AllowsSetElementsLength() && |
| 1724 receiver->HasFastProperties() && | 1728 receiver->HasFastProperties() && |
| 1725 !receiver->map()->is_frozen()) { | 1729 !receiver->map()->is_frozen()) { |
| 1726 Handle<Code> stub = | 1730 Handle<Code> stub = |
| 1727 StoreArrayLengthStub(kind(), strict_mode).GetCode(isolate()); | 1731 StoreArrayLengthStub(kind(), strict_mode).GetCode(isolate()); |
| 1728 set_target(*stub); | 1732 set_target(*stub); |
| 1729 TRACE_IC("StoreIC", name, state, *stub); | 1733 TRACE_IC("StoreIC", name, state, *stub); |
| 1730 return JSReceiver::SetPropertyOrFail( | 1734 Handle<Object> result = JSReceiver::SetProperty( |
| 1731 receiver, name, value, NONE, strict_mode, store_mode); | 1735 receiver, name, value, NONE, strict_mode, store_mode); |
| 1736 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1737 return *result; |
| 1732 } | 1738 } |
| 1733 | 1739 |
| 1734 if (receiver->IsJSGlobalProxy()) { | 1740 if (receiver->IsJSGlobalProxy()) { |
| 1735 if (use_ic && kind() != Code::KEYED_STORE_IC) { | 1741 if (use_ic && kind() != Code::KEYED_STORE_IC) { |
| 1736 // Generate a generic stub that goes to the runtime when we see a global | 1742 // Generate a generic stub that goes to the runtime when we see a global |
| 1737 // proxy as receiver. | 1743 // proxy as receiver. |
| 1738 Handle<Code> stub = (strict_mode == kStrictMode) | 1744 Handle<Code> stub = (strict_mode == kStrictMode) |
| 1739 ? global_proxy_stub_strict() | 1745 ? global_proxy_stub_strict() |
| 1740 : global_proxy_stub(); | 1746 : global_proxy_stub(); |
| 1741 set_target(*stub); | 1747 set_target(*stub); |
| 1742 TRACE_IC("StoreIC", name, state, *stub); | 1748 TRACE_IC("StoreIC", name, state, *stub); |
| 1743 } | 1749 } |
| 1744 return JSReceiver::SetPropertyOrFail( | 1750 Handle<Object> result = JSReceiver::SetProperty( |
| 1745 receiver, name, value, NONE, strict_mode, store_mode); | 1751 receiver, name, value, NONE, strict_mode, store_mode); |
| 1752 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1753 return *result; |
| 1746 } | 1754 } |
| 1747 | 1755 |
| 1748 LookupResult lookup(isolate()); | 1756 LookupResult lookup(isolate()); |
| 1749 bool can_store = LookupForWrite(receiver, name, value, &lookup, &state); | 1757 bool can_store = LookupForWrite(receiver, name, value, &lookup, &state); |
| 1750 if (!can_store && | 1758 if (!can_store && |
| 1751 strict_mode == kStrictMode && | 1759 strict_mode == kStrictMode && |
| 1752 !(lookup.IsProperty() && lookup.IsReadOnly()) && | 1760 !(lookup.IsProperty() && lookup.IsReadOnly()) && |
| 1753 IsUndeclaredGlobal(object)) { | 1761 IsUndeclaredGlobal(object)) { |
| 1754 // Strict mode doesn't allow setting non-existent global property. | 1762 // Strict mode doesn't allow setting non-existent global property. |
| 1755 return ReferenceError("not_defined", name); | 1763 return ReferenceError("not_defined", name); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1766 } else if (!name->IsCacheable(isolate()) || | 1774 } else if (!name->IsCacheable(isolate()) || |
| 1767 lookup.IsNormal() || | 1775 lookup.IsNormal() || |
| 1768 (lookup.IsField() && lookup.CanHoldValue(value))) { | 1776 (lookup.IsField() && lookup.CanHoldValue(value))) { |
| 1769 Handle<Code> stub = (strict_mode == kStrictMode) ? generic_stub_strict() | 1777 Handle<Code> stub = (strict_mode == kStrictMode) ? generic_stub_strict() |
| 1770 : generic_stub(); | 1778 : generic_stub(); |
| 1771 set_target(*stub); | 1779 set_target(*stub); |
| 1772 } | 1780 } |
| 1773 } | 1781 } |
| 1774 | 1782 |
| 1775 // Set the property. | 1783 // Set the property. |
| 1776 return JSReceiver::SetPropertyOrFail( | 1784 Handle<Object> result = JSReceiver::SetProperty( |
| 1777 receiver, name, value, NONE, strict_mode, store_mode); | 1785 receiver, name, value, NONE, strict_mode, store_mode); |
| 1786 RETURN_IF_EMPTY_HANDLE(isolate(), result); |
| 1787 return *result; |
| 1778 } | 1788 } |
| 1779 | 1789 |
| 1780 | 1790 |
| 1781 void StoreIC::UpdateCaches(LookupResult* lookup, | 1791 void StoreIC::UpdateCaches(LookupResult* lookup, |
| 1782 State state, | 1792 State state, |
| 1783 StrictModeFlag strict_mode, | 1793 StrictModeFlag strict_mode, |
| 1784 Handle<JSObject> receiver, | 1794 Handle<JSObject> receiver, |
| 1785 Handle<String> name, | 1795 Handle<String> name, |
| 1786 Handle<Object> value) { | 1796 Handle<Object> value) { |
| 1787 ASSERT(!receiver->IsJSGlobalProxy()); | 1797 ASSERT(!receiver->IsJSGlobalProxy()); |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3149 #undef ADDR | 3159 #undef ADDR |
| 3150 }; | 3160 }; |
| 3151 | 3161 |
| 3152 | 3162 |
| 3153 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 3163 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 3154 return IC_utilities[id]; | 3164 return IC_utilities[id]; |
| 3155 } | 3165 } |
| 3156 | 3166 |
| 3157 | 3167 |
| 3158 } } // namespace v8::internal | 3168 } } // namespace v8::internal |
| OLD | NEW |