| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 InitializeVM(); | 630 InitializeVM(); |
| 631 | 631 |
| 632 v8::HandleScope sc; | 632 v8::HandleScope sc; |
| 633 Handle<String> name = Factory::LookupAsciiSymbol("Array"); | 633 Handle<String> name = Factory::LookupAsciiSymbol("Array"); |
| 634 Handle<JSFunction> function = Handle<JSFunction>( | 634 Handle<JSFunction> function = Handle<JSFunction>( |
| 635 JSFunction::cast(Top::context()->global()->GetProperty(*name))); | 635 JSFunction::cast(Top::context()->global()->GetProperty(*name))); |
| 636 | 636 |
| 637 // Allocate the object. | 637 // Allocate the object. |
| 638 Handle<JSObject> object = Factory::NewJSObject(function); | 638 Handle<JSObject> object = Factory::NewJSObject(function); |
| 639 Handle<JSArray> array = Handle<JSArray>::cast(object); | 639 Handle<JSArray> array = Handle<JSArray>::cast(object); |
| 640 array->Initialize(0); | 640 Object* ok = array->Initialize(0); |
| 641 // We just initialized the VM, no heap allocation failure yet. |
| 642 CHECK(!ok->IsFailure()); |
| 641 | 643 |
| 642 // Set array length to 0. | 644 // Set array length to 0. |
| 643 array->SetElementsLength(Smi::FromInt(0)); | 645 ok = array->SetElementsLength(Smi::FromInt(0)); |
| 646 CHECK(!ok->IsFailure()); |
| 644 CHECK_EQ(Smi::FromInt(0), array->length()); | 647 CHECK_EQ(Smi::FromInt(0), array->length()); |
| 645 CHECK(array->HasFastElements()); // Must be in fast mode. | 648 CHECK(array->HasFastElements()); // Must be in fast mode. |
| 646 | 649 |
| 647 // array[length] = name. | 650 // array[length] = name. |
| 648 array->SetElement(0, *name); | 651 ok = array->SetElement(0, *name); |
| 652 CHECK(!ok->IsFailure()); |
| 649 CHECK_EQ(Smi::FromInt(1), array->length()); | 653 CHECK_EQ(Smi::FromInt(1), array->length()); |
| 650 CHECK_EQ(array->GetElement(0), *name); | 654 CHECK_EQ(array->GetElement(0), *name); |
| 651 | 655 |
| 652 // Set array length with larger than smi value. | 656 // Set array length with larger than smi value. |
| 653 Handle<Object> length = | 657 Handle<Object> length = |
| 654 Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); | 658 Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); |
| 655 array->SetElementsLength(*length); | 659 ok = array->SetElementsLength(*length); |
| 660 CHECK(!ok->IsFailure()); |
| 656 | 661 |
| 657 uint32_t int_length = 0; | 662 uint32_t int_length = 0; |
| 658 CHECK(length->ToArrayIndex(&int_length)); | 663 CHECK(length->ToArrayIndex(&int_length)); |
| 659 CHECK_EQ(*length, array->length()); | 664 CHECK_EQ(*length, array->length()); |
| 660 CHECK(array->HasDictionaryElements()); // Must be in slow mode. | 665 CHECK(array->HasDictionaryElements()); // Must be in slow mode. |
| 661 | 666 |
| 662 // array[length] = name. | 667 // array[length] = name. |
| 663 array->SetElement(int_length, *name); | 668 ok = array->SetElement(int_length, *name); |
| 669 CHECK(!ok->IsFailure()); |
| 664 uint32_t new_int_length = 0; | 670 uint32_t new_int_length = 0; |
| 665 CHECK(array->length()->ToArrayIndex(&new_int_length)); | 671 CHECK(array->length()->ToArrayIndex(&new_int_length)); |
| 666 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); | 672 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); |
| 667 CHECK_EQ(array->GetElement(int_length), *name); | 673 CHECK_EQ(array->GetElement(int_length), *name); |
| 668 CHECK_EQ(array->GetElement(0), *name); | 674 CHECK_EQ(array->GetElement(0), *name); |
| 669 } | 675 } |
| 670 | 676 |
| 671 | 677 |
| 672 TEST(JSObjectCopy) { | 678 TEST(JSObjectCopy) { |
| 673 InitializeVM(); | 679 InitializeVM(); |
| 674 | 680 |
| 675 v8::HandleScope sc; | 681 v8::HandleScope sc; |
| 676 String* object_symbol = String::cast(Heap::Object_symbol()); | 682 String* object_symbol = String::cast(Heap::Object_symbol()); |
| 677 JSFunction* object_function = | 683 JSFunction* object_function = |
| 678 JSFunction::cast(Top::context()->global()->GetProperty(object_symbol)); | 684 JSFunction::cast(Top::context()->global()->GetProperty(object_symbol)); |
| 679 Handle<JSFunction> constructor(object_function); | 685 Handle<JSFunction> constructor(object_function); |
| 680 Handle<JSObject> obj = Factory::NewJSObject(constructor); | 686 Handle<JSObject> obj = Factory::NewJSObject(constructor); |
| 681 Handle<String> first = Factory::LookupAsciiSymbol("first"); | 687 Handle<String> first = Factory::LookupAsciiSymbol("first"); |
| 682 Handle<String> second = Factory::LookupAsciiSymbol("second"); | 688 Handle<String> second = Factory::LookupAsciiSymbol("second"); |
| 683 | 689 |
| 684 obj->SetProperty(*first, Smi::FromInt(1), NONE); | 690 obj->SetProperty(*first, Smi::FromInt(1), NONE); |
| 685 obj->SetProperty(*second, Smi::FromInt(2), NONE); | 691 obj->SetProperty(*second, Smi::FromInt(2), NONE); |
| 686 | 692 |
| 687 obj->SetElement(0, *first); | 693 Object* ok = obj->SetElement(0, *first); |
| 688 obj->SetElement(1, *second); | 694 CHECK(!ok->IsFailure()); |
| 695 |
| 696 ok = obj->SetElement(1, *second); |
| 697 CHECK(!ok->IsFailure()); |
| 689 | 698 |
| 690 // Make the clone. | 699 // Make the clone. |
| 691 Handle<JSObject> clone = Copy(obj); | 700 Handle<JSObject> clone = Copy(obj); |
| 692 CHECK(!clone.is_identical_to(obj)); | 701 CHECK(!clone.is_identical_to(obj)); |
| 693 | 702 |
| 694 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); | 703 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); |
| 695 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); | 704 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); |
| 696 | 705 |
| 697 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); | 706 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); |
| 698 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); | 707 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); |
| 699 | 708 |
| 700 // Flip the values. | 709 // Flip the values. |
| 701 clone->SetProperty(*first, Smi::FromInt(2), NONE); | 710 clone->SetProperty(*first, Smi::FromInt(2), NONE); |
| 702 clone->SetProperty(*second, Smi::FromInt(1), NONE); | 711 clone->SetProperty(*second, Smi::FromInt(1), NONE); |
| 703 | 712 |
| 704 clone->SetElement(0, *second); | 713 ok = clone->SetElement(0, *second); |
| 705 clone->SetElement(1, *first); | 714 CHECK(!ok->IsFailure()); |
| 715 ok = clone->SetElement(1, *first); |
| 716 CHECK(!ok->IsFailure()); |
| 706 | 717 |
| 707 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); | 718 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); |
| 708 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); | 719 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); |
| 709 | 720 |
| 710 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); | 721 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); |
| 711 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); | 722 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); |
| 712 } | 723 } |
| 713 | 724 |
| 714 | 725 |
| 715 TEST(StringAllocation) { | 726 TEST(StringAllocation) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 Heap::CollectAllGarbage(true); | 994 Heap::CollectAllGarbage(true); |
| 984 | 995 |
| 985 // foo should no longer be in the compilation cache | 996 // foo should no longer be in the compilation cache |
| 986 CHECK(!function->shared()->is_compiled()); | 997 CHECK(!function->shared()->is_compiled()); |
| 987 CHECK(!function->is_compiled()); | 998 CHECK(!function->is_compiled()); |
| 988 // Call foo to get it recompiled. | 999 // Call foo to get it recompiled. |
| 989 CompileRun("foo()"); | 1000 CompileRun("foo()"); |
| 990 CHECK(function->shared()->is_compiled()); | 1001 CHECK(function->shared()->is_compiled()); |
| 991 CHECK(function->is_compiled()); | 1002 CHECK(function->is_compiled()); |
| 992 } | 1003 } |
| OLD | NEW |