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