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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); | 848 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); |
849 #endif | 849 #endif |
850 } | 850 } |
851 // Get the string if we have a string wrapper object. | 851 // Get the string if we have a string wrapper object. |
852 Handle<Object> string = object->IsJSValue() | 852 Handle<Object> string = object->IsJSValue() |
853 ? Handle<Object>(Handle<JSValue>::cast(object)->value()) | 853 ? Handle<Object>(Handle<JSValue>::cast(object)->value()) |
854 : object; | 854 : object; |
855 return Smi::FromInt(String::cast(*string)->length()); | 855 return Smi::FromInt(String::cast(*string)->length()); |
856 } | 856 } |
857 | 857 |
| 858 // Use specialized code for getting the length of arrays. |
| 859 if (object->IsJSArray() && |
| 860 name->Equals(isolate()->heap()->length_symbol())) { |
| 861 Handle<Code> stub; |
| 862 if (state == UNINITIALIZED) { |
| 863 stub = pre_monomorphic_stub(); |
| 864 } else if (state == PREMONOMORPHIC) { |
| 865 stub = isolate()->builtins()->LoadIC_ArrayLength(); |
| 866 } else if (state != MEGAMORPHIC) { |
| 867 stub = megamorphic_stub(); |
| 868 } |
| 869 if (!stub.is_null()) { |
| 870 set_target(*stub); |
| 871 #ifdef DEBUG |
| 872 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); |
| 873 #endif |
| 874 } |
| 875 return JSArray::cast(*object)->length(); |
| 876 } |
| 877 |
858 // Use specialized code for getting prototype of functions. | 878 // Use specialized code for getting prototype of functions. |
859 if (object->IsJSFunction() && | 879 if (object->IsJSFunction() && |
860 name->Equals(isolate()->heap()->prototype_symbol()) && | 880 name->Equals(isolate()->heap()->prototype_symbol()) && |
861 Handle<JSFunction>::cast(object)->should_have_prototype()) { | 881 Handle<JSFunction>::cast(object)->should_have_prototype()) { |
862 Handle<Code> stub; | 882 Handle<Code> stub; |
863 if (state == UNINITIALIZED) { | 883 if (state == UNINITIALIZED) { |
864 stub = pre_monomorphic_stub(); | 884 stub = pre_monomorphic_stub(); |
865 } else if (state == PREMONOMORPHIC) { | 885 } else if (state == PREMONOMORPHIC) { |
866 stub = isolate()->builtins()->LoadIC_FunctionPrototype(); | 886 stub = isolate()->builtins()->LoadIC_FunctionPrototype(); |
867 } else if (state != MEGAMORPHIC) { | 887 } else if (state != MEGAMORPHIC) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 if (!info->IsCompatibleReceiver(*receiver)) return; | 999 if (!info->IsCompatibleReceiver(*receiver)) return; |
980 code = isolate()->stub_cache()->ComputeLoadCallback( | 1000 code = isolate()->stub_cache()->ComputeLoadCallback( |
981 name, receiver, holder, info); | 1001 name, receiver, holder, info); |
982 } else if (callback->IsAccessorPair()) { | 1002 } else if (callback->IsAccessorPair()) { |
983 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter()); | 1003 Handle<Object> getter(Handle<AccessorPair>::cast(callback)->getter()); |
984 if (!getter->IsJSFunction()) return; | 1004 if (!getter->IsJSFunction()) return; |
985 if (holder->IsGlobalObject()) return; | 1005 if (holder->IsGlobalObject()) return; |
986 if (!holder->HasFastProperties()) return; | 1006 if (!holder->HasFastProperties()) return; |
987 code = isolate()->stub_cache()->ComputeLoadViaGetter( | 1007 code = isolate()->stub_cache()->ComputeLoadViaGetter( |
988 name, receiver, holder, Handle<JSFunction>::cast(getter)); | 1008 name, receiver, holder, Handle<JSFunction>::cast(getter)); |
989 } else if (holder->IsJSArray() && | |
990 name->Equals(isolate()->heap()->length_symbol())) { | |
991 ASSERT(callback->IsForeign()); | |
992 ASSERT(reinterpret_cast<AccessorDescriptor*>( | |
993 Handle<Foreign>::cast(callback)->foreign_address()) | |
994 == &Accessors::ArrayLength); | |
995 // Use a "load field" IC for getting the array length. | |
996 // Note that the resulting code object is marked as "Code::FIELD" | |
997 // and not as "Code::CALLBACKS". | |
998 code = isolate()->stub_cache()->ComputeLoadField( | |
999 name, receiver, holder, JSArray::ArrayLengthIndex()); | |
1000 } else { | 1009 } else { |
1001 ASSERT(callback->IsForeign()); | 1010 ASSERT(callback->IsForeign()); |
1002 // No IC support for old-style native accessors. | 1011 // No IC support for old-style native accessors. |
1003 return; | 1012 return; |
1004 } | 1013 } |
1005 break; | 1014 break; |
1006 } | 1015 } |
1007 case INTERCEPTOR: | 1016 case INTERCEPTOR: |
1008 ASSERT(HasInterceptorGetter(*holder)); | 1017 ASSERT(HasInterceptorGetter(*holder)); |
1009 code = isolate()->stub_cache()->ComputeLoadInterceptor( | 1018 code = isolate()->stub_cache()->ComputeLoadInterceptor( |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2760 #undef ADDR | 2769 #undef ADDR |
2761 }; | 2770 }; |
2762 | 2771 |
2763 | 2772 |
2764 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2773 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2765 return IC_utilities[id]; | 2774 return IC_utilities[id]; |
2766 } | 2775 } |
2767 | 2776 |
2768 | 2777 |
2769 } } // namespace v8::internal | 2778 } } // namespace v8::internal |
OLD | NEW |