| 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 2670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2681 | 2681 |
| 2682 if (name->AsArrayIndex(&index)) { | 2682 if (name->AsArrayIndex(&index)) { |
| 2683 ASSERT(attr == NONE); | 2683 ASSERT(attr == NONE); |
| 2684 return js_object->SetElement(index, *value); | 2684 return js_object->SetElement(index, *value); |
| 2685 } else { | 2685 } else { |
| 2686 return js_object->SetProperty(*name, *value, attr); | 2686 return js_object->SetProperty(*name, *value, attr); |
| 2687 } | 2687 } |
| 2688 } | 2688 } |
| 2689 | 2689 |
| 2690 | 2690 |
| 2691 Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, |
| 2692 Handle<Object> key, |
| 2693 Handle<Object> value, |
| 2694 PropertyAttributes attr) { |
| 2695 HandleScope scope; |
| 2696 |
| 2697 // Check if the given key is an array index. |
| 2698 uint32_t index; |
| 2699 if (Array::IndexFromObject(*key, &index)) { |
| 2700 ASSERT(attr == NONE); |
| 2701 |
| 2702 // In Firefox/SpiderMonkey, Safari and Opera you can access the characters |
| 2703 // of a string using [] notation. We need to support this too in |
| 2704 // JavaScript. |
| 2705 // In the case of a String object we just need to redirect the assignment to |
| 2706 // the underlying string if the index is in range. Since the underlying |
| 2707 // string does nothing with the assignment then we can ignore such |
| 2708 // assignments. |
| 2709 if (js_object->IsStringObjectWithCharacterAt(index)) { |
| 2710 return *value; |
| 2711 } |
| 2712 |
| 2713 return js_object->SetElement(index, *value); |
| 2714 } |
| 2715 |
| 2716 if (key->IsString()) { |
| 2717 if (Handle<String>::cast(key)->AsArrayIndex(&index)) { |
| 2718 ASSERT(attr == NONE); |
| 2719 return js_object->SetElement(index, *value); |
| 2720 } else { |
| 2721 Handle<String> key_string = Handle<String>::cast(key); |
| 2722 key_string->TryFlattenIfNotFlat(); |
| 2723 return js_object->IgnoreAttributesAndSetLocalProperty(*key_string, |
| 2724 *value, |
| 2725 attr); |
| 2726 } |
| 2727 } |
| 2728 |
| 2729 // Call-back into JavaScript to convert the key to a string. |
| 2730 bool has_pending_exception = false; |
| 2731 Handle<Object> converted = Execution::ToString(key, &has_pending_exception); |
| 2732 if (has_pending_exception) return Failure::Exception(); |
| 2733 Handle<String> name = Handle<String>::cast(converted); |
| 2734 |
| 2735 if (name->AsArrayIndex(&index)) { |
| 2736 ASSERT(attr == NONE); |
| 2737 return js_object->SetElement(index, *value); |
| 2738 } else { |
| 2739 return js_object->IgnoreAttributesAndSetLocalProperty(*name, *value, attr); |
| 2740 } |
| 2741 } |
| 2742 |
| 2743 |
| 2691 static Object* Runtime_SetProperty(Arguments args) { | 2744 static Object* Runtime_SetProperty(Arguments args) { |
| 2692 NoHandleAllocation ha; | 2745 NoHandleAllocation ha; |
| 2693 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); | 2746 RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); |
| 2694 | 2747 |
| 2695 Handle<Object> object = args.at<Object>(0); | 2748 Handle<Object> object = args.at<Object>(0); |
| 2696 Handle<Object> key = args.at<Object>(1); | 2749 Handle<Object> key = args.at<Object>(1); |
| 2697 Handle<Object> value = args.at<Object>(2); | 2750 Handle<Object> value = args.at<Object>(2); |
| 2698 | 2751 |
| 2699 // Compute attributes. | 2752 // Compute attributes. |
| 2700 PropertyAttributes attributes = NONE; | 2753 PropertyAttributes attributes = NONE; |
| (...skipping 4236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6937 } else { | 6990 } else { |
| 6938 // Handle last resort GC and make sure to allow future allocations | 6991 // Handle last resort GC and make sure to allow future allocations |
| 6939 // to grow the heap without causing GCs (if possible). | 6992 // to grow the heap without causing GCs (if possible). |
| 6940 Counters::gc_last_resort_from_js.Increment(); | 6993 Counters::gc_last_resort_from_js.Increment(); |
| 6941 Heap::CollectAllGarbage(); | 6994 Heap::CollectAllGarbage(); |
| 6942 } | 6995 } |
| 6943 } | 6996 } |
| 6944 | 6997 |
| 6945 | 6998 |
| 6946 } } // namespace v8::internal | 6999 } } // namespace v8::internal |
| OLD | NEW |