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