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/ic/ic.h" | 5 #include "src/ic/ic.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api.h" | 8 #include "src/api.h" |
9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 Handle<Code> LoadIC::SimpleFieldLoad(FieldIndex index) { | 969 Handle<Code> LoadIC::SimpleFieldLoad(FieldIndex index) { |
970 LoadFieldStub stub(isolate(), index); | 970 LoadFieldStub stub(isolate(), index); |
971 return stub.GetCode(); | 971 return stub.GetCode(); |
972 } | 972 } |
973 | 973 |
974 | 974 |
975 bool IsCompatibleReceiver(LookupIterator* lookup, Handle<Map> receiver_map) { | 975 bool IsCompatibleReceiver(LookupIterator* lookup, Handle<Map> receiver_map) { |
976 DCHECK(lookup->state() == LookupIterator::ACCESSOR); | 976 DCHECK(lookup->state() == LookupIterator::ACCESSOR); |
977 Isolate* isolate = lookup->isolate(); | 977 Isolate* isolate = lookup->isolate(); |
978 Handle<Object> accessors = lookup->GetAccessors(); | 978 Handle<Object> accessors = lookup->GetAccessors(); |
979 if (accessors->IsExecutableAccessorInfo()) { | 979 if (accessors->IsAccessorInfo()) { |
980 Handle<ExecutableAccessorInfo> info = | 980 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(accessors); |
981 Handle<ExecutableAccessorInfo>::cast(accessors); | |
982 if (info->getter() != NULL && | 981 if (info->getter() != NULL && |
983 !ExecutableAccessorInfo::IsCompatibleReceiverMap(isolate, info, | 982 !AccessorInfo::IsCompatibleReceiverMap(isolate, info, receiver_map)) { |
984 receiver_map)) { | |
985 return false; | 983 return false; |
986 } | 984 } |
987 } else if (accessors->IsAccessorPair()) { | 985 } else if (accessors->IsAccessorPair()) { |
988 Handle<Object> getter(Handle<AccessorPair>::cast(accessors)->getter(), | 986 Handle<Object> getter(Handle<AccessorPair>::cast(accessors)->getter(), |
989 isolate); | 987 isolate); |
990 Handle<JSObject> holder = lookup->GetHolder<JSObject>(); | 988 Handle<JSObject> holder = lookup->GetHolder<JSObject>(); |
991 Handle<Object> receiver = lookup->GetReceiver(); | 989 Handle<Object> receiver = lookup->GetReceiver(); |
992 if (getter->IsJSFunction() && holder->HasFastProperties()) { | 990 if (getter->IsJSFunction() && holder->HasFastProperties()) { |
993 Handle<JSFunction> function = Handle<JSFunction>::cast(getter); | 991 Handle<JSFunction> function = Handle<JSFunction>::cast(getter); |
994 if (receiver->IsJSObject() || function->shared()->IsBuiltin() || | 992 if (receiver->IsJSObject() || function->shared()->IsBuiltin() || |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 return SimpleFieldLoad(index); | 1160 return SimpleFieldLoad(index); |
1163 } | 1161 } |
1164 if (Accessors::IsJSArrayBufferViewFieldAccessor(map, lookup->name(), | 1162 if (Accessors::IsJSArrayBufferViewFieldAccessor(map, lookup->name(), |
1165 &object_offset)) { | 1163 &object_offset)) { |
1166 FieldIndex index = FieldIndex::ForInObjectOffset(object_offset, *map); | 1164 FieldIndex index = FieldIndex::ForInObjectOffset(object_offset, *map); |
1167 ArrayBufferViewLoadFieldStub stub(isolate(), index); | 1165 ArrayBufferViewLoadFieldStub stub(isolate(), index); |
1168 return stub.GetCode(); | 1166 return stub.GetCode(); |
1169 } | 1167 } |
1170 | 1168 |
1171 Handle<Object> accessors = lookup->GetAccessors(); | 1169 Handle<Object> accessors = lookup->GetAccessors(); |
1172 if (accessors->IsExecutableAccessorInfo()) { | 1170 if (accessors->IsAccessorInfo()) { |
1173 Handle<ExecutableAccessorInfo> info = | 1171 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(accessors); |
1174 Handle<ExecutableAccessorInfo>::cast(accessors); | |
1175 if (v8::ToCData<Address>(info->getter()) == 0) break; | 1172 if (v8::ToCData<Address>(info->getter()) == 0) break; |
1176 if (!ExecutableAccessorInfo::IsCompatibleReceiverMap(isolate(), info, | 1173 if (!AccessorInfo::IsCompatibleReceiverMap(isolate(), info, map)) { |
1177 map)) { | |
1178 // This case should be already handled in LoadIC::UpdateCaches. | 1174 // This case should be already handled in LoadIC::UpdateCaches. |
1179 UNREACHABLE(); | 1175 UNREACHABLE(); |
1180 break; | 1176 break; |
1181 } | 1177 } |
1182 if (!holder->HasFastProperties()) break; | 1178 if (!holder->HasFastProperties()) break; |
1183 NamedLoadHandlerCompiler compiler(isolate(), map, holder, cache_holder); | 1179 NamedLoadHandlerCompiler compiler(isolate(), map, holder, cache_holder); |
1184 return compiler.CompileLoadCallback(lookup->name(), info); | 1180 return compiler.CompileLoadCallback(lookup->name(), info); |
1185 } | 1181 } |
1186 if (accessors->IsAccessorPair()) { | 1182 if (accessors->IsAccessorPair()) { |
1187 Handle<Object> getter(Handle<AccessorPair>::cast(accessors)->getter(), | 1183 Handle<Object> getter(Handle<AccessorPair>::cast(accessors)->getter(), |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 NamedStoreHandlerCompiler compiler(isolate(), receiver_map(), holder); | 1722 NamedStoreHandlerCompiler compiler(isolate(), receiver_map(), holder); |
1727 return compiler.CompileStoreInterceptor(lookup->name()); | 1723 return compiler.CompileStoreInterceptor(lookup->name()); |
1728 } | 1724 } |
1729 | 1725 |
1730 case LookupIterator::ACCESSOR: { | 1726 case LookupIterator::ACCESSOR: { |
1731 if (!holder->HasFastProperties()) { | 1727 if (!holder->HasFastProperties()) { |
1732 TRACE_GENERIC_IC(isolate(), "StoreIC", "accessor on slow map"); | 1728 TRACE_GENERIC_IC(isolate(), "StoreIC", "accessor on slow map"); |
1733 break; | 1729 break; |
1734 } | 1730 } |
1735 Handle<Object> accessors = lookup->GetAccessors(); | 1731 Handle<Object> accessors = lookup->GetAccessors(); |
1736 if (accessors->IsExecutableAccessorInfo()) { | 1732 if (accessors->IsAccessorInfo()) { |
1737 Handle<ExecutableAccessorInfo> info = | 1733 Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(accessors); |
1738 Handle<ExecutableAccessorInfo>::cast(accessors); | |
1739 if (v8::ToCData<Address>(info->setter()) == 0) { | 1734 if (v8::ToCData<Address>(info->setter()) == 0) { |
1740 TRACE_GENERIC_IC(isolate(), "StoreIC", "setter == 0"); | 1735 TRACE_GENERIC_IC(isolate(), "StoreIC", "setter == 0"); |
1741 break; | 1736 break; |
1742 } | 1737 } |
1743 if (AccessorInfo::cast(*accessors)->is_special_data_property() && | 1738 if (AccessorInfo::cast(*accessors)->is_special_data_property() && |
1744 !lookup->HolderIsReceiverOrHiddenPrototype()) { | 1739 !lookup->HolderIsReceiverOrHiddenPrototype()) { |
1745 TRACE_GENERIC_IC(isolate(), "StoreIC", | 1740 TRACE_GENERIC_IC(isolate(), "StoreIC", |
1746 "special data property in prototype chain"); | 1741 "special data property in prototype chain"); |
1747 break; | 1742 break; |
1748 } | 1743 } |
1749 if (!ExecutableAccessorInfo::IsCompatibleReceiverMap(isolate(), info, | 1744 if (!AccessorInfo::IsCompatibleReceiverMap(isolate(), info, |
1750 receiver_map())) { | 1745 receiver_map())) { |
1751 TRACE_GENERIC_IC(isolate(), "StoreIC", "incompatible receiver type"); | 1746 TRACE_GENERIC_IC(isolate(), "StoreIC", "incompatible receiver type"); |
1752 break; | 1747 break; |
1753 } | 1748 } |
1754 NamedStoreHandlerCompiler compiler(isolate(), receiver_map(), holder); | 1749 NamedStoreHandlerCompiler compiler(isolate(), receiver_map(), holder); |
1755 return compiler.CompileStoreCallback(receiver, lookup->name(), info); | 1750 return compiler.CompileStoreCallback(receiver, lookup->name(), info); |
1756 } else if (accessors->IsAccessorPair()) { | 1751 } else if (accessors->IsAccessorPair()) { |
1757 Handle<Object> setter(Handle<AccessorPair>::cast(accessors)->setter(), | 1752 Handle<Object> setter(Handle<AccessorPair>::cast(accessors)->setter(), |
1758 isolate()); | 1753 isolate()); |
1759 if (!setter->IsJSFunction()) { | 1754 if (!setter->IsJSFunction()) { |
1760 TRACE_GENERIC_IC(isolate(), "StoreIC", "setter not a function"); | 1755 TRACE_GENERIC_IC(isolate(), "StoreIC", "setter not a function"); |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2813 | 2808 |
2814 | 2809 |
2815 RUNTIME_FUNCTION(Runtime_StoreCallbackProperty) { | 2810 RUNTIME_FUNCTION(Runtime_StoreCallbackProperty) { |
2816 Handle<JSObject> receiver = args.at<JSObject>(0); | 2811 Handle<JSObject> receiver = args.at<JSObject>(0); |
2817 Handle<JSObject> holder = args.at<JSObject>(1); | 2812 Handle<JSObject> holder = args.at<JSObject>(1); |
2818 Handle<HeapObject> callback_or_cell = args.at<HeapObject>(2); | 2813 Handle<HeapObject> callback_or_cell = args.at<HeapObject>(2); |
2819 Handle<Name> name = args.at<Name>(3); | 2814 Handle<Name> name = args.at<Name>(3); |
2820 Handle<Object> value = args.at<Object>(4); | 2815 Handle<Object> value = args.at<Object>(4); |
2821 HandleScope scope(isolate); | 2816 HandleScope scope(isolate); |
2822 | 2817 |
2823 Handle<ExecutableAccessorInfo> callback( | 2818 Handle<AccessorInfo> callback( |
2824 callback_or_cell->IsWeakCell() | 2819 callback_or_cell->IsWeakCell() |
2825 ? ExecutableAccessorInfo::cast( | 2820 ? AccessorInfo::cast(WeakCell::cast(*callback_or_cell)->value()) |
2826 WeakCell::cast(*callback_or_cell)->value()) | 2821 : AccessorInfo::cast(*callback_or_cell)); |
2827 : ExecutableAccessorInfo::cast(*callback_or_cell)); | |
2828 | 2822 |
2829 DCHECK(callback->IsCompatibleReceiver(*receiver)); | 2823 DCHECK(callback->IsCompatibleReceiver(*receiver)); |
2830 | 2824 |
2831 Address setter_address = v8::ToCData<Address>(callback->setter()); | 2825 Address setter_address = v8::ToCData<Address>(callback->setter()); |
2832 v8::AccessorNameSetterCallback fun = | 2826 v8::AccessorNameSetterCallback fun = |
2833 FUNCTION_CAST<v8::AccessorNameSetterCallback>(setter_address); | 2827 FUNCTION_CAST<v8::AccessorNameSetterCallback>(setter_address); |
2834 DCHECK(fun != NULL); | 2828 DCHECK(fun != NULL); |
2835 | 2829 |
2836 LOG(isolate, ApiNamedPropertyAccess("store", *receiver, *name)); | 2830 LOG(isolate, ApiNamedPropertyAccess("store", *receiver, *name)); |
2837 PropertyCallbackArguments custom_args(isolate, callback->data(), *receiver, | 2831 PropertyCallbackArguments custom_args(isolate, callback->data(), *receiver, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2975 KeyedLoadICNexus nexus(vector, vector_slot); | 2969 KeyedLoadICNexus nexus(vector, vector_slot); |
2976 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus); | 2970 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus); |
2977 ic.UpdateState(receiver, key); | 2971 ic.UpdateState(receiver, key); |
2978 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, ic.Load(receiver, key)); | 2972 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, ic.Load(receiver, key)); |
2979 } | 2973 } |
2980 | 2974 |
2981 return *result; | 2975 return *result; |
2982 } | 2976 } |
2983 } // namespace internal | 2977 } // namespace internal |
2984 } // namespace v8 | 2978 } // namespace v8 |
OLD | NEW |