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

Side by Side Diff: test/cctest/test-heap.cc

Issue 1221303019: Fix keyed access of primitive objects in the runtime. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Created 5 years, 5 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
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/primitive-keyed-access.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 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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 // We just initialized the VM, no heap allocation failure yet. 784 // We just initialized the VM, no heap allocation failure yet.
785 JSArray::Initialize(array, 0); 785 JSArray::Initialize(array, 0);
786 786
787 // Set array length to 0. 787 // Set array length to 0.
788 JSArray::SetLength(array, 0); 788 JSArray::SetLength(array, 0);
789 CHECK_EQ(Smi::FromInt(0), array->length()); 789 CHECK_EQ(Smi::FromInt(0), array->length());
790 // Must be in fast mode. 790 // Must be in fast mode.
791 CHECK(array->HasFastSmiOrObjectElements()); 791 CHECK(array->HasFastSmiOrObjectElements());
792 792
793 // array[length] = name. 793 // array[length] = name.
794 JSReceiver::SetElement(array, 0, name, SLOPPY).Check(); 794 JSReceiver::SetElement(isolate, array, 0, name, SLOPPY).Check();
795 CHECK_EQ(Smi::FromInt(1), array->length()); 795 CHECK_EQ(Smi::FromInt(1), array->length());
796 element = i::Object::GetElement(isolate, array, 0).ToHandleChecked(); 796 element = i::Object::GetElement(isolate, array, 0).ToHandleChecked();
797 CHECK_EQ(*element, *name); 797 CHECK_EQ(*element, *name);
798 798
799 // Set array length with larger than smi value. 799 // Set array length with larger than smi value.
800 JSArray::SetLength(array, static_cast<uint32_t>(Smi::kMaxValue) + 1); 800 JSArray::SetLength(array, static_cast<uint32_t>(Smi::kMaxValue) + 1);
801 801
802 uint32_t int_length = 0; 802 uint32_t int_length = 0;
803 CHECK(array->length()->ToArrayIndex(&int_length)); 803 CHECK(array->length()->ToArrayIndex(&int_length));
804 CHECK_EQ(static_cast<uint32_t>(Smi::kMaxValue) + 1, int_length); 804 CHECK_EQ(static_cast<uint32_t>(Smi::kMaxValue) + 1, int_length);
805 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 805 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
806 806
807 // array[length] = name. 807 // array[length] = name.
808 JSReceiver::SetElement(array, int_length, name, SLOPPY).Check(); 808 JSReceiver::SetElement(isolate, array, int_length, name, SLOPPY).Check();
809 uint32_t new_int_length = 0; 809 uint32_t new_int_length = 0;
810 CHECK(array->length()->ToArrayIndex(&new_int_length)); 810 CHECK(array->length()->ToArrayIndex(&new_int_length));
811 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 811 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
812 element = Object::GetElement(isolate, array, int_length).ToHandleChecked(); 812 element = Object::GetElement(isolate, array, int_length).ToHandleChecked();
813 CHECK_EQ(*element, *name); 813 CHECK_EQ(*element, *name);
814 element = Object::GetElement(isolate, array, 0).ToHandleChecked(); 814 element = Object::GetElement(isolate, array, 0).ToHandleChecked();
815 CHECK_EQ(*element, *name); 815 CHECK_EQ(*element, *name);
816 } 816 }
817 817
818 818
(...skipping 10 matching lines...) Expand all
829 Handle<JSObject> obj = factory->NewJSObject(constructor); 829 Handle<JSObject> obj = factory->NewJSObject(constructor);
830 Handle<String> first = factory->InternalizeUtf8String("first"); 830 Handle<String> first = factory->InternalizeUtf8String("first");
831 Handle<String> second = factory->InternalizeUtf8String("second"); 831 Handle<String> second = factory->InternalizeUtf8String("second");
832 832
833 Handle<Smi> one(Smi::FromInt(1), isolate); 833 Handle<Smi> one(Smi::FromInt(1), isolate);
834 Handle<Smi> two(Smi::FromInt(2), isolate); 834 Handle<Smi> two(Smi::FromInt(2), isolate);
835 835
836 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check(); 836 JSReceiver::SetProperty(obj, first, one, SLOPPY).Check();
837 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check(); 837 JSReceiver::SetProperty(obj, second, two, SLOPPY).Check();
838 838
839 JSReceiver::SetElement(obj, 0, first, SLOPPY).Check(); 839 JSReceiver::SetElement(isolate, obj, 0, first, SLOPPY).Check();
840 JSReceiver::SetElement(obj, 1, second, SLOPPY).Check(); 840 JSReceiver::SetElement(isolate, obj, 1, second, SLOPPY).Check();
841 841
842 // Make the clone. 842 // Make the clone.
843 Handle<Object> value1, value2; 843 Handle<Object> value1, value2;
844 Handle<JSObject> clone = factory->CopyJSObject(obj); 844 Handle<JSObject> clone = factory->CopyJSObject(obj);
845 CHECK(!clone.is_identical_to(obj)); 845 CHECK(!clone.is_identical_to(obj));
846 846
847 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); 847 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
848 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); 848 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
849 CHECK_EQ(*value1, *value2); 849 CHECK_EQ(*value1, *value2);
850 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); 850 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
851 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); 851 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
852 CHECK_EQ(*value1, *value2); 852 CHECK_EQ(*value1, *value2);
853 853
854 value1 = Object::GetProperty(obj, first).ToHandleChecked(); 854 value1 = Object::GetProperty(obj, first).ToHandleChecked();
855 value2 = Object::GetProperty(clone, first).ToHandleChecked(); 855 value2 = Object::GetProperty(clone, first).ToHandleChecked();
856 CHECK_EQ(*value1, *value2); 856 CHECK_EQ(*value1, *value2);
857 value1 = Object::GetProperty(obj, second).ToHandleChecked(); 857 value1 = Object::GetProperty(obj, second).ToHandleChecked();
858 value2 = Object::GetProperty(clone, second).ToHandleChecked(); 858 value2 = Object::GetProperty(clone, second).ToHandleChecked();
859 CHECK_EQ(*value1, *value2); 859 CHECK_EQ(*value1, *value2);
860 860
861 // Flip the values. 861 // Flip the values.
862 JSReceiver::SetProperty(clone, first, two, SLOPPY).Check(); 862 JSReceiver::SetProperty(clone, first, two, SLOPPY).Check();
863 JSReceiver::SetProperty(clone, second, one, SLOPPY).Check(); 863 JSReceiver::SetProperty(clone, second, one, SLOPPY).Check();
864 864
865 JSReceiver::SetElement(clone, 0, second, SLOPPY).Check(); 865 JSReceiver::SetElement(isolate, clone, 0, second, SLOPPY).Check();
866 JSReceiver::SetElement(clone, 1, first, SLOPPY).Check(); 866 JSReceiver::SetElement(isolate, clone, 1, first, SLOPPY).Check();
867 867
868 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked(); 868 value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
869 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked(); 869 value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
870 CHECK_EQ(*value1, *value2); 870 CHECK_EQ(*value1, *value2);
871 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked(); 871 value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
872 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked(); 872 value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
873 CHECK_EQ(*value1, *value2); 873 CHECK_EQ(*value1, *value2);
874 874
875 value1 = Object::GetProperty(obj, second).ToHandleChecked(); 875 value1 = Object::GetProperty(obj, second).ToHandleChecked();
876 value2 = Object::GetProperty(clone, first).ToHandleChecked(); 876 value2 = Object::GetProperty(clone, first).ToHandleChecked();
(...skipping 5171 matching lines...) Expand 10 before | Expand all | Expand 10 after
6048 array->address(), 6048 array->address(),
6049 array->address() + array->Size()); 6049 array->address() + array->Size());
6050 DCHECK(reinterpret_cast<void*>(buffer->Get(1)) == 6050 DCHECK(reinterpret_cast<void*>(buffer->Get(1)) ==
6051 HeapObject::RawField(heap->empty_fixed_array(), 6051 HeapObject::RawField(heap->empty_fixed_array(),
6052 FixedArrayBase::kLengthOffset)); 6052 FixedArrayBase::kLengthOffset));
6053 DCHECK(reinterpret_cast<void*>(buffer->Get(2)) == 6053 DCHECK(reinterpret_cast<void*>(buffer->Get(2)) ==
6054 HeapObject::RawField(heap->empty_fixed_array(), 6054 HeapObject::RawField(heap->empty_fixed_array(),
6055 FixedArrayBase::kLengthOffset)); 6055 FixedArrayBase::kLengthOffset));
6056 delete buffer; 6056 delete buffer;
6057 } 6057 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/primitive-keyed-access.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698