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

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

Issue 6613005: Implementation of strict mode in SetElement. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: SetElement in strict mode. Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 Handle<JSArray> array = Handle<JSArray>::cast(object); 663 Handle<JSArray> array = Handle<JSArray>::cast(object);
664 // We just initialized the VM, no heap allocation failure yet. 664 // We just initialized the VM, no heap allocation failure yet.
665 Object* ok = array->Initialize(0)->ToObjectChecked(); 665 Object* ok = array->Initialize(0)->ToObjectChecked();
666 666
667 // Set array length to 0. 667 // Set array length to 0.
668 ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked(); 668 ok = array->SetElementsLength(Smi::FromInt(0))->ToObjectChecked();
669 CHECK_EQ(Smi::FromInt(0), array->length()); 669 CHECK_EQ(Smi::FromInt(0), array->length());
670 CHECK(array->HasFastElements()); // Must be in fast mode. 670 CHECK(array->HasFastElements()); // Must be in fast mode.
671 671
672 // array[length] = name. 672 // array[length] = name.
673 ok = array->SetElement(0, *name)->ToObjectChecked(); 673 ok = array->SetElement(0, *name, kNonStrictMode)->ToObjectChecked();
674 CHECK_EQ(Smi::FromInt(1), array->length()); 674 CHECK_EQ(Smi::FromInt(1), array->length());
675 CHECK_EQ(array->GetElement(0), *name); 675 CHECK_EQ(array->GetElement(0), *name);
676 676
677 // Set array length with larger than smi value. 677 // Set array length with larger than smi value.
678 Handle<Object> length = 678 Handle<Object> length =
679 Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1); 679 Factory::NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
680 ok = array->SetElementsLength(*length)->ToObjectChecked(); 680 ok = array->SetElementsLength(*length)->ToObjectChecked();
681 681
682 uint32_t int_length = 0; 682 uint32_t int_length = 0;
683 CHECK(length->ToArrayIndex(&int_length)); 683 CHECK(length->ToArrayIndex(&int_length));
684 CHECK_EQ(*length, array->length()); 684 CHECK_EQ(*length, array->length());
685 CHECK(array->HasDictionaryElements()); // Must be in slow mode. 685 CHECK(array->HasDictionaryElements()); // Must be in slow mode.
686 686
687 // array[length] = name. 687 // array[length] = name.
688 ok = array->SetElement(int_length, *name)->ToObjectChecked(); 688 ok = array->SetElement(int_length, *name, kNonStrictMode)->ToObjectChecked();
689 uint32_t new_int_length = 0; 689 uint32_t new_int_length = 0;
690 CHECK(array->length()->ToArrayIndex(&new_int_length)); 690 CHECK(array->length()->ToArrayIndex(&new_int_length));
691 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1); 691 CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
692 CHECK_EQ(array->GetElement(int_length), *name); 692 CHECK_EQ(array->GetElement(int_length), *name);
693 CHECK_EQ(array->GetElement(0), *name); 693 CHECK_EQ(array->GetElement(0), *name);
694 } 694 }
695 695
696 696
697 TEST(JSObjectCopy) { 697 TEST(JSObjectCopy) {
698 InitializeVM(); 698 InitializeVM();
699 699
700 v8::HandleScope sc; 700 v8::HandleScope sc;
701 String* object_symbol = String::cast(Heap::Object_symbol()); 701 String* object_symbol = String::cast(Heap::Object_symbol());
702 Object* raw_object = 702 Object* raw_object =
703 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked(); 703 Top::context()->global()->GetProperty(object_symbol)->ToObjectChecked();
704 JSFunction* object_function = JSFunction::cast(raw_object); 704 JSFunction* object_function = JSFunction::cast(raw_object);
705 Handle<JSFunction> constructor(object_function); 705 Handle<JSFunction> constructor(object_function);
706 Handle<JSObject> obj = Factory::NewJSObject(constructor); 706 Handle<JSObject> obj = Factory::NewJSObject(constructor);
707 Handle<String> first = Factory::LookupAsciiSymbol("first"); 707 Handle<String> first = Factory::LookupAsciiSymbol("first");
708 Handle<String> second = Factory::LookupAsciiSymbol("second"); 708 Handle<String> second = Factory::LookupAsciiSymbol("second");
709 709
710 obj->SetProperty( 710 obj->SetProperty(
711 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 711 *first, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
712 obj->SetProperty( 712 obj->SetProperty(
713 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); 713 *second, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked();
714 714
715 Object* ok = obj->SetElement(0, *first)->ToObjectChecked(); 715 Object* ok = obj->SetElement(0, *first, kNonStrictMode)->ToObjectChecked();
716 716
717 ok = obj->SetElement(1, *second)->ToObjectChecked(); 717 ok = obj->SetElement(1, *second, kNonStrictMode)->ToObjectChecked();
718 718
719 // Make the clone. 719 // Make the clone.
720 Handle<JSObject> clone = Copy(obj); 720 Handle<JSObject> clone = Copy(obj);
721 CHECK(!clone.is_identical_to(obj)); 721 CHECK(!clone.is_identical_to(obj));
722 722
723 CHECK_EQ(obj->GetElement(0), clone->GetElement(0)); 723 CHECK_EQ(obj->GetElement(0), clone->GetElement(0));
724 CHECK_EQ(obj->GetElement(1), clone->GetElement(1)); 724 CHECK_EQ(obj->GetElement(1), clone->GetElement(1));
725 725
726 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); 726 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
727 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); 727 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
728 728
729 // Flip the values. 729 // Flip the values.
730 clone->SetProperty( 730 clone->SetProperty(
731 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked(); 731 *first, Smi::FromInt(2), NONE, kNonStrictMode)->ToObjectChecked();
732 clone->SetProperty( 732 clone->SetProperty(
733 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked(); 733 *second, Smi::FromInt(1), NONE, kNonStrictMode)->ToObjectChecked();
734 734
735 ok = clone->SetElement(0, *second)->ToObjectChecked(); 735 ok = clone->SetElement(0, *second, kNonStrictMode)->ToObjectChecked();
736 ok = clone->SetElement(1, *first)->ToObjectChecked(); 736 ok = clone->SetElement(1, *first, kNonStrictMode)->ToObjectChecked();
737 737
738 CHECK_EQ(obj->GetElement(1), clone->GetElement(0)); 738 CHECK_EQ(obj->GetElement(1), clone->GetElement(0));
739 CHECK_EQ(obj->GetElement(0), clone->GetElement(1)); 739 CHECK_EQ(obj->GetElement(0), clone->GetElement(1));
740 740
741 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 741 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
742 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second)); 742 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*second));
743 } 743 }
744 744
745 745
746 TEST(StringAllocation) { 746 TEST(StringAllocation) {
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 CHECK(helper.b_found()); 1308 CHECK(helper.b_found());
1309 } 1309 }
1310 // ...but is now unreachable. 1310 // ...but is now unreachable.
1311 { 1311 {
1312 HeapIteratorTestHelper helper(a_saved, *b); 1312 HeapIteratorTestHelper helper(a_saved, *b);
1313 helper.IterateHeap(HeapIterator::kFilterUnreachable); 1313 helper.IterateHeap(HeapIterator::kFilterUnreachable);
1314 CHECK(!helper.a_found()); 1314 CHECK(!helper.a_found());
1315 CHECK(helper.b_found()); 1315 CHECK(helper.b_found());
1316 } 1316 }
1317 } 1317 }
OLDNEW
« src/handles.cc ('K') | « test/cctest/test-api.cc ('k') | test/mjsunit/strict-mode.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698