OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <sstream> | 6 #include <sstream> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 CHECK(!IsObjectShrinkable(*obj)); | 717 CHECK(!IsObjectShrinkable(*obj)); |
718 | 718 |
719 // No slack left. | 719 // No slack left. |
720 CHECK_EQ(kMaxInobjectProperties, obj->map()->GetInObjectProperties()); | 720 CHECK_EQ(kMaxInobjectProperties, obj->map()->GetInObjectProperties()); |
721 } | 721 } |
722 | 722 |
723 // The other classes in the hierarchy are not affected. | 723 // The other classes in the hierarchy are not affected. |
724 TestClassHierarchy(hierarchy_desc, kNoOverflowCount); | 724 TestClassHierarchy(hierarchy_desc, kNoOverflowCount); |
725 } | 725 } |
726 | 726 |
| 727 static void CheckExpectedProperties(int expected, std::ostringstream& os) { |
| 728 Handle<HeapObject> obj = Handle<HeapObject>::cast( |
| 729 v8::Utils::OpenHandle(*CompileRun(os.str().c_str()))); |
| 730 CHECK_EQ(expected, obj->map()->GetInObjectProperties()); |
| 731 } |
| 732 |
| 733 TEST(ObjectLiteralPropertyBackingStoreSize) { |
| 734 v8::HandleScope scope(CcTest::isolate()); |
| 735 LocalContext env; |
| 736 |
| 737 std::ostringstream os; |
| 738 |
| 739 // An index key does not require space in the property backing store. |
| 740 os << "(function() {\n" |
| 741 " function f() {\n" |
| 742 " var o = {\n" |
| 743 " '-1': 42,\n" // Allocate for non-index key. |
| 744 " 1: 42,\n" // Do not allocate for index key. |
| 745 " '2': 42\n" // Do not allocate for index key. |
| 746 " };\n" |
| 747 " return o;\n" |
| 748 " }\n" |
| 749 "\n" |
| 750 " return f();\n" |
| 751 "} )();"; |
| 752 CheckExpectedProperties(1, os); |
| 753 |
| 754 // Avoid over-/under-allocation for computed property names. |
| 755 os << "(function() {\n" |
| 756 " function f(x) {\n" |
| 757 " var o = {\n" |
| 758 " 1: 42,\n" // Do not allocate for index key. |
| 759 " '2': 42,\n" // Do not allocate for index key. |
| 760 " [x]: 42,\n" // Allocate for property with computed name. |
| 761 " 3: 42\n" // Allocate for index key because we have seen a |
| 762 // computed property. |
| 763 " };\n" |
| 764 " return o;\n" |
| 765 " }\n" |
| 766 "\n" |
| 767 " var x = 'hello'\n" |
| 768 "\n" |
| 769 " return f(x);\n" |
| 770 "} )();"; |
| 771 CheckExpectedProperties(2, os); |
| 772 |
| 773 os << "(function() {\n" |
| 774 " function f() {\n" |
| 775 " var o = {};\n" |
| 776 " return o;\n" |
| 777 " }\n" |
| 778 "\n" |
| 779 " return f();\n" |
| 780 "} )();"; |
| 781 // Empty objects have slack for 4 properties. |
| 782 CheckExpectedProperties(4, os); |
| 783 |
| 784 os << "(function() {\n" |
| 785 " function f(x) {\n" |
| 786 " var o = {\n" |
| 787 " a: 42,\n" // Allocate for constant property. |
| 788 " [x]: 42,\n" // Allocate for property with computed name. |
| 789 " b: 42\n" // Allocate for constant property. |
| 790 " };\n" |
| 791 " return o;\n" |
| 792 " }\n" |
| 793 "\n" |
| 794 " var x = 'hello'\n" |
| 795 "\n" |
| 796 " return f(x);\n" |
| 797 "} )();"; |
| 798 CheckExpectedProperties(3, os); |
| 799 |
| 800 os << "(function() {\n" |
| 801 " function f(x) {\n" |
| 802 " var o = {\n" |
| 803 " a: 42,\n" // Allocate for constant property. |
| 804 " __proto__: 42,\n" // Do not allocate for __proto__. |
| 805 " [x]: 42\n" // Allocate for property with computed name. |
| 806 " };\n" |
| 807 " return o;\n" |
| 808 " }\n" |
| 809 "\n" |
| 810 " var x = 'hello'\n" |
| 811 "\n" |
| 812 " return f(x);\n" |
| 813 "} )();"; |
| 814 // __proto__ is not allocated in the backing store. |
| 815 CheckExpectedProperties(2, os); |
| 816 |
| 817 os << "(function() {\n" |
| 818 " function f(x) {\n" |
| 819 " var o = {\n" |
| 820 " a: 42,\n" // Allocate for constant property. |
| 821 " [x]: 42,\n" // Allocate for property with computed name. |
| 822 " __proto__: 42\n" // Do not allocate for __proto__. |
| 823 " };\n" |
| 824 " return o;\n" |
| 825 " }\n" |
| 826 "\n" |
| 827 " var x = 'hello'\n" |
| 828 "\n" |
| 829 " return f(x);\n" |
| 830 "} )();"; |
| 831 CheckExpectedProperties(2, os); |
| 832 } |
727 | 833 |
728 TEST(SlowModeSubclass) { | 834 TEST(SlowModeSubclass) { |
729 // Avoid eventual completion of in-object slack tracking. | 835 // Avoid eventual completion of in-object slack tracking. |
730 FLAG_inline_construct = false; | 836 FLAG_inline_construct = false; |
731 FLAG_always_opt = false; | 837 FLAG_always_opt = false; |
732 CcTest::InitializeVM(); | 838 CcTest::InitializeVM(); |
733 v8::HandleScope scope(CcTest::isolate()); | 839 v8::HandleScope scope(CcTest::isolate()); |
734 | 840 |
735 std::vector<int> hierarchy_desc; | 841 std::vector<int> hierarchy_desc; |
736 const int kNoOverflowCount = 5; | 842 const int kNoOverflowCount = 5; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1208 |
1103 TestSubclassBuiltin("A1", JS_PROMISE_TYPE, "Promise", | 1209 TestSubclassBuiltin("A1", JS_PROMISE_TYPE, "Promise", |
1104 "function(resolve, reject) { resolve('ok'); }"); | 1210 "function(resolve, reject) { resolve('ok'); }"); |
1105 } | 1211 } |
1106 | 1212 |
1107 | 1213 |
1108 TEST(SubclassPromiseBuiltinNoInlineNew) { | 1214 TEST(SubclassPromiseBuiltinNoInlineNew) { |
1109 FLAG_inline_new = false; | 1215 FLAG_inline_new = false; |
1110 TestSubclassPromiseBuiltin(); | 1216 TestSubclassPromiseBuiltin(); |
1111 } | 1217 } |
OLD | NEW |