OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "execution.h" | 7 #include "execution.h" |
8 #include "factory.h" | 8 #include "factory.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 #include "global-handles.h" | 10 #include "global-handles.h" |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 Handle<String> name = FACTORY->LookupAsciiSymbol("Array"); | 660 Handle<String> name = FACTORY->LookupAsciiSymbol("Array"); |
661 Object* raw_object = Isolate::Current()->context()->global()-> | 661 Object* raw_object = Isolate::Current()->context()->global()-> |
662 GetProperty(*name)->ToObjectChecked(); | 662 GetProperty(*name)->ToObjectChecked(); |
663 Handle<JSFunction> function = Handle<JSFunction>( | 663 Handle<JSFunction> function = Handle<JSFunction>( |
664 JSFunction::cast(raw_object)); | 664 JSFunction::cast(raw_object)); |
665 | 665 |
666 // Allocate the object. | 666 // Allocate the object. |
667 Handle<JSObject> object = FACTORY->NewJSObject(function); | 667 Handle<JSObject> object = FACTORY->NewJSObject(function); |
668 Handle<JSArray> array = Handle<JSArray>::cast(object); | 668 Handle<JSArray> array = Handle<JSArray>::cast(object); |
669 // We just initialized the VM, no heap allocation failure yet. | 669 // We just initialized the VM, no heap allocation failure yet. |
670 Object* ok = array->Initialize(0)->ToObjectChecked(); | 670 array->Initialize(0)->ToObjectChecked(); |
671 | 671 |
672 // Set array length to 0. | 672 // Set array length to 0. |
673 ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); | 673 array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); |
674 CHECK_EQ(Smi::FromInt(0), array->length()); | 674 CHECK_EQ(Smi::FromInt(0), array->length()); |
675 // Must be in fast mode. | 675 // Must be in fast mode. |
676 CHECK(array->HasFastTypeElements()); | 676 CHECK(array->HasFastTypeElements()); |
677 | 677 |
678 // array[length] = name. | 678 // array[length] = name. |
679 ok = array->SetElement(0, *name, kNonStrictMode, true)->ToObjectChecked(); | 679 array->SetElement(0, *name, kNonStrictMode, true)->ToObjectChecked(); |
680 CHECK_EQ(Smi::FromInt(1), array->length()); | 680 CHECK_EQ(Smi::FromInt(1), array->length()); |
681 CHECK_EQ(array->GetElement(0), *name); | 681 CHECK_EQ(array->GetElement(0), *name); |
682 | 682 |
683 // Set array length with larger than smi value. | 683 // Set array length with larger than smi value. |
684 Handle<Object> length = | 684 Handle<Object> length = |
685 FACTORY->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 685 FACTORY->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
686 ok = array->SetElementsLength(*length)->ToObjectChecked(); | 686 array->SetElementsLength(*length)->ToObjectChecked(); |
687 | 687 |
688 uint32_t int_length = 0; | 688 uint32_t int_length = 0; |
689 CHECK(length->ToArrayIndex(&int_length)); | 689 CHECK(length->ToArrayIndex(&int_length)); |
690 CHECK_EQ(*length, array->length()); | 690 CHECK_EQ(*length, array->length()); |
691 CHECK(array->HasDictionaryElements()); // Must be in slow mode. | 691 CHECK(array->HasDictionaryElements()); // Must be in slow mode. |
692 | 692 |
693 // array[length] = name. | 693 // array[length] = name. |
694 ok = array->SetElement( | 694 array->SetElement(int_length, *name, kNonStrictMode, true)->ToObjectChecked(); |
695 int_length, *name, kNonStrictMode, true)->ToObjectChecked(); | |
696 uint32_t new_int_length = 0; | 695 uint32_t new_int_length = 0; |
697 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 696 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
698 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 697 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
699 CHECK_EQ(array->GetElement(int_length), *name); | 698 CHECK_EQ(array->GetElement(int_length), *name); |
700 CHECK_EQ(array->GetElement(0), *name); | 699 CHECK_EQ(array->GetElement(0), *name); |
701 } | 700 } |
702 | 701 |
703 | 702 |
704 TEST(JSObjectCopy) { | 703 TEST(JSObjectCopy) { |
705 InitializeVM(); | 704 InitializeVM(); |
706 | 705 |
707 v8::HandleScope sc; | 706 v8::HandleScope sc; |
708 String* object_symbol = String::cast(HEAP->Object_symbol()); | 707 String* object_symbol = String::cast(HEAP->Object_symbol()); |
709 Object* raw_object = Isolate::Current()->context()->global()-> | 708 Object* raw_object = Isolate::Current()->context()->global()-> |
710 GetProperty(object_symbol)->ToObjectChecked(); | 709 GetProperty(object_symbol)->ToObjectChecked(); |
711 JSFunction* object_function = JSFunction::cast(raw_object); | 710 JSFunction* object_function = JSFunction::cast(raw_object); |
712 Handle<JSFunction> constructor(object_function); | 711 Handle<JSFunction> constructor(object_function); |
713 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); | 712 Handle<JSObject> obj = FACTORY->NewJSObject(constructor); |
714 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); | 713 Handle<String> first = FACTORY->LookupAsciiSymbol("first"); |
715 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); | 714 Handle<String> second = FACTORY->LookupAsciiSymbol("second"); |
716 | 715 |
717 obj->SetProperty( | 716 obj->SetProperty( |
718 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 717 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
719 obj->SetProperty( | 718 obj->SetProperty( |
720 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); | 719 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
721 | 720 |
722 Object* ok = | 721 obj->SetElement(0, *first, kNonStrictMode, true)->ToObjectChecked(); |
723 obj->SetElement(0, *first, kNonStrictMode, true)->ToObjectChecked(); | 722 obj->SetElement(1, *second, kNonStrictMode, true)->ToObjectChecked(); |
724 | |
725 ok = obj->SetElement(1, *second, kNonStrictMode, true)->ToObjectChecked(); | |
726 | 723 |
727 // Make the clone. | 724 // Make the clone. |
728 Handle<JSObject> clone = Copy(obj); | 725 Handle<JSObject> clone = Copy(obj); |
729 CHECK(!clone.is_identical_to(obj)); | 726 CHECK(!clone.is_identical_to(obj)); |
730 | 727 |
731 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); | 728 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); |
732 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); | 729 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); |
733 | 730 |
734 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 731 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
735 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 732 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
736 | 733 |
737 // Flip the values. | 734 // Flip the values. |
738 clone->SetProperty( | 735 clone->SetProperty( |
739 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); | 736 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); |
740 clone->SetProperty( | 737 clone->SetProperty( |
741 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); | 738 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); |
742 | 739 |
743 ok = clone->SetElement(0, *second, kNonStrictMode, true)->ToObjectChecked(); | 740 clone->SetElement(0, *second, kNonStrictMode, true)->ToObjectChecked(); |
744 ok = clone->SetElement(1, *first, kNonStrictMode, true)->ToObjectChecked(); | 741 clone->SetElement(1, *first, kNonStrictMode, true)->ToObjectChecked(); |
745 | 742 |
746 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); | 743 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); |
747 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); | 744 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); |
748 | 745 |
749 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 746 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
750 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 747 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
751 } | 748 } |
752 | 749 |
753 | 750 |
754 TEST(StringAllocation) { | 751 TEST(StringAllocation) { |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 CHECK(old_capacity == 2 * new_capacity); | 1263 CHECK(old_capacity == 2 * new_capacity); |
1267 | 1264 |
1268 // Consecutive shrinking should not affect space capacity. | 1265 // Consecutive shrinking should not affect space capacity. |
1269 old_capacity = new_space->Capacity(); | 1266 old_capacity = new_space->Capacity(); |
1270 new_space->Shrink(); | 1267 new_space->Shrink(); |
1271 new_space->Shrink(); | 1268 new_space->Shrink(); |
1272 new_space->Shrink(); | 1269 new_space->Shrink(); |
1273 new_capacity = new_space->Capacity(); | 1270 new_capacity = new_space->Capacity(); |
1274 CHECK(old_capacity == new_capacity); | 1271 CHECK(old_capacity == new_capacity); |
1275 } | 1272 } |
OLD | NEW |