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 2762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2773 | 2773 |
2774 if (name->AsArrayIndex(&index)) { | 2774 if (name->AsArrayIndex(&index)) { |
2775 ASSERT(attr == NONE); | 2775 ASSERT(attr == NONE); |
2776 return js_object->SetElement(index, *value); | 2776 return js_object->SetElement(index, *value); |
2777 } else { | 2777 } else { |
2778 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr); | 2778 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr); |
2779 } | 2779 } |
2780 } | 2780 } |
2781 | 2781 |
2782 | 2782 |
| 2783 Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object, |
| 2784 Handle<Object> key) { |
| 2785 HandleScope scope; |
| 2786 |
| 2787 // Check if the given key is an array index. |
| 2788 uint32_t index; |
| 2789 if (Array::IndexFromObject(*key, &index)) { |
| 2790 // In Firefox/SpiderMonkey, Safari and Opera you can access the |
| 2791 // characters of a string using [] notation. In the case of a |
| 2792 // String object we just need to redirect the deletion to the |
| 2793 // underlying string if the index is in range. Since the |
| 2794 // underlying string does nothing with the deletion, we can ignore |
| 2795 // such deletions. |
| 2796 if (js_object->IsStringObjectWithCharacterAt(index)) { |
| 2797 return Heap::true_value(); |
| 2798 } |
| 2799 |
| 2800 return js_object->DeleteElement(index, JSObject::FORCE_DELETION); |
| 2801 } |
| 2802 |
| 2803 Handle<String> key_string; |
| 2804 if (key->IsString()) { |
| 2805 key_string = Handle<String>::cast(key); |
| 2806 } else { |
| 2807 // Call-back into JavaScript to convert the key to a string. |
| 2808 bool has_pending_exception = false; |
| 2809 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
| 2810 if (has_pending_exception) return Failure::Exception(); |
| 2811 key_string = Handle<String>::cast(converted); |
| 2812 } |
| 2813 |
| 2814 key_string->TryFlattenIfNotFlat(); |
| 2815 return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION); |
| 2816 } |
| 2817 |
| 2818 |
2783 static Object* Runtime_SetProperty(Arguments args) { | 2819 static Object* Runtime_SetProperty(Arguments args) { |
2784 NoHandleAllocation ha; | 2820 NoHandleAllocation ha; |
2785 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); | 2821 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); |
2786 | 2822 |
2787 Handle<Object> object = args.at<Object>(0); | 2823 Handle<Object> object = args.at<Object>(0); |
2788 Handle<Object> key = args.at<Object>(1); | 2824 Handle<Object> key = args.at<Object>(1); |
2789 Handle<Object> value = args.at<Object>(2); | 2825 Handle<Object> value = args.at<Object>(2); |
2790 | 2826 |
2791 // Compute attributes. | 2827 // Compute attributes. |
2792 PropertyAttributes attributes = NONE; | 2828 PropertyAttributes attributes = NONE; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2824 IgnoreAttributesAndSetLocalProperty(name, args[2], attributes); | 2860 IgnoreAttributesAndSetLocalProperty(name, args[2], attributes); |
2825 } | 2861 } |
2826 | 2862 |
2827 | 2863 |
2828 static Object* Runtime_DeleteProperty(Arguments args) { | 2864 static Object* Runtime_DeleteProperty(Arguments args) { |
2829 NoHandleAllocation ha; | 2865 NoHandleAllocation ha; |
2830 ASSERT(args.length() == 2); | 2866 ASSERT(args.length() == 2); |
2831 | 2867 |
2832 CONVERT_CHECKED(JSObject, object, args[0]); | 2868 CONVERT_CHECKED(JSObject, object, args[0]); |
2833 CONVERT_CHECKED(String, key, args[1]); | 2869 CONVERT_CHECKED(String, key, args[1]); |
2834 return object->DeleteProperty(key); | 2870 return object->DeleteProperty(key, JSObject::NORMAL_DELETION); |
2835 } | 2871 } |
2836 | 2872 |
2837 | 2873 |
2838 static Object* HasLocalPropertyImplementation(Handle<JSObject> object, | 2874 static Object* HasLocalPropertyImplementation(Handle<JSObject> object, |
2839 Handle<String> key) { | 2875 Handle<String> key) { |
2840 if (object->HasLocalProperty(*key)) return Heap::true_value(); | 2876 if (object->HasLocalProperty(*key)) return Heap::true_value(); |
2841 // Handle hidden prototypes. If there's a hidden prototype above this thing | 2877 // Handle hidden prototypes. If there's a hidden prototype above this thing |
2842 // then we have to check it for properties, because they are supposed to | 2878 // then we have to check it for properties, because they are supposed to |
2843 // look like they are on this object. | 2879 // look like they are on this object. |
2844 Handle<Object> proto(object->GetPrototype()); | 2880 Handle<Object> proto(object->GetPrototype()); |
(...skipping 4223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7068 } else { | 7104 } else { |
7069 // Handle last resort GC and make sure to allow future allocations | 7105 // Handle last resort GC and make sure to allow future allocations |
7070 // to grow the heap without causing GCs (if possible). | 7106 // to grow the heap without causing GCs (if possible). |
7071 Counters::gc_last_resort_from_js.Increment(); | 7107 Counters::gc_last_resort_from_js.Increment(); |
7072 Heap::CollectAllGarbage(); | 7108 Heap::CollectAllGarbage(); |
7073 } | 7109 } |
7074 } | 7110 } |
7075 | 7111 |
7076 | 7112 |
7077 } } // namespace v8::internal | 7113 } } // namespace v8::internal |
OLD | NEW |