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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 283 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
284 function->set_initial_map(*initial_map); | 284 function->set_initial_map(*initial_map); |
285 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check(); | 285 JSReceiver::SetProperty(global, name, function, NONE, SLOPPY).Check(); |
286 // Allocate an object. Unrooted after leaving the scope. | 286 // Allocate an object. Unrooted after leaving the scope. |
287 Handle<JSObject> obj = factory->NewJSObject(function); | 287 Handle<JSObject> obj = factory->NewJSObject(function); |
288 JSReceiver::SetProperty( | 288 JSReceiver::SetProperty( |
289 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); | 289 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); |
290 JSReceiver::SetProperty( | 290 JSReceiver::SetProperty( |
291 obj, prop_namex, twenty_four, NONE, SLOPPY).Check(); | 291 obj, prop_namex, twenty_four, NONE, SLOPPY).Check(); |
292 | 292 |
293 CHECK_EQ(Smi::FromInt(23), | 293 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name)); |
294 *Object::GetProperty(obj, prop_name).ToHandleChecked()); | 294 CHECK_EQ(Smi::FromInt(24), *Object::GetProperty(obj, prop_namex)); |
295 CHECK_EQ(Smi::FromInt(24), | |
296 *Object::GetProperty(obj, prop_namex).ToHandleChecked()); | |
297 } | 295 } |
298 | 296 |
299 heap->CollectGarbage(NEW_SPACE); | 297 heap->CollectGarbage(NEW_SPACE); |
300 | 298 |
301 // Function should be alive. | 299 // Function should be alive. |
302 CHECK(JSReceiver::HasLocalProperty(global, name)); | 300 CHECK(JSReceiver::HasLocalProperty(global, name)); |
303 // Check function is retained. | 301 // Check function is retained. |
304 Handle<Object> func_value = | 302 Handle<Object> func_value = Object::GetProperty(global, name); |
305 Object::GetProperty(global, name).ToHandleChecked(); | |
306 CHECK(func_value->IsJSFunction()); | 303 CHECK(func_value->IsJSFunction()); |
307 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 304 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
308 | 305 |
309 { | 306 { |
310 HandleScope inner_scope(isolate); | 307 HandleScope inner_scope(isolate); |
311 // Allocate another object, make it reachable from global. | 308 // Allocate another object, make it reachable from global. |
312 Handle<JSObject> obj = factory->NewJSObject(function); | 309 Handle<JSObject> obj = factory->NewJSObject(function); |
313 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check(); | 310 JSReceiver::SetProperty(global, obj_name, obj, NONE, SLOPPY).Check(); |
314 JSReceiver::SetProperty( | 311 JSReceiver::SetProperty( |
315 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); | 312 obj, prop_name, twenty_three, NONE, SLOPPY).Check(); |
316 } | 313 } |
317 | 314 |
318 // After gc, it should survive. | 315 // After gc, it should survive. |
319 heap->CollectGarbage(NEW_SPACE); | 316 heap->CollectGarbage(NEW_SPACE); |
320 | 317 |
321 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); | 318 CHECK(JSReceiver::HasLocalProperty(global, obj_name)); |
322 Handle<Object> obj = | 319 Handle<Object> obj = Object::GetProperty(global, obj_name); |
323 Object::GetProperty(global, obj_name).ToHandleChecked(); | |
324 CHECK(obj->IsJSObject()); | 320 CHECK(obj->IsJSObject()); |
325 CHECK_EQ(Smi::FromInt(23), | 321 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name)); |
326 *Object::GetProperty(obj, prop_name).ToHandleChecked()); | |
327 } | 322 } |
328 | 323 |
329 | 324 |
330 static void VerifyStringAllocation(Isolate* isolate, const char* string) { | 325 static void VerifyStringAllocation(Isolate* isolate, const char* string) { |
331 HandleScope scope(isolate); | 326 HandleScope scope(isolate); |
332 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string)); | 327 Handle<String> s = isolate->factory()->NewStringFromUtf8(CStrVector(string)); |
333 CHECK_EQ(StrLength(string), s->length()); | 328 CHECK_EQ(StrLength(string), s->length()); |
334 for (int index = 0; index < s->length(); index++) { | 329 for (int index = 0; index < s->length(); index++) { |
335 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); | 330 CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index)); |
336 } | 331 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 Handle<Map> initial_map = | 635 Handle<Map> initial_map = |
641 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 636 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
642 function->set_initial_map(*initial_map); | 637 function->set_initial_map(*initial_map); |
643 | 638 |
644 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 639 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
645 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); | 640 Handle<Smi> twenty_four(Smi::FromInt(24), isolate); |
646 | 641 |
647 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 642 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
648 Handle<JSObject> obj = factory->NewJSObject(function); | 643 Handle<JSObject> obj = factory->NewJSObject(function); |
649 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); | 644 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); |
650 CHECK_EQ(Smi::FromInt(23), | 645 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name)); |
651 *Object::GetProperty(obj, prop_name).ToHandleChecked()); | |
652 // Check that we can add properties to function objects. | 646 // Check that we can add properties to function objects. |
653 JSReceiver::SetProperty( | 647 JSReceiver::SetProperty( |
654 function, prop_name, twenty_four, NONE, SLOPPY).Check(); | 648 function, prop_name, twenty_four, NONE, SLOPPY).Check(); |
655 CHECK_EQ(Smi::FromInt(24), | 649 CHECK_EQ(Smi::FromInt(24), *Object::GetProperty(function, prop_name)); |
656 *Object::GetProperty(function, prop_name).ToHandleChecked()); | |
657 } | 650 } |
658 | 651 |
659 | 652 |
660 TEST(ObjectProperties) { | 653 TEST(ObjectProperties) { |
661 CcTest::InitializeVM(); | 654 CcTest::InitializeVM(); |
662 Isolate* isolate = CcTest::i_isolate(); | 655 Isolate* isolate = CcTest::i_isolate(); |
663 Factory* factory = isolate->factory(); | 656 Factory* factory = isolate->factory(); |
664 | 657 |
665 v8::HandleScope sc(CcTest::isolate()); | 658 v8::HandleScope sc(CcTest::isolate()); |
666 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); | 659 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); |
667 Handle<Object> object = Object::GetProperty( | 660 Handle<Object> object = |
668 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); | 661 Object::GetProperty(CcTest::i_isolate()->global_object(), object_string); |
669 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); | 662 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); |
670 Handle<JSObject> obj = factory->NewJSObject(constructor); | 663 Handle<JSObject> obj = factory->NewJSObject(constructor); |
671 Handle<String> first = factory->InternalizeUtf8String("first"); | 664 Handle<String> first = factory->InternalizeUtf8String("first"); |
672 Handle<String> second = factory->InternalizeUtf8String("second"); | 665 Handle<String> second = factory->InternalizeUtf8String("second"); |
673 | 666 |
674 Handle<Smi> one(Smi::FromInt(1), isolate); | 667 Handle<Smi> one(Smi::FromInt(1), isolate); |
675 Handle<Smi> two(Smi::FromInt(2), isolate); | 668 Handle<Smi> two(Smi::FromInt(2), isolate); |
676 | 669 |
677 // check for empty | 670 // check for empty |
678 CHECK(!JSReceiver::HasLocalProperty(obj, first)); | 671 CHECK(!JSReceiver::HasLocalProperty(obj, first)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 Handle<Map> initial_map = | 732 Handle<Map> initial_map = |
740 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 733 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
741 function->set_initial_map(*initial_map); | 734 function->set_initial_map(*initial_map); |
742 | 735 |
743 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); | 736 Handle<String> prop_name = factory->InternalizeUtf8String("theSlot"); |
744 Handle<JSObject> obj = factory->NewJSObject(function); | 737 Handle<JSObject> obj = factory->NewJSObject(function); |
745 | 738 |
746 // Set a propery | 739 // Set a propery |
747 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); | 740 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); |
748 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); | 741 JSReceiver::SetProperty(obj, prop_name, twenty_three, NONE, SLOPPY).Check(); |
749 CHECK_EQ(Smi::FromInt(23), | 742 CHECK_EQ(Smi::FromInt(23), *Object::GetProperty(obj, prop_name)); |
750 *Object::GetProperty(obj, prop_name).ToHandleChecked()); | |
751 | 743 |
752 // Check the map has changed | 744 // Check the map has changed |
753 CHECK(*initial_map != obj->map()); | 745 CHECK(*initial_map != obj->map()); |
754 } | 746 } |
755 | 747 |
756 | 748 |
757 TEST(JSArray) { | 749 TEST(JSArray) { |
758 CcTest::InitializeVM(); | 750 CcTest::InitializeVM(); |
759 Isolate* isolate = CcTest::i_isolate(); | 751 Isolate* isolate = CcTest::i_isolate(); |
760 Factory* factory = isolate->factory(); | 752 Factory* factory = isolate->factory(); |
761 | 753 |
762 v8::HandleScope sc(CcTest::isolate()); | 754 v8::HandleScope sc(CcTest::isolate()); |
763 Handle<String> name = factory->InternalizeUtf8String("Array"); | 755 Handle<String> name = factory->InternalizeUtf8String("Array"); |
764 Handle<Object> fun_obj = Object::GetProperty( | 756 Handle<Object> fun_obj = |
765 CcTest::i_isolate()->global_object(), name).ToHandleChecked(); | 757 Object::GetProperty(CcTest::i_isolate()->global_object(), name); |
766 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj); | 758 Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj); |
767 | 759 |
768 // Allocate the object. | 760 // Allocate the object. |
769 Handle<JSObject> object = factory->NewJSObject(function); | 761 Handle<JSObject> object = factory->NewJSObject(function); |
770 Handle<JSArray> array = Handle<JSArray>::cast(object); | 762 Handle<JSArray> array = Handle<JSArray>::cast(object); |
771 // We just initialized the VM, no heap allocation failure yet. | 763 // We just initialized the VM, no heap allocation failure yet. |
772 JSArray::Initialize(array, 0); | 764 JSArray::Initialize(array, 0); |
773 | 765 |
774 // Set array length to 0. | 766 // Set array length to 0. |
775 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); | 767 JSArray::SetElementsLength(array, handle(Smi::FromInt(0), isolate)).Check(); |
(...skipping 27 matching lines...) Expand all Loading... |
803 } | 795 } |
804 | 796 |
805 | 797 |
806 TEST(JSObjectCopy) { | 798 TEST(JSObjectCopy) { |
807 CcTest::InitializeVM(); | 799 CcTest::InitializeVM(); |
808 Isolate* isolate = CcTest::i_isolate(); | 800 Isolate* isolate = CcTest::i_isolate(); |
809 Factory* factory = isolate->factory(); | 801 Factory* factory = isolate->factory(); |
810 | 802 |
811 v8::HandleScope sc(CcTest::isolate()); | 803 v8::HandleScope sc(CcTest::isolate()); |
812 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); | 804 Handle<String> object_string(String::cast(CcTest::heap()->Object_string())); |
813 Handle<Object> object = Object::GetProperty( | 805 Handle<Object> object = |
814 CcTest::i_isolate()->global_object(), object_string).ToHandleChecked(); | 806 Object::GetProperty(CcTest::i_isolate()->global_object(), object_string); |
815 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); | 807 Handle<JSFunction> constructor = Handle<JSFunction>::cast(object); |
816 Handle<JSObject> obj = factory->NewJSObject(constructor); | 808 Handle<JSObject> obj = factory->NewJSObject(constructor); |
817 Handle<String> first = factory->InternalizeUtf8String("first"); | 809 Handle<String> first = factory->InternalizeUtf8String("first"); |
818 Handle<String> second = factory->InternalizeUtf8String("second"); | 810 Handle<String> second = factory->InternalizeUtf8String("second"); |
819 | 811 |
820 Handle<Smi> one(Smi::FromInt(1), isolate); | 812 Handle<Smi> one(Smi::FromInt(1), isolate); |
821 Handle<Smi> two(Smi::FromInt(2), isolate); | 813 Handle<Smi> two(Smi::FromInt(2), isolate); |
822 | 814 |
823 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); | 815 JSReceiver::SetProperty(obj, first, one, NONE, SLOPPY).Check(); |
824 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); | 816 JSReceiver::SetProperty(obj, second, two, NONE, SLOPPY).Check(); |
825 | 817 |
826 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); | 818 JSReceiver::SetElement(obj, 0, first, NONE, SLOPPY).Check(); |
827 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); | 819 JSReceiver::SetElement(obj, 1, second, NONE, SLOPPY).Check(); |
828 | 820 |
829 // Make the clone. | 821 // Make the clone. |
830 Handle<JSObject> clone = JSObject::Copy(obj); | 822 Handle<JSObject> clone = JSObject::Copy(obj); |
831 CHECK(!clone.is_identical_to(obj)); | 823 CHECK(!clone.is_identical_to(obj)); |
832 | 824 |
833 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), | 825 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), |
834 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); | 826 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); |
835 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), | 827 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), |
836 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); | 828 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); |
837 | 829 |
838 CHECK_EQ(*Object::GetProperty(obj, first).ToHandleChecked(), | 830 CHECK_EQ(*Object::GetProperty(obj, first), |
839 *Object::GetProperty(clone, first).ToHandleChecked()); | 831 *Object::GetProperty(clone, first)); |
840 CHECK_EQ(*Object::GetProperty(obj, second).ToHandleChecked(), | 832 CHECK_EQ(*Object::GetProperty(obj, second), |
841 *Object::GetProperty(clone, second).ToHandleChecked()); | 833 *Object::GetProperty(clone, second)); |
842 | 834 |
843 // Flip the values. | 835 // Flip the values. |
844 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); | 836 JSReceiver::SetProperty(clone, first, two, NONE, SLOPPY).Check(); |
845 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); | 837 JSReceiver::SetProperty(clone, second, one, NONE, SLOPPY).Check(); |
846 | 838 |
847 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); | 839 JSReceiver::SetElement(clone, 0, second, NONE, SLOPPY).Check(); |
848 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); | 840 JSReceiver::SetElement(clone, 1, first, NONE, SLOPPY).Check(); |
849 | 841 |
850 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), | 842 CHECK_EQ(*i::Object::GetElement(isolate, obj, 1).ToHandleChecked(), |
851 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); | 843 *i::Object::GetElement(isolate, clone, 0).ToHandleChecked()); |
852 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), | 844 CHECK_EQ(*i::Object::GetElement(isolate, obj, 0).ToHandleChecked(), |
853 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); | 845 *i::Object::GetElement(isolate, clone, 1).ToHandleChecked()); |
854 | 846 |
855 CHECK_EQ(*Object::GetProperty(obj, second).ToHandleChecked(), | 847 CHECK_EQ(*Object::GetProperty(obj, second), |
856 *Object::GetProperty(clone, first).ToHandleChecked()); | 848 *Object::GetProperty(clone, first)); |
857 CHECK_EQ(*Object::GetProperty(obj, first).ToHandleChecked(), | 849 CHECK_EQ(*Object::GetProperty(obj, first), |
858 *Object::GetProperty(clone, second).ToHandleChecked()); | 850 *Object::GetProperty(clone, second)); |
859 } | 851 } |
860 | 852 |
861 | 853 |
862 TEST(StringAllocation) { | 854 TEST(StringAllocation) { |
863 CcTest::InitializeVM(); | 855 CcTest::InitializeVM(); |
864 Isolate* isolate = CcTest::i_isolate(); | 856 Isolate* isolate = CcTest::i_isolate(); |
865 Factory* factory = isolate->factory(); | 857 Factory* factory = isolate->factory(); |
866 | 858 |
867 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; | 859 const unsigned char chars[] = { 0xe5, 0xa4, 0xa7 }; |
868 for (int length = 0; length < 100; length++) { | 860 for (int length = 0; length < 100; length++) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 "};" | 1059 "};" |
1068 "foo()"; | 1060 "foo()"; |
1069 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); | 1061 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); |
1070 | 1062 |
1071 // This compile will add the code to the compilation cache. | 1063 // This compile will add the code to the compilation cache. |
1072 { v8::HandleScope scope(CcTest::isolate()); | 1064 { v8::HandleScope scope(CcTest::isolate()); |
1073 CompileRun(source); | 1065 CompileRun(source); |
1074 } | 1066 } |
1075 | 1067 |
1076 // Check function is compiled. | 1068 // Check function is compiled. |
1077 Handle<Object> func_value = Object::GetProperty( | 1069 Handle<Object> func_value = |
1078 CcTest::i_isolate()->global_object(), foo_name).ToHandleChecked(); | 1070 Object::GetProperty(CcTest::i_isolate()->global_object(), foo_name); |
1079 CHECK(func_value->IsJSFunction()); | 1071 CHECK(func_value->IsJSFunction()); |
1080 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 1072 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
1081 CHECK(function->shared()->is_compiled()); | 1073 CHECK(function->shared()->is_compiled()); |
1082 | 1074 |
1083 // The code will survive at least two GCs. | 1075 // The code will survive at least two GCs. |
1084 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1076 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1085 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1077 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1086 CHECK(function->shared()->is_compiled()); | 1078 CHECK(function->shared()->is_compiled()); |
1087 | 1079 |
1088 // Simulate several GCs that use full marking. | 1080 // Simulate several GCs that use full marking. |
(...skipping 29 matching lines...) Expand all Loading... |
1118 "foo()"; | 1110 "foo()"; |
1119 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); | 1111 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); |
1120 | 1112 |
1121 // Compile foo, but don't run it. | 1113 // Compile foo, but don't run it. |
1122 { v8::HandleScope scope(CcTest::isolate()); | 1114 { v8::HandleScope scope(CcTest::isolate()); |
1123 CompileRun(source); | 1115 CompileRun(source); |
1124 } | 1116 } |
1125 | 1117 |
1126 // Check function is compiled. | 1118 // Check function is compiled. |
1127 Handle<Object> func_value = | 1119 Handle<Object> func_value = |
1128 Object::GetProperty(isolate->global_object(), foo_name).ToHandleChecked(); | 1120 Object::GetProperty(isolate->global_object(), foo_name); |
1129 CHECK(func_value->IsJSFunction()); | 1121 CHECK(func_value->IsJSFunction()); |
1130 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 1122 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
1131 CHECK(function->shared()->is_compiled()); | 1123 CHECK(function->shared()->is_compiled()); |
1132 | 1124 |
1133 // The code has been run so will survive at least one GC. | 1125 // The code has been run so will survive at least one GC. |
1134 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1126 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1135 CHECK(function->shared()->is_compiled()); | 1127 CHECK(function->shared()->is_compiled()); |
1136 | 1128 |
1137 // The code was only run once, so it should be pre-aged and collected on the | 1129 // The code was only run once, so it should be pre-aged and collected on the |
1138 // next GC. | 1130 // next GC. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 "foo()"; | 1175 "foo()"; |
1184 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); | 1176 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); |
1185 | 1177 |
1186 // This compile will add the code to the compilation cache. | 1178 // This compile will add the code to the compilation cache. |
1187 { v8::HandleScope scope(CcTest::isolate()); | 1179 { v8::HandleScope scope(CcTest::isolate()); |
1188 CompileRun(source); | 1180 CompileRun(source); |
1189 } | 1181 } |
1190 | 1182 |
1191 // Check function is compiled. | 1183 // Check function is compiled. |
1192 Handle<Object> func_value = | 1184 Handle<Object> func_value = |
1193 Object::GetProperty(isolate->global_object(), foo_name).ToHandleChecked(); | 1185 Object::GetProperty(isolate->global_object(), foo_name); |
1194 CHECK(func_value->IsJSFunction()); | 1186 CHECK(func_value->IsJSFunction()); |
1195 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 1187 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
1196 CHECK(function->shared()->is_compiled()); | 1188 CHECK(function->shared()->is_compiled()); |
1197 | 1189 |
1198 // The code will survive at least two GCs. | 1190 // The code will survive at least two GCs. |
1199 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1191 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1200 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1192 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1201 CHECK(function->shared()->is_compiled()); | 1193 CHECK(function->shared()->is_compiled()); |
1202 | 1194 |
1203 // Simulate several GCs that use incremental marking. | 1195 // Simulate several GCs that use incremental marking. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 // Perfrom one initial GC to enable code flushing. | 1252 // Perfrom one initial GC to enable code flushing. |
1261 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1253 CcTest::heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1262 | 1254 |
1263 // This compile will add the code to the compilation cache. | 1255 // This compile will add the code to the compilation cache. |
1264 { v8::HandleScope scope(CcTest::isolate()); | 1256 { v8::HandleScope scope(CcTest::isolate()); |
1265 CompileRun(source); | 1257 CompileRun(source); |
1266 } | 1258 } |
1267 | 1259 |
1268 // Check functions are compiled. | 1260 // Check functions are compiled. |
1269 Handle<Object> func_value = | 1261 Handle<Object> func_value = |
1270 Object::GetProperty(isolate->global_object(), foo_name).ToHandleChecked(); | 1262 Object::GetProperty(isolate->global_object(), foo_name); |
1271 CHECK(func_value->IsJSFunction()); | 1263 CHECK(func_value->IsJSFunction()); |
1272 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 1264 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
1273 CHECK(function->shared()->is_compiled()); | 1265 CHECK(function->shared()->is_compiled()); |
1274 Handle<Object> func_value2 = | 1266 Handle<Object> func_value2 = |
1275 Object::GetProperty(isolate->global_object(), bar_name).ToHandleChecked(); | 1267 Object::GetProperty(isolate->global_object(), bar_name); |
1276 CHECK(func_value2->IsJSFunction()); | 1268 CHECK(func_value2->IsJSFunction()); |
1277 Handle<JSFunction> function2 = Handle<JSFunction>::cast(func_value2); | 1269 Handle<JSFunction> function2 = Handle<JSFunction>::cast(func_value2); |
1278 CHECK(function2->shared()->is_compiled()); | 1270 CHECK(function2->shared()->is_compiled()); |
1279 | 1271 |
1280 // Clear references to functions so that one of them can die. | 1272 // Clear references to functions so that one of them can die. |
1281 { v8::HandleScope scope(CcTest::isolate()); | 1273 { v8::HandleScope scope(CcTest::isolate()); |
1282 CompileRun("foo = 0; bar = 0;"); | 1274 CompileRun("foo = 0; bar = 0;"); |
1283 } | 1275 } |
1284 | 1276 |
1285 // Bump the code age so that flushing is triggered while the function | 1277 // Bump the code age so that flushing is triggered while the function |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 "foo()"; | 1314 "foo()"; |
1323 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); | 1315 Handle<String> foo_name = factory->InternalizeUtf8String("foo"); |
1324 | 1316 |
1325 // This compile will add the code to the compilation cache. | 1317 // This compile will add the code to the compilation cache. |
1326 { v8::HandleScope scope(CcTest::isolate()); | 1318 { v8::HandleScope scope(CcTest::isolate()); |
1327 CompileRun(source); | 1319 CompileRun(source); |
1328 } | 1320 } |
1329 | 1321 |
1330 // Check function is compiled. | 1322 // Check function is compiled. |
1331 Handle<Object> func_value = | 1323 Handle<Object> func_value = |
1332 Object::GetProperty(isolate->global_object(), foo_name).ToHandleChecked(); | 1324 Object::GetProperty(isolate->global_object(), foo_name); |
1333 CHECK(func_value->IsJSFunction()); | 1325 CHECK(func_value->IsJSFunction()); |
1334 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); | 1326 Handle<JSFunction> function = Handle<JSFunction>::cast(func_value); |
1335 CHECK(function->shared()->is_compiled()); | 1327 CHECK(function->shared()->is_compiled()); |
1336 | 1328 |
1337 // The code will survive at least two GCs. | 1329 // The code will survive at least two GCs. |
1338 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1330 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1339 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 1331 heap->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
1340 CHECK(function->shared()->is_compiled()); | 1332 CHECK(function->shared()->is_compiled()); |
1341 | 1333 |
1342 // Bump the code age so that flushing is triggered. | 1334 // Bump the code age so that flushing is triggered. |
(...skipping 2705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4048 v8::Context::Scope cscope(context); | 4040 v8::Context::Scope cscope(context); |
4049 | 4041 |
4050 v8::Local<v8::Value> result = CompileRun( | 4042 v8::Local<v8::Value> result = CompileRun( |
4051 "var locals = '';" | 4043 "var locals = '';" |
4052 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" | 4044 "for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';" |
4053 "eval('function f() {' + locals + 'return function() { return v0; }; }');" | 4045 "eval('function f() {' + locals + 'return function() { return v0; }; }');" |
4054 "interrupt();" // This triggers a fake stack overflow in f. | 4046 "interrupt();" // This triggers a fake stack overflow in f. |
4055 "f()()"); | 4047 "f()()"); |
4056 CHECK_EQ(42.0, result->ToNumber()->Value()); | 4048 CHECK_EQ(42.0, result->ToNumber()->Value()); |
4057 } | 4049 } |
OLD | NEW |