OLD | NEW |
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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 | 760 |
761 // Set array length to 0. | 761 // Set array length to 0. |
762 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); | 762 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); |
763 CHECK_EQ(Smi::FromInt(0), array->length()); | 763 CHECK_EQ(Smi::FromInt(0), array->length()); |
764 // Must be in fast mode. | 764 // Must be in fast mode. |
765 CHECK(array->HasFastSmiOrObjectElements()); | 765 CHECK(array->HasFastSmiOrObjectElements()); |
766 | 766 |
767 // array[length] = name. | 767 // array[length] = name. |
768 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY); | 768 JSReceiver::SetElement(array, 0, name, NONE, SLOPPY); |
769 CHECK_EQ(Smi::FromInt(1), array->length()); | 769 CHECK_EQ(Smi::FromInt(1), array->length()); |
770 CHECK_EQ(array->GetElement(isolate, 0), *name); | 770 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); |
771 | 771 |
772 // Set array length with larger than smi value. | 772 // Set array length with larger than smi value. |
773 Handle<Object> length = | 773 Handle<Object> length = |
774 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 774 factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
775 array->SetElementsLength(*length)->ToObjectChecked(); | 775 array->SetElementsLength(*length)->ToObjectChecked(); |
776 | 776 |
777 uint32_t int_length = 0; | 777 uint32_t int_length = 0; |
778 CHECK(length->ToArrayIndex(&int_length)); | 778 CHECK(length->ToArrayIndex(&int_length)); |
779 CHECK_EQ(*length, array->length()); | 779 CHECK_EQ(*length, array->length()); |
780 CHECK(array->HasDictionaryElements()); // Must be in slow mode. | 780 CHECK(array->HasDictionaryElements()); // Must be in slow mode. |
781 | 781 |
782 // array[length] = name. | 782 // array[length] = name. |
783 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY); | 783 JSReceiver::SetElement(array, int_length, name, NONE, SLOPPY); |
784 uint32_t new_int_length = 0; | 784 uint32_t new_int_length = 0; |
785 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 785 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
786 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 786 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
787 CHECK_EQ(array->GetElement(isolate, int_length), *name); | 787 CHECK_EQ(*i::Object::GetElement(isolate, array, int_length), *name); |
788 CHECK_EQ(array->GetElement(isolate, 0), *name); | 788 CHECK_EQ(*i::Object::GetElement(isolate, array, 0), *name); |
789 } | 789 } |
790 | 790 |
791 | 791 |
792 TEST(JSObjectCopy) { | 792 TEST(JSObjectCopy) { |
793 CcTest::InitializeVM(); | 793 CcTest::InitializeVM(); |
794 Isolate* isolate = CcTest::i_isolate(); | 794 Isolate* isolate = CcTest::i_isolate(); |
795 Factory* factory = isolate->factory(); | 795 Factory* factory = isolate->factory(); |
796 | 796 |
797 v8::HandleScope sc(CcTest::isolate()); | 797 v8::HandleScope sc(CcTest::isolate()); |
798 String* object_string = String::cast(CcTest::heap()->Object_string()); | 798 String* object_string = String::cast(CcTest::heap()->Object_string()); |
(...skipping 11 matching lines...) Expand all Loading... |
810 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); | 810 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); |
811 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY); | 811 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY); |
812 | 812 |
813 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY); | 813 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY); |
814 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY); | 814 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY); |
815 | 815 |
816 // Make the clone. | 816 // Make the clone. |
817 Handle<JSObject> clone = JSObject::Copy(obj); | 817 Handle<JSObject> clone = JSObject::Copy(obj); |
818 CHECK(!clone.is_identical_to(obj)); | 818 CHECK(!clone.is_identical_to(obj)); |
819 | 819 |
820 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 0)); | 820 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), |
821 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 1)); | 821 *i::Object::GetElement(isolate, clone, 0)); |
| 822 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), |
| 823 *i::Object::GetElement(isolate, clone, 1)); |
822 | 824 |
823 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 825 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
824 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 826 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
825 | 827 |
826 // Flip the values. | 828 // Flip the values. |
827 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY); | 829 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY); |
828 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY); | 830 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY); |
829 | 831 |
830 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY); | 832 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY); |
831 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY); | 833 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY); |
832 | 834 |
833 CHECK_EQ(obj->GetElement(isolate, 1), clone->GetElement(isolate, 0)); | 835 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), |
834 CHECK_EQ(obj->GetElement(isolate, 0), clone->GetElement(isolate, 1)); | 836 *i::Object::GetElement(isolate, clone, 0)); |
| 837 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), |
| 838 *i::Object::GetElement(isolate, clone, 1)); |
835 | 839 |
836 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 840 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
837 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 841 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
838 } | 842 } |
839 | 843 |
840 | 844 |
841 TEST(StringAllocation) { | 845 TEST(StringAllocation) { |
842 CcTest::InitializeVM(); | 846 CcTest::InitializeVM(); |
843 Isolate* isolate = CcTest::i_isolate(); | 847 Isolate* isolate = CcTest::i_isolate(); |
844 Factory* factory = isolate->factory(); | 848 Factory* factory = isolate->factory(); |
(...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 v8::Handle<v8::Object> global = CcTest::global(); | 3737 v8::Handle<v8::Object> global = CcTest::global(); |
3734 v8::Handle<v8::Function> g = | 3738 v8::Handle<v8::Function> g = |
3735 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); | 3739 v8::Handle<v8::Function>::Cast(global->Get(v8_str("crash"))); |
3736 v8::Handle<v8::Value> args1[] = { v8_num(1) }; | 3740 v8::Handle<v8::Value> args1[] = { v8_num(1) }; |
3737 heap->DisableInlineAllocation(); | 3741 heap->DisableInlineAllocation(); |
3738 heap->set_allocation_timeout(1); | 3742 heap->set_allocation_timeout(1); |
3739 g->Call(global, 1, args1); | 3743 g->Call(global, 1, args1); |
3740 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 3744 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
3741 } | 3745 } |
3742 #endif | 3746 #endif |
OLD | NEW |