Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/runtime.cc

Issue 2832001: Add support for elements and array indices in Object.defineProperty... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/bugs/bug-619.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 619 }
620 620
621 // This can potentially be an element in the elements dictionary or 621 // This can potentially be an element in the elements dictionary or
622 // a fast element. 622 // a fast element.
623 if (obj->HasDictionaryElements()) { 623 if (obj->HasDictionaryElements()) {
624 NumberDictionary* dictionary = obj->element_dictionary(); 624 NumberDictionary* dictionary = obj->element_dictionary();
625 int entry = dictionary->FindEntry(index); 625 int entry = dictionary->FindEntry(index);
626 PropertyDetails details = dictionary->DetailsAt(entry); 626 PropertyDetails details = dictionary->DetailsAt(entry);
627 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 627 elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
628 elms->set(VALUE_INDEX, dictionary->ValueAt(entry)); 628 elms->set(VALUE_INDEX, dictionary->ValueAt(entry));
629 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!details.IsDontDelete())); 629 elms->set(WRITABLE_INDEX, Heap::ToBoolean(!details.IsReadOnly()));
630 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!details.IsDontEnum())); 630 elms->set(ENUMERABLE_INDEX, Heap::ToBoolean(!details.IsDontEnum()));
631 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!details.IsReadOnly())); 631 elms->set(CONFIGURABLE_INDEX, Heap::ToBoolean(!details.IsDontDelete()));
632 return *desc; 632 return *desc;
633 } else { 633 } else {
634 // Elements that are stored as array elements always has: 634 // Elements that are stored as array elements always has:
635 // writable: true, configurable: true, enumerable: true. 635 // writable: true, configurable: true, enumerable: true.
636 elms->set(IS_ACCESSOR_INDEX, Heap::false_value()); 636 elms->set(IS_ACCESSOR_INDEX, Heap::false_value());
637 elms->set(VALUE_INDEX, obj->GetElement(index)); 637 elms->set(VALUE_INDEX, obj->GetElement(index));
638 elms->set(WRITABLE_INDEX, Heap::true_value()); 638 elms->set(WRITABLE_INDEX, Heap::true_value());
639 elms->set(ENUMERABLE_INDEX, Heap::true_value()); 639 elms->set(ENUMERABLE_INDEX, Heap::true_value());
640 elms->set(CONFIGURABLE_INDEX, Heap::true_value()); 640 elms->set(CONFIGURABLE_INDEX, Heap::true_value());
641 return *desc; 641 return *desc;
(...skipping 3200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3842 ASSERT(args.length() == 4); 3842 ASSERT(args.length() == 4);
3843 HandleScope scope; 3843 HandleScope scope;
3844 CONVERT_ARG_CHECKED(JSObject, js_object, 0); 3844 CONVERT_ARG_CHECKED(JSObject, js_object, 0);
3845 CONVERT_ARG_CHECKED(String, name, 1); 3845 CONVERT_ARG_CHECKED(String, name, 1);
3846 Handle<Object> obj_value = args.at<Object>(2); 3846 Handle<Object> obj_value = args.at<Object>(2);
3847 3847
3848 CONVERT_CHECKED(Smi, flag, args[3]); 3848 CONVERT_CHECKED(Smi, flag, args[3]);
3849 int unchecked = flag->value(); 3849 int unchecked = flag->value();
3850 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); 3850 RUNTIME_ASSERT((unchecked & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
3851 3851
3852 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3853
3854 // Check if this is an element.
3855 uint32_t index;
3856 bool is_element = name->AsArrayIndex(&index);
3857
3858 // Special case for elements if any of the flags are true.
3859 // If elements are in fast case we always implicitly assume that:
3860 // DONT_DELETE: false, DONT_ENUM: false, READ_ONLY: false.
3861 if (((unchecked & (DONT_DELETE | DONT_ENUM | READ_ONLY)) != 0) &&
3862 is_element) {
3863 // Normalize the elements to enable attributes on the property.
3864 js_object->NormalizeElements();
3865 NumberDictionary* dictionary = js_object->element_dictionary();
3866 // Make sure that we never go back to fast case.
3867 dictionary->set_requires_slow_elements();
3868 PropertyDetails details = PropertyDetails(attr, NORMAL);
3869 dictionary->Set(index, *obj_value, details);
3870 }
3871
3852 LookupResult result; 3872 LookupResult result;
3853 js_object->LocalLookupRealNamedProperty(*name, &result); 3873 js_object->LocalLookupRealNamedProperty(*name, &result);
3854 3874
3855 PropertyAttributes attr = static_cast<PropertyAttributes>(unchecked);
3856
3857 // Take special care when attributes are different and there is already 3875 // Take special care when attributes are different and there is already
3858 // a property. For simplicity we normalize the property which enables us 3876 // a property. For simplicity we normalize the property which enables us
3859 // to not worry about changing the instance_descriptor and creating a new 3877 // to not worry about changing the instance_descriptor and creating a new
3860 // map. The current version of SetObjectProperty does not handle attributes 3878 // map. The current version of SetObjectProperty does not handle attributes
3861 // correctly in the case where a property is a field and is reset with 3879 // correctly in the case where a property is a field and is reset with
3862 // new attributes. 3880 // new attributes.
3863 if (result.IsProperty() && attr != result.GetAttributes()) { 3881 if (result.IsProperty() && attr != result.GetAttributes()) {
3864 // New attributes - normalize to avoid writing to instance descriptor 3882 // New attributes - normalize to avoid writing to instance descriptor
3865 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0); 3883 js_object->NormalizeProperties(CLEAR_INOBJECT_PROPERTIES, 0);
3866 // Use IgnoreAttributes version since a readonly property may be 3884 // Use IgnoreAttributes version since a readonly property may be
3867 // overridden and SetProperty does not allow this. 3885 // overridden and SetProperty does not allow this.
3868 return js_object->IgnoreAttributesAndSetLocalProperty(*name, 3886 return js_object->IgnoreAttributesAndSetLocalProperty(*name,
3869 *obj_value, 3887 *obj_value,
3870 attr); 3888 attr);
3871 } 3889 }
3890
3872 return Runtime::SetObjectProperty(js_object, name, obj_value, attr); 3891 return Runtime::SetObjectProperty(js_object, name, obj_value, attr);
3873 } 3892 }
3874 3893
3875 3894
3876 Object* Runtime::SetObjectProperty(Handle<Object> object, 3895 Object* Runtime::SetObjectProperty(Handle<Object> object,
3877 Handle<Object> key, 3896 Handle<Object> key,
3878 Handle<Object> value, 3897 Handle<Object> value,
3879 PropertyAttributes attr) { 3898 PropertyAttributes attr) {
3880 HandleScope scope; 3899 HandleScope scope;
3881 3900
(...skipping 6490 matching lines...) Expand 10 before | Expand all | Expand 10 after
10372 } else { 10391 } else {
10373 // Handle last resort GC and make sure to allow future allocations 10392 // Handle last resort GC and make sure to allow future allocations
10374 // to grow the heap without causing GCs (if possible). 10393 // to grow the heap without causing GCs (if possible).
10375 Counters::gc_last_resort_from_js.Increment(); 10394 Counters::gc_last_resort_from_js.Increment();
10376 Heap::CollectAllGarbage(false); 10395 Heap::CollectAllGarbage(false);
10377 } 10396 }
10378 } 10397 }
10379 10398
10380 10399
10381 } } // namespace v8::internal 10400 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/bugs/bug-619.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698