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

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

Issue 225283005: Return MaybeHandle from SetProperty. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 8 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
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); 278 Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
279 279
280 { 280 {
281 HandleScope inner_scope(isolate); 281 HandleScope inner_scope(isolate);
282 // Allocate a function and keep it in global object's property. 282 // Allocate a function and keep it in global object's property.
283 Handle<JSFunction> function = 283 Handle<JSFunction> function =
284 factory->NewFunction(name, factory->undefined_value()); 284 factory->NewFunction(name, factory->undefined_value());
285 Handle<Map> initial_map = 285 Handle<Map> initial_map =
286 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 286 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
287 function->set_initial_map(*initial_map); 287 function->set_initial_map(*initial_map);
288 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY); 288 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check();
289 // Allocate an object. Unrooted after leaving the scope. 289 // Allocate an object. Unrooted after leaving the scope.
290 Handle<JSObject> obj = factory->NewJSObject(function); 290 Handle<JSObject> obj = factory->NewJSObject(function);
291 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY); 291 JSReceiver::SetProperty(
292 JSReceiver::SetProperty(obj, prop_namex, twenty_four, NONE, SLOPPY); 292 obj, prop_name, twenty_three, NONE, SLOPPY).Check();
293 JSReceiver::SetProperty(
294 obj, prop_namex, twenty_four, NONE, SLOPPY).Check();
293 295
294 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 296 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
295 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex)); 297 CHECK_EQ(Smi::FromInt(24), obj->GetProperty(*prop_namex));
296 } 298 }
297 299
298 heap->CollectGarbage(NEW_SPACE); 300 heap->CollectGarbage(NEW_SPACE);
299 301
300 // Function should be alive. 302 // Function should be alive.
301 CHECK(JSReceiver::HasLocalProperty(global, name)); 303 CHECK(JSReceiver::HasLocalProperty(global, name));
302 // Check function is retained. 304 // Check function is retained.
303 Object* func_value = CcTest::i_isolate()->context()->global_object()-> 305 Object* func_value = CcTest::i_isolate()->context()->global_object()->
304 GetProperty(*name)->ToObjectChecked(); 306 GetProperty(*name)->ToObjectChecked();
305 CHECK(func_value->IsJSFunction()); 307 CHECK(func_value->IsJSFunction());
306 Handle<JSFunction> function(JSFunction::cast(func_value)); 308 Handle<JSFunction> function(JSFunction::cast(func_value));
307 309
308 { 310 {
309 HandleScope inner_scope(isolate); 311 HandleScope inner_scope(isolate);
310 // Allocate another object, make it reachable from global. 312 // Allocate another object, make it reachable from global.
311 Handle<JSObject> obj = factory->NewJSObject(function); 313 Handle<JSObject> obj = factory->NewJSObject(function);
312 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY); 314 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check();
313 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY); 315 JSReceiver::SetProperty(
316 obj, prop_name, twenty_three, NONE, SLOPPY).Check();
314 } 317 }
315 318
316 // After gc, it should survive. 319 // After gc, it should survive.
317 heap->CollectGarbage(NEW_SPACE); 320 heap->CollectGarbage(NEW_SPACE);
318 321
319 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); 322 CHECK(JSReceiver::HasLocalProperty(global, obj_name));
320 CHECK(CcTest::i_isolate()->context()->global_object()-> 323 CHECK(CcTest::i_isolate()->context()->global_object()->
321 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject()); 324 GetProperty(*obj_name)->ToObjectChecked()->IsJSObject());
322 Object* obj = CcTest::i_isolate()->context()->global_object()-> 325 Object* obj = CcTest::i_isolate()->context()->global_object()->
323 GetProperty(*obj_name)->ToObjectChecked(); 326 GetProperty(*obj_name)->ToObjectChecked();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 factory->NewFunction(name, factory->undefined_value()); 641 factory->NewFunction(name, factory->undefined_value());
639 Handle<Map> initial_map = 642 Handle<Map> initial_map =
640 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 643 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
641 function->set_initial_map(*initial_map); 644 function->set_initial_map(*initial_map);
642 645
643 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 646 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
644 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); 647 Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
645 648
646 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 649 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
647 Handle<JSObject> obj = factory->NewJSObject(function); 650 Handle<JSObject> obj = factory->NewJSObject(function);
648 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY); 651 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check();
649 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 652 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
650 // Check that we can add properties to function objects. 653 // Check that we can add properties to function objects.
651 JSReceiver::SetProperty(function, prop_name, twenty_four, NONE, SLOPPY); 654 JSReceiver::SetProperty(
655 function, prop_name, twenty_four, NONE, SLOPPY).Check();
652 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name)); 656 CHECK_EQ(Smi::FromInt(24), function->GetProperty(*prop_name));
653 } 657 }
654 658
655 659
656 TEST(ObjectProperties) { 660 TEST(ObjectProperties) {
657 CcTest::InitializeVM(); 661 CcTest::InitializeVM();
658 Isolate* isolate = CcTest::i_isolate(); 662 Isolate* isolate = CcTest::i_isolate();
659 Factory* factory = isolate->factory(); 663 Factory* factory = isolate->factory();
660 664
661 v8::HandleScope sc(CcTest::isolate()); 665 v8::HandleScope sc(CcTest::isolate());
662 String* object_string = String::cast(CcTest::heap()->Object_string()); 666 String* object_string = String::cast(CcTest::heap()->Object_string());
663 Object* raw_object = CcTest::i_isolate()->context()->global_object()-> 667 Object* raw_object = CcTest::i_isolate()->context()->global_object()->
664 GetProperty(object_string)->ToObjectChecked(); 668 GetProperty(object_string)->ToObjectChecked();
665 JSFunction* object_function = JSFunction::cast(raw_object); 669 JSFunction* object_function = JSFunction::cast(raw_object);
666 Handle<JSFunction> constructor(object_function); 670 Handle<JSFunction> constructor(object_function);
667 Handle<JSObject> obj = factory->NewJSObject(constructor); 671 Handle<JSObject> obj = factory->NewJSObject(constructor);
668 Handle<String> first = factory->InternalizeUtf8String("first"); 672 Handle<String> first = factory->InternalizeUtf8String("first");
669 Handle<String> second = factory->InternalizeUtf8String("second"); 673 Handle<String> second = factory->InternalizeUtf8String("second");
670 674
671 Handle<Smi> one(Smi::FromInt(1), isolate); 675 Handle<Smi> one(Smi::FromInt(1), isolate);
672 Handle<Smi> two(Smi::FromInt(2), isolate); 676 Handle<Smi> two(Smi::FromInt(2), isolate);
673 677
674 // check for empty 678 // check for empty
675 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 679 CHECK(!JSReceiver::HasLocalProperty(obj, first));
676 680
677 // add first 681 // add first
678 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); 682 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check();
679 CHECK(JSReceiver::HasLocalProperty(obj, first)); 683 CHECK(JSReceiver::HasLocalProperty(obj, first));
680 684
681 // delete first 685 // delete first
682 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 686 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
683 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 687 CHECK(!JSReceiver::HasLocalProperty(obj, first));
684 688
685 // add first and then second 689 // add first and then second
686 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); 690 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check();
687 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY); 691 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check();
688 CHECK(JSReceiver::HasLocalProperty(obj, first)); 692 CHECK(JSReceiver::HasLocalProperty(obj, first));
689 CHECK(JSReceiver::HasLocalProperty(obj, second)); 693 CHECK(JSReceiver::HasLocalProperty(obj, second));
690 694
691 // delete first and then second 695 // delete first and then second
692 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 696 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
693 CHECK(JSReceiver::HasLocalProperty(obj, second)); 697 CHECK(JSReceiver::HasLocalProperty(obj, second));
694 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); 698 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
695 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 699 CHECK(!JSReceiver::HasLocalProperty(obj, first));
696 CHECK(!JSReceiver::HasLocalProperty(obj, second)); 700 CHECK(!JSReceiver::HasLocalProperty(obj, second));
697 701
698 // add first and then second 702 // add first and then second
699 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); 703 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check();
700 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY); 704 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check();
701 CHECK(JSReceiver::HasLocalProperty(obj, first)); 705 CHECK(JSReceiver::HasLocalProperty(obj, first));
702 CHECK(JSReceiver::HasLocalProperty(obj, second)); 706 CHECK(JSReceiver::HasLocalProperty(obj, second));
703 707
704 // delete second and then first 708 // delete second and then first
705 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION); 709 JSReceiver::DeleteProperty(obj, second, JSReceiver::NORMAL_DELETION);
706 CHECK(JSReceiver::HasLocalProperty(obj, first)); 710 CHECK(JSReceiver::HasLocalProperty(obj, first));
707 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION); 711 JSReceiver::DeleteProperty(obj, first, JSReceiver::NORMAL_DELETION);
708 CHECK(!JSReceiver::HasLocalProperty(obj, first)); 712 CHECK(!JSReceiver::HasLocalProperty(obj, first));
709 CHECK(!JSReceiver::HasLocalProperty(obj, second)); 713 CHECK(!JSReceiver::HasLocalProperty(obj, second));
710 714
711 // check string and internalized string match 715 // check string and internalized string match
712 const char* string1 = "fisk"; 716 const char* string1 = "fisk";
713 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1)); 717 Handle<String> s1 = factory->NewStringFromAscii(CStrVector(string1));
714 JSReceiver::SetProperty(obj, s1, one, NONE, SLOPPY); 718 JSReceiver::SetProperty(obj, s1, one, NONE, SLOPPY).Check();
715 Handle<String> s1_string = factory->InternalizeUtf8String(string1); 719 Handle<String> s1_string = factory->InternalizeUtf8String(string1);
716 CHECK(JSReceiver::HasLocalProperty(obj, s1_string)); 720 CHECK(JSReceiver::HasLocalProperty(obj, s1_string));
717 721
718 // check internalized string and string match 722 // check internalized string and string match
719 const char* string2 = "fugl"; 723 const char* string2 = "fugl";
720 Handle<String> s2_string = factory->InternalizeUtf8String(string2); 724 Handle<String> s2_string = factory->InternalizeUtf8String(string2);
721 JSReceiver::SetProperty(obj, s2_string, one, NONE, SLOPPY); 725 JSReceiver::SetProperty(obj, s2_string, one, NONE, SLOPPY).Check();
722 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2)); 726 Handle<String> s2 = factory->NewStringFromAscii(CStrVector(string2));
723 CHECK(JSReceiver::HasLocalProperty(obj, s2)); 727 CHECK(JSReceiver::HasLocalProperty(obj, s2));
724 } 728 }
725 729
726 730
727 TEST(JSObjectMaps) { 731 TEST(JSObjectMaps) {
728 CcTest::InitializeVM(); 732 CcTest::InitializeVM();
729 Isolate* isolate = CcTest::i_isolate(); 733 Isolate* isolate = CcTest::i_isolate();
730 Factory* factory = isolate->factory(); 734 Factory* factory = isolate->factory();
731 735
732 v8::HandleScope sc(CcTest::isolate()); 736 v8::HandleScope sc(CcTest::isolate());
733 Handle<String> name = factory->InternalizeUtf8String("theFunction"); 737 Handle<String> name = factory->InternalizeUtf8String("theFunction");
734 Handle<JSFunction> function = 738 Handle<JSFunction> function =
735 factory->NewFunction(name, factory->undefined_value()); 739 factory->NewFunction(name, factory->undefined_value());
736 Handle<Map> initial_map = 740 Handle<Map> initial_map =
737 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); 741 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
738 function->set_initial_map(*initial_map); 742 function->set_initial_map(*initial_map);
739 743
740 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); 744 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
741 Handle<JSObject> obj = factory->NewJSObject(function); 745 Handle<JSObject> obj = factory->NewJSObject(function);
742 746
743 // Set a propery 747 // Set a propery
744 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 748 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
745 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY); 749 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check();
746 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name)); 750 CHECK_EQ(Smi::FromInt(23), obj->GetProperty(*prop_name));
747 751
748 // Check the map has changed 752 // Check the map has changed
749 CHECK(*initial_map != obj->map()); 753 CHECK(*initial_map != obj->map());
750 } 754 }
751 755
752 756
753 TEST(JSArray) { 757 TEST(JSArray) {
754 CcTest::InitializeVM(); 758 CcTest::InitializeVM();
755 Isolate* isolate = CcTest::i_isolate(); 759 Isolate* isolate = CcTest::i_isolate();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 GetProperty(object_string)->ToObjectChecked(); 814 GetProperty(object_string)->ToObjectChecked();
811 JSFunction* object_function = JSFunction::cast(raw_object); 815 JSFunction* object_function = JSFunction::cast(raw_object);
812 Handle<JSFunction> constructor(object_function); 816 Handle<JSFunction> constructor(object_function);
813 Handle<JSObject> obj = factory->NewJSObject(constructor); 817 Handle<JSObject> obj = factory->NewJSObject(constructor);
814 Handle<String> first = factory->InternalizeUtf8String("first"); 818 Handle<String> first = factory->InternalizeUtf8String("first");
815 Handle<String> second = factory->InternalizeUtf8String("second"); 819 Handle<String> second = factory->InternalizeUtf8String("second");
816 820
817 Handle<Smi> one(Smi::FromInt(1), isolate); 821 Handle<Smi> one(Smi::FromInt(1), isolate);
818 Handle<Smi> two(Smi::FromInt(2), isolate); 822 Handle<Smi> two(Smi::FromInt(2), isolate);
819 823
820 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY); 824 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check();
821 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY); 825 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check();
822 826
823 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY); 827 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY);
824 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY); 828 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY);
825 829
826 // Make the clone. 830 // Make the clone.
827 Handle<JSObject> clone = JSObject::Copy(obj); 831 Handle<JSObject> clone = JSObject::Copy(obj);
828 CHECK(!clone.is_identical_to(obj)); 832 CHECK(!clone.is_identical_to(obj));
829 833
830 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), 834 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
831 *i::Object::GetElement(isolate, clone, 0)); 835 *i::Object::GetElement(isolate, clone, 0));
832 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), 836 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
833 *i::Object::GetElement(isolate, clone, 1)); 837 *i::Object::GetElement(isolate, clone, 1));
834 838
835 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first)); 839 CHECK_EQ(obj->GetProperty(*first), clone->GetProperty(*first));
836 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second)); 840 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*second));
837 841
838 // Flip the values. 842 // Flip the values.
839 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY); 843 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check();
840 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY); 844 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check();
841 845
842 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY); 846 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY);
843 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY); 847 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY);
844 848
845 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1), 849 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1),
846 *i::Object::GetElement(isolate, clone, 0)); 850 *i::Object::GetElement(isolate, clone, 0));
847 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0), 851 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0),
848 *i::Object::GetElement(isolate, clone, 1)); 852 *i::Object::GetElement(isolate, clone, 1));
849 853
850 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first)); 854 CHECK_EQ(obj->GetProperty(*second), clone->GetProperty(*first));
(...skipping 3082 matching lines...) Expand 10 before | Expand all | Expand 10 after
3933 v8::Context::Scope cscope(context); 3937 v8::Context::Scope cscope(context);
3934 3938
3935 v8::Local<v8::Value> result = CompileRun( 3939 v8::Local<v8::Value> result = CompileRun(
3936 "var locals = '';" 3940 "var locals = '';"
3937 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" 3941 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';"
3938 "eval('function f() {' + locals + 'return function() { return v0; }; }');" 3942 "eval('function f() {' + locals + 'return function() { return v0; }; }');"
3939 "interrupt();" // This triggers a fake stack overflow in f. 3943 "interrupt();" // This triggers a fake stack overflow in f.
3940 "f()()"); 3944 "f()()");
3941 CHECK_EQ(42.0, result->ToNumber()->Value()); 3945 CHECK_EQ(42.0, result->ToNumber()->Value());
3942 } 3946 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698