OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 2814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2825 static Object* Runtime_DeleteProperty(Arguments args) { | 2825 static Object* Runtime_DeleteProperty(Arguments args) { |
2826 NoHandleAllocation ha; | 2826 NoHandleAllocation ha; |
2827 ASSERT(args.length() == 2); | 2827 ASSERT(args.length() == 2); |
2828 | 2828 |
2829 CONVERT_CHECKED(JSObject, object, args[0]); | 2829 CONVERT_CHECKED(JSObject, object, args[0]); |
2830 CONVERT_CHECKED(String, key, args[1]); | 2830 CONVERT_CHECKED(String, key, args[1]); |
2831 return object->DeleteProperty(key); | 2831 return object->DeleteProperty(key); |
2832 } | 2832 } |
2833 | 2833 |
2834 | 2834 |
2835 static Object* HasLocalPropertyImplementation(Object* obj, String* key) { | 2835 static Object* HasLocalPropertyImplementation(Handle<JSObject> object, |
| 2836 Handle<String> key) { |
| 2837 if (object->HasLocalProperty(*key)) return Heap::true_value(); |
| 2838 // Handle hidden prototypes. If there's a hidden prototype above this thing |
| 2839 // then we have to check it for properties, because they are supposed to |
| 2840 // look like they are on this object. |
| 2841 Handle<Object> proto(object->GetPrototype()); |
| 2842 if (proto->IsJSObject() && |
| 2843 JSObject::cast(*proto)->map()->is_hidden_prototype()) { |
| 2844 return HasLocalPropertyImplementation(Handle<JSObject>::cast(proto), key); |
| 2845 } |
| 2846 return Heap::false_value(); |
| 2847 } |
| 2848 |
| 2849 |
| 2850 static Object* Runtime_HasLocalProperty(Arguments args) { |
| 2851 NoHandleAllocation ha; |
| 2852 ASSERT(args.length() == 2); |
| 2853 CONVERT_CHECKED(String, key, args[1]); |
| 2854 |
| 2855 Object* obj = args[0]; |
2836 // Only JS objects can have properties. | 2856 // Only JS objects can have properties. |
2837 if (obj->IsJSObject()) { | 2857 if (obj->IsJSObject()) { |
2838 JSObject* object = JSObject::cast(obj); | 2858 JSObject* object = JSObject::cast(obj); |
2839 if (object->HasLocalProperty(key)) return Heap::true_value(); | 2859 // Fast case - no interceptors. |
2840 // Handle hidden prototypes. If there's a hidden prototype above this thing | 2860 if (object->HasRealNamedProperty(key)) return Heap::true_value(); |
2841 // then we have to check it for properties, because they are supposed to | 2861 // Slow case. Either it's not there or we have an interceptor. We should |
2842 // look like they are on this object. | 2862 // have handles for this kind of deal. |
2843 Object* proto = object->GetPrototype(); | 2863 HandleScope scope; |
2844 if (proto->IsJSObject() && | 2864 return HasLocalPropertyImplementation(Handle<JSObject>(object), |
2845 JSObject::cast(proto)->map()->is_hidden_prototype()) { | 2865 Handle<String>(key)); |
2846 return HasLocalPropertyImplementation(object->GetPrototype(), key); | |
2847 } | |
2848 } else if (obj->IsString()) { | 2866 } else if (obj->IsString()) { |
2849 // Well, there is one exception: Handle [] on strings. | 2867 // Well, there is one exception: Handle [] on strings. |
2850 uint32_t index; | 2868 uint32_t index; |
2851 if (key->AsArrayIndex(&index)) { | 2869 if (key->AsArrayIndex(&index)) { |
2852 String* string = String::cast(obj); | 2870 String* string = String::cast(obj); |
2853 if (index < static_cast<uint32_t>(string->length())) | 2871 if (index < static_cast<uint32_t>(string->length())) |
2854 return Heap::true_value(); | 2872 return Heap::true_value(); |
2855 } | 2873 } |
2856 } | 2874 } |
2857 return Heap::false_value(); | 2875 return Heap::false_value(); |
2858 } | 2876 } |
2859 | 2877 |
2860 | 2878 |
2861 static Object* Runtime_HasLocalProperty(Arguments args) { | |
2862 NoHandleAllocation ha; | |
2863 ASSERT(args.length() == 2); | |
2864 CONVERT_CHECKED(String, key, args[1]); | |
2865 | |
2866 return HasLocalPropertyImplementation(args[0], key); | |
2867 } | |
2868 | |
2869 | |
2870 static Object* Runtime_HasProperty(Arguments args) { | 2879 static Object* Runtime_HasProperty(Arguments args) { |
2871 NoHandleAllocation na; | 2880 NoHandleAllocation na; |
2872 ASSERT(args.length() == 2); | 2881 ASSERT(args.length() == 2); |
2873 | 2882 |
2874 // Only JS objects can have properties. | 2883 // Only JS objects can have properties. |
2875 if (args[0]->IsJSObject()) { | 2884 if (args[0]->IsJSObject()) { |
2876 JSObject* object = JSObject::cast(args[0]); | 2885 JSObject* object = JSObject::cast(args[0]); |
2877 CONVERT_CHECKED(String, key, args[1]); | 2886 CONVERT_CHECKED(String, key, args[1]); |
2878 if (object->HasProperty(key)) return Heap::true_value(); | 2887 if (object->HasProperty(key)) return Heap::true_value(); |
2879 } | 2888 } |
(...skipping 4182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7062 } else { | 7071 } else { |
7063 // Handle last resort GC and make sure to allow future allocations | 7072 // Handle last resort GC and make sure to allow future allocations |
7064 // to grow the heap without causing GCs (if possible). | 7073 // to grow the heap without causing GCs (if possible). |
7065 Counters::gc_last_resort_from_js.Increment(); | 7074 Counters::gc_last_resort_from_js.Increment(); |
7066 Heap::CollectAllGarbage(); | 7075 Heap::CollectAllGarbage(); |
7067 } | 7076 } |
7068 } | 7077 } |
7069 | 7078 |
7070 | 7079 |
7071 } } // namespace v8::internal | 7080 } } // namespace v8::internal |
OLD | NEW |