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

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

Issue 66803002: Handlify JSObject::SetElement & brethren (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: sync Created 7 years, 1 month 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/runtime.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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 // We just initialized the VM, no heap allocation failure yet. 753 // We just initialized the VM, no heap allocation failure yet.
754 array->Initialize(0)->ToObjectChecked(); 754 array->Initialize(0)->ToObjectChecked();
755 755
756 // Set array length to 0. 756 // Set array length to 0.
757 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); 757 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
758 CHECK_EQ(Smi::FromInt(0), array->length()); 758 CHECK_EQ(Smi::FromInt(0), array->length());
759 // Must be in fast mode. 759 // Must be in fast mode.
760 CHECK(array->HasFastSmiOrObjectElements()); 760 CHECK(array->HasFastSmiOrObjectElements());
761 761
762 // array[length] = name. 762 // array[length] = name.
763 array->SetElement(0, *name, NONE, kNonStrictMode)->ToObjectChecked(); 763 JSReceiver::SetElement(array, 0, name, NONE, kNonStrictMode);
764 CHECK_EQ(Smi::FromInt(1), array->length()); 764 CHECK_EQ(Smi::FromInt(1), array->length());
765 CHECK_EQ(array->GetElement(isolate, 0), *name); 765 CHECK_EQ(array->GetElement(isolate, 0), *name);
766 766
767 // Set array length with larger than smi value. 767 // Set array length with larger than smi value.
768 Handle<Object> length = 768 Handle<Object> length =
769 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 769 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
770 array->SetElementsLength(*length)->ToObjectChecked(); 770 array->SetElementsLength(*length)->ToObjectChecked();
771 771
772 uint32_t int_length = 0; 772 uint32_t int_length = 0;
773 CHECK(length->ToArrayIndex(&int_length)); 773 CHECK(length->ToArrayIndex(&int_length));
774 CHECK_EQ(*length, array->length()); 774 CHECK_EQ(*length, array->length());
775 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 775 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
776 776
777 // array[length] = name. 777 // array[length] = name.
778 array->SetElement(int_length, *name, NONE, kNonStrictMode)->ToObjectChecked(); 778 JSReceiver::SetElement(array, int_length, name, NONE, kNonStrictMode);
779 uint32_t new_int_length = 0; 779 uint32_t new_int_length = 0;
780 CHECK(array->length()->ToArrayIndex(&new_int_length)); 780 CHECK(array->length()->ToArrayIndex(&new_int_length));
781 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 781 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
782 CHECK_EQ(array->GetElement(isolate, int_length), *name); 782 CHECK_EQ(array->GetElement(isolate, int_length), *name);
783 CHECK_EQ(array->GetElement(isolate, 0), *name); 783 CHECK_EQ(array->GetElement(isolate, 0), *name);
784 } 784 }
785 785
786 786
787 TEST(JSObjectCopy) { 787 TEST(JSObjectCopy) {
788 CcTest::InitializeVM(); 788 CcTest::InitializeVM();
789 Isolate* isolate = CcTest::i_isolate(); 789 Isolate* isolate = CcTest::i_isolate();
790 Factory* factory = isolate->factory(); 790 Factory* factory = isolate->factory();
791 791
792 v8::HandleScope sc(CcTest::isolate()); 792 v8::HandleScope sc(CcTest::isolate());
793 String* object_string = String::cast(CcTest::heap()->Object_string()); 793 String* object_string = String::cast(CcTest::heap()->Object_string());
794 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 794 Object* raw_object = CcTest::i_isolate()->context()->global_object()->
795 GetProperty(object_string)->ToObjectChecked(); 795 GetProperty(object_string)->ToObjectChecked();
796 JSFunction* object_function = JSFunction::cast(raw_object); 796 JSFunction* object_function = JSFunction::cast(raw_object);
797 Handle<JSFunction> constructor(object_function); 797 Handle<JSFunction> constructor(object_function);
798 Handle<JSObject> obj = factory->NewJSObject(constructor); 798 Handle<JSObject> obj = factory->NewJSObject(constructor);
799 Handle<String> first = factory->InternalizeUtf8String("first"); 799 Handle<String> first = factory->InternalizeUtf8String("first");
800 Handle<String> second = factory->InternalizeUtf8String("second"); 800 Handle<String> second = factory->InternalizeUtf8String("second");
801 801
802 Handle<Smi> one(Smi::FromInt(1), isolate); 802 Handle<Smi> one(Smi::FromInt(1), isolate);
803 Handle<Smi> two(Smi::FromInt(2), isolate); 803 Handle<Smi> two(Smi::FromInt(2), isolate);
804 804
805 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode); 805 JSReceiver::SetProperty(obj, first, one, NONE, kNonStrictMode);
806 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode); 806 JSReceiver::SetProperty(obj, second, two, NONE, kNonStrictMode);
807 807
808 obj->SetElement(0, *first, NONE, kNonStrictMode)->ToObjectChecked(); 808 JSReceiver::SetElement(obj, 0, first, NONE, kNonStrictMode);
809 obj->SetElement(1, *second, NONE, kNonStrictMode)->ToObjectChecked(); 809 JSReceiver::SetElement(obj, 1, second, NONE, kNonStrictMode);
810 810
811 // Make the clone. 811 // Make the clone.
812 Handle<JSObject> clone = JSObject::Copy(obj); 812 Handle<JSObject> clone = JSObject::Copy(obj);
813 CHECK(!clone.is_identical_to(obj)); 813 CHECK(!clone.is_identical_to(obj));
814 814
815 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0)); 815 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0));
816 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1)); 816 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1));
817 817
818 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); 818 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
819 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); 819 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
820 820
821 // Flip the values. 821 // Flip the values.
822 JSReceiver::SetProperty(clone, first, two, NONE, kNonStrictMode); 822 JSReceiver::SetProperty(clone, first, two, NONE, kNonStrictMode);
823 JSReceiver::SetProperty(clone, second, one, NONE, kNonStrictMode); 823 JSReceiver::SetProperty(clone, second, one, NONE, kNonStrictMode);
824 824
825 clone->SetElement(0, *second, NONE, kNonStrictMode)->ToObjectChecked(); 825 JSReceiver::SetElement(clone, 0, second, NONE, kNonStrictMode);
826 clone->SetElement(1, *first, NONE, kNonStrictMode)->ToObjectChecked(); 826 JSReceiver::SetElement(clone, 1, first, NONE, kNonStrictMode);
827 827
828 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0)); 828 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0));
829 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1)); 829 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1));
830 830
831 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 831 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
832 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 832 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
833 } 833 }
834 834
835 835
836 TEST(StringAllocation) { 836 TEST(StringAllocation) {
(...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after
3542 CompileRun("run()"); 3542 CompileRun("run()");
3543 3543
3544 // Run test with inline allocation disabled and pretenuring. 3544 // Run test with inline allocation disabled and pretenuring.
3545 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true); 3545 CcTest::heap()->SetNewSpaceHighPromotionModeActive(true);
3546 CompileRun("run()"); 3546 CompileRun("run()");
3547 3547
3548 // Run test with inline allocation re-enabled. 3548 // Run test with inline allocation re-enabled.
3549 CcTest::heap()->EnableInlineAllocation(); 3549 CcTest::heap()->EnableInlineAllocation();
3550 CompileRun("run()"); 3550 CompileRun("run()");
3551 } 3551 }
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698