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

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

Issue 1191313003: More cleanup related to setting array.length (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj); 778 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj);
779 779
780 // Allocate the object. 780 // Allocate the object.
781 Handle<Object> element; 781 Handle<Object> element;
782 Handle<JSObject> object = factory->NewJSObject(function); 782 Handle<JSObject> object = factory->NewJSObject(function);
783 Handle<JSArray> array = Handle<JSArray>::cast(object); 783 Handle<JSArray> array = Handle<JSArray>::cast(object);
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::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); 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(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 Handle<Object> length = 800 JSArray::SetLength(array, static_cast<uint32_t>(Smi::kMaxValue) + 1);
801 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
802 JSArray::SetElementsLength(array, length).Check();
803 801
804 uint32_t int_length = 0; 802 uint32_t int_length = 0;
805 CHECK(length->ToArrayIndex(&int_length)); 803 CHECK(array->length()->ToArrayIndex(&int_length));
806 CHECK_EQ(*length, array->length()); 804 CHECK_EQ(static_cast<uint32_t>(Smi::kMaxValue) + 1, int_length);
807 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 805 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
808 806
809 // array[length] = name. 807 // array[length] = name.
810 JSReceiver::SetElement(array, int_length, name, SLOPPY).Check(); 808 JSReceiver::SetElement(array, int_length, name, SLOPPY).Check();
811 uint32_t new_int_length = 0; 809 uint32_t new_int_length = 0;
812 CHECK(array->length()->ToArrayIndex(&new_int_length)); 810 CHECK(array->length()->ToArrayIndex(&new_int_length));
813 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 811 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
814 element = Object::GetElement(isolate, array, int_length).ToHandleChecked(); 812 element = Object::GetElement(isolate, array, int_length).ToHandleChecked();
815 CHECK_EQ(*element, *name); 813 CHECK_EQ(*element, *name);
816 element = Object::GetElement(isolate, array, 0).ToHandleChecked(); 814 element = Object::GetElement(isolate, array, 0).ToHandleChecked();
(...skipping 5146 matching lines...) Expand 10 before | Expand all | Expand 10 after
5963 size_t counter2 = 2000; 5961 size_t counter2 = 2000;
5964 tracer->SampleAllocation(time2, counter2, counter2); 5962 tracer->SampleAllocation(time2, counter2, counter2);
5965 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); 5963 size_t throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
5966 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput); 5964 CHECK_EQ(2 * (counter2 - counter1) / (time2 - time1), throughput);
5967 int time3 = 1000; 5965 int time3 = 1000;
5968 size_t counter3 = 30000; 5966 size_t counter3 = 30000;
5969 tracer->SampleAllocation(time3, counter3, counter3); 5967 tracer->SampleAllocation(time3, counter3, counter3);
5970 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100); 5968 throughput = tracer->AllocationThroughputInBytesPerMillisecond(100);
5971 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput); 5969 CHECK_EQ(2 * (counter3 - counter1) / (time3 - time1), throughput);
5972 } 5970 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698