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 // TODO(rmcilroy): Remove this define after this flag is turned on globally | 5 // TODO(rmcilroy): Remove this define after this flag is turned on globally |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 | 1208 |
1209 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" | 1209 #define FUNC_ARG "new (function Obj() { this.func = function() { return; }})()" |
1210 | 1210 |
1211 | 1211 |
1212 TEST(PropertyCall) { | 1212 TEST(PropertyCall) { |
1213 InitializedHandleScope handle_scope; | 1213 InitializedHandleScope handle_scope; |
1214 BytecodeGeneratorHelper helper; | 1214 BytecodeGeneratorHelper helper; |
1215 Zone zone; | 1215 Zone zone; |
1216 | 1216 |
1217 FeedbackVectorSpec feedback_spec(&zone); | 1217 FeedbackVectorSpec feedback_spec(&zone); |
1218 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 1218 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
1219 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 1219 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
1220 USE(slot1); | 1220 USE(slot1); |
1221 | 1221 |
1222 Handle<i::TypeFeedbackVector> vector = | 1222 Handle<i::TypeFeedbackVector> vector = |
1223 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1223 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
1224 | 1224 |
| 1225 // These are a hack used by the CallWide test below. |
| 1226 int wide_idx = vector->GetIndex(slot1) - 2; |
| 1227 |
1225 ExpectedSnippet<const char*> snippets[] = { | 1228 ExpectedSnippet<const char*> snippets[] = { |
1226 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", | 1229 {"function f(a) { return a.func(); }\nf(" FUNC_ARG ")", |
1227 2 * kPointerSize, | 1230 2 * kPointerSize, |
1228 2, | 1231 2, |
1229 15, | 1232 16, |
1230 { | 1233 { |
1231 B(Ldar), A(1, 2), // | 1234 B(Ldar), A(1, 2), // |
1232 B(Star), R(1), // | 1235 B(Star), R(1), // |
1233 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1236 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
1234 B(Star), R(0), // | 1237 B(Star), R(0), // |
1235 B(Call), R(0), R(1), U8(0), // | 1238 B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot1)), // |
1236 B(Return), // | 1239 B(Return), // |
1237 }, | 1240 }, |
1238 1, | 1241 1, |
1239 {"func"}}, | 1242 {"func"}}, |
1240 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", | 1243 {"function f(a, b, c) { return a.func(b, c); }\nf(" FUNC_ARG ", 1, 2)", |
1241 4 * kPointerSize, | 1244 4 * kPointerSize, |
1242 4, | 1245 4, |
1243 23, | 1246 24, |
1244 { | 1247 { |
1245 B(Ldar), A(1, 4), // | 1248 B(Ldar), A(1, 4), // |
1246 B(Star), R(1), // | 1249 B(Star), R(1), // |
1247 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1250 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
1248 B(Star), R(0), // | 1251 B(Star), R(0), // |
1249 B(Ldar), A(2, 4), // | 1252 B(Ldar), A(2, 4), // |
1250 B(Star), R(2), // | 1253 B(Star), R(2), // |
1251 B(Ldar), A(3, 4), // | 1254 B(Ldar), A(3, 4), // |
1252 B(Star), R(3), // | 1255 B(Star), R(3), // |
1253 B(Call), R(0), R(1), U8(2), // | 1256 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), // |
1254 B(Return) // | 1257 B(Return) // |
1255 }, | 1258 }, |
1256 1, | 1259 1, |
1257 {"func"}}, | 1260 {"func"}}, |
1258 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", | 1261 {"function f(a, b) { return a.func(b + b, b); }\nf(" FUNC_ARG ", 1)", |
1259 4 * kPointerSize, | 1262 4 * kPointerSize, |
1260 3, | 1263 3, |
1261 25, | 1264 26, |
1262 { | 1265 { |
1263 B(Ldar), A(1, 3), // | 1266 B(Ldar), A(1, 3), // |
1264 B(Star), R(1), // | 1267 B(Star), R(1), // |
1265 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // | 1268 B(LoadICSloppy), R(1), U8(0), U8(vector->GetIndex(slot2)), // |
1266 B(Star), R(0), // | 1269 B(Star), R(0), // |
1267 B(Ldar), A(2, 3), // | 1270 B(Ldar), A(2, 3), // |
1268 B(Add), A(2, 3), // | 1271 B(Add), A(2, 3), // |
1269 B(Star), R(2), // | 1272 B(Star), R(2), // |
1270 B(Ldar), A(2, 3), // | 1273 B(Ldar), A(2, 3), // |
1271 B(Star), R(3), // | 1274 B(Star), R(3), // |
1272 B(Call), R(0), R(1), U8(2), // | 1275 B(Call), R(0), R(1), U8(2), U8(vector->GetIndex(slot1)), // |
1273 B(Return), // | 1276 B(Return), // |
1274 }, | 1277 }, |
1275 1, | 1278 1, |
1276 {"func"}}}; | 1279 {"func"}}, |
| 1280 {"function f(a) {\n" |
| 1281 REPEAT_127(SPACE, " a.func;\n") |
| 1282 " return a.func(); }\nf(" FUNC_ARG ")", |
| 1283 2 * kPointerSize, |
| 1284 2, |
| 1285 528, |
| 1286 { |
| 1287 REPEAT_127(COMMA, // |
| 1288 B(LoadICSloppy), A(1, 2), U8(0), U8((wide_idx += 2))), // |
| 1289 B(Ldar), A(1, 2), // |
| 1290 B(Star), R(1), // |
| 1291 B(LoadICSloppyWide), R(1), U16(0), U16(wide_idx + 4), // |
| 1292 B(Star), R(0), // |
| 1293 B(CallWide), R(0), R(1), U16(0), U16(wide_idx + 2), // |
| 1294 B(Return), // |
| 1295 }, |
| 1296 1, |
| 1297 {"func"}}, |
| 1298 }; |
1277 for (size_t i = 0; i < arraysize(snippets); i++) { | 1299 for (size_t i = 0; i < arraysize(snippets); i++) { |
1278 Handle<BytecodeArray> bytecode_array = | 1300 Handle<BytecodeArray> bytecode_array = |
1279 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); | 1301 helper.MakeBytecode(snippets[i].code_snippet, helper.kFunctionName); |
1280 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1302 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1281 } | 1303 } |
1282 } | 1304 } |
1283 | 1305 |
1284 | 1306 |
1285 TEST(LoadGlobal) { | 1307 TEST(LoadGlobal) { |
1286 InitializedHandleScope handle_scope; | 1308 InitializedHandleScope handle_scope; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 } | 1505 } |
1484 } | 1506 } |
1485 | 1507 |
1486 | 1508 |
1487 TEST(CallGlobal) { | 1509 TEST(CallGlobal) { |
1488 InitializedHandleScope handle_scope; | 1510 InitializedHandleScope handle_scope; |
1489 BytecodeGeneratorHelper helper; | 1511 BytecodeGeneratorHelper helper; |
1490 Zone zone; | 1512 Zone zone; |
1491 | 1513 |
1492 FeedbackVectorSpec feedback_spec(&zone); | 1514 FeedbackVectorSpec feedback_spec(&zone); |
1493 FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); | 1515 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
1494 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 1516 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
1495 USE(slot1); | 1517 USE(slot1); |
1496 | 1518 |
1497 Handle<i::TypeFeedbackVector> vector = | 1519 Handle<i::TypeFeedbackVector> vector = |
1498 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 1520 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
1499 | 1521 |
1500 ExpectedSnippet<const char*> snippets[] = { | 1522 ExpectedSnippet<const char*> snippets[] = { |
1501 {"function t() { }\nfunction f() { return t(); }\nf()", | 1523 {"function t() { }\nfunction f() { return t(); }\nf()", |
1502 2 * kPointerSize, | 1524 2 * kPointerSize, |
1503 1, | 1525 1, |
1504 13, | 1526 14, |
1505 { | 1527 { |
1506 B(LdaUndefined), // | 1528 B(LdaUndefined), // |
1507 B(Star), R(1), // | 1529 B(Star), R(1), // |
1508 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 1530 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
1509 B(Star), R(0), // | 1531 B(Star), R(0), // |
1510 B(Call), R(0), R(1), U8(0), // | 1532 B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot1)), // |
1511 B(Return) // | 1533 B(Return) // |
1512 }, | 1534 }, |
1513 1, | 1535 1, |
1514 {"t"}}, | 1536 {"t"}}, |
1515 {"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", | 1537 {"function t(a, b, c) { }\nfunction f() { return t(1, 2, 3); }\nf()", |
1516 5 * kPointerSize, | 1538 5 * kPointerSize, |
1517 1, | 1539 1, |
1518 25, | 1540 26, |
1519 { | 1541 { |
1520 B(LdaUndefined), // | 1542 B(LdaUndefined), // |
1521 B(Star), R(1), // | 1543 B(Star), R(1), // |
1522 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // | 1544 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot2)), // |
1523 B(Star), R(0), // | 1545 B(Star), R(0), // |
1524 B(LdaSmi8), U8(1), // | 1546 B(LdaSmi8), U8(1), // |
1525 B(Star), R(2), // | 1547 B(Star), R(2), // |
1526 B(LdaSmi8), U8(2), // | 1548 B(LdaSmi8), U8(2), // |
1527 B(Star), R(3), // | 1549 B(Star), R(3), // |
1528 B(LdaSmi8), U8(3), // | 1550 B(LdaSmi8), U8(3), // |
1529 B(Star), R(4), // | 1551 B(Star), R(4), // |
1530 B(Call), R(0), R(1), U8(3), // | 1552 B(Call), R(0), R(1), U8(3), U8(vector->GetIndex(slot1)), // |
1531 B(Return) // | 1553 B(Return) // |
1532 }, | 1554 }, |
1533 1, | 1555 1, |
1534 {"t"}}, | 1556 {"t"}}, |
1535 }; | 1557 }; |
1536 | 1558 |
1537 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | 1559 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); |
1538 for (size_t i = 0; i < num_snippets; i++) { | 1560 for (size_t i = 0; i < num_snippets; i++) { |
1539 Handle<BytecodeArray> bytecode_array = | 1561 Handle<BytecodeArray> bytecode_array = |
1540 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 1562 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
1541 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1563 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 FeedbackVectorSpec feedback_spec_stores(&zone); | 1876 FeedbackVectorSpec feedback_spec_stores(&zone); |
1855 FeedbackVectorSlot store_slot_1 = feedback_spec_stores.AddStoreICSlot(); | 1877 FeedbackVectorSlot store_slot_1 = feedback_spec_stores.AddStoreICSlot(); |
1856 FeedbackVectorSlot store_slot_2 = feedback_spec_stores.AddStoreICSlot(); | 1878 FeedbackVectorSlot store_slot_2 = feedback_spec_stores.AddStoreICSlot(); |
1857 USE(store_slot_1); | 1879 USE(store_slot_1); |
1858 | 1880 |
1859 Handle<i::TypeFeedbackVector> store_vector = | 1881 Handle<i::TypeFeedbackVector> store_vector = |
1860 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_stores); | 1882 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_stores); |
1861 | 1883 |
1862 FeedbackVectorSpec feedback_spec_loads(&zone); | 1884 FeedbackVectorSpec feedback_spec_loads(&zone); |
1863 FeedbackVectorSlot load_slot_1 = feedback_spec_loads.AddLoadICSlot(); | 1885 FeedbackVectorSlot load_slot_1 = feedback_spec_loads.AddLoadICSlot(); |
| 1886 FeedbackVectorSlot call_slot_1 = feedback_spec_loads.AddCallICSlot(); |
1864 | 1887 |
1865 Handle<i::TypeFeedbackVector> load_vector = | 1888 Handle<i::TypeFeedbackVector> load_vector = |
1866 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_loads); | 1889 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec_loads); |
1867 | 1890 |
1868 ExpectedSnippet<InstanceType> snippets[] = { | 1891 ExpectedSnippet<InstanceType> snippets[] = { |
1869 {"var a = 1;", | 1892 {"var a = 1;", |
1870 4 * kPointerSize, | 1893 4 * kPointerSize, |
1871 1, | 1894 1, |
1872 30, | 1895 30, |
1873 { | 1896 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 B(Star), R(0), // | 1950 B(Star), R(0), // |
1928 B(Ldar), R(0), // | 1951 B(Ldar), R(0), // |
1929 B(Return) // | 1952 B(Return) // |
1930 }, | 1953 }, |
1931 2, | 1954 2, |
1932 {InstanceType::FIXED_ARRAY_TYPE, | 1955 {InstanceType::FIXED_ARRAY_TYPE, |
1933 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 1956 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
1934 {"function f() {}\nf();", | 1957 {"function f() {}\nf();", |
1935 3 * kPointerSize, | 1958 3 * kPointerSize, |
1936 1, | 1959 1, |
1937 29, | 1960 30, |
1938 { | 1961 { |
1939 B(LdaConstant), U8(0), // | 1962 B(LdaConstant), U8(0), // |
1940 B(Star), R(1), // | 1963 B(Star), R(1), // |
1941 B(LdaZero), // | 1964 B(LdaZero), // |
1942 B(Star), R(2), // | 1965 B(Star), R(2), // |
1943 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // | 1966 B(CallRuntime), U16(Runtime::kDeclareGlobals), R(1), U8(2), // |
1944 B(LdaUndefined), // | 1967 B(LdaUndefined), // |
1945 B(Star), R(2), // | 1968 B(Star), R(2), // |
1946 B(LdaGlobalSloppy), U8(1), // | 1969 B(LdaGlobalSloppy), U8(1), // |
1947 U8(load_vector->GetIndex(load_slot_1)), // | 1970 U8(load_vector->GetIndex(load_slot_1)), // |
1948 B(Star), R(1), // | 1971 B(Star), R(1), // |
1949 B(Call), R(1), R(2), U8(0), // | 1972 B(Call), R(1), R(2), U8(0), // |
1950 B(Star), R(0), // | 1973 U8(load_vector->GetIndex(call_slot_1)), // |
1951 B(Ldar), R(0), // | 1974 B(Star), R(0), // |
1952 B(Return) // | 1975 B(Ldar), R(0), // |
| 1976 B(Return) // |
1953 }, | 1977 }, |
1954 2, | 1978 2, |
1955 {InstanceType::FIXED_ARRAY_TYPE, | 1979 {InstanceType::FIXED_ARRAY_TYPE, |
1956 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | 1980 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
1957 }; | 1981 }; |
1958 | 1982 |
1959 for (size_t i = 0; i < arraysize(snippets); i++) { | 1983 for (size_t i = 0; i < arraysize(snippets); i++) { |
1960 Handle<BytecodeArray> bytecode_array = | 1984 Handle<BytecodeArray> bytecode_array = |
1961 helper.MakeTopLevelBytecode(snippets[i].code_snippet); | 1985 helper.MakeTopLevelBytecode(snippets[i].code_snippet); |
1962 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1986 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 Handle<BytecodeArray> bytecode_array = | 2794 Handle<BytecodeArray> bytecode_array = |
2771 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 2795 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
2772 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2796 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2773 } | 2797 } |
2774 } | 2798 } |
2775 | 2799 |
2776 | 2800 |
2777 TEST(FunctionLiterals) { | 2801 TEST(FunctionLiterals) { |
2778 InitializedHandleScope handle_scope; | 2802 InitializedHandleScope handle_scope; |
2779 BytecodeGeneratorHelper helper; | 2803 BytecodeGeneratorHelper helper; |
| 2804 Zone zone; |
| 2805 |
| 2806 FeedbackVectorSpec feedback_spec(&zone); |
| 2807 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); |
| 2808 |
| 2809 Handle<i::TypeFeedbackVector> vector = |
| 2810 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
2780 | 2811 |
2781 ExpectedSnippet<InstanceType> snippets[] = { | 2812 ExpectedSnippet<InstanceType> snippets[] = { |
2782 {"return function(){ }", | 2813 {"return function(){ }", |
2783 0, | 2814 0, |
2784 1, | 2815 1, |
2785 5, | 2816 5, |
2786 { | 2817 { |
2787 B(LdaConstant), U8(0), // | 2818 B(LdaConstant), U8(0), // |
2788 B(CreateClosure), U8(0), // | 2819 B(CreateClosure), U8(0), // |
2789 B(Return) // | 2820 B(Return) // |
2790 }, | 2821 }, |
2791 1, | 2822 1, |
2792 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2823 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
2793 {"return (function(){ })()", | 2824 {"return (function(){ })()", |
2794 2 * kPointerSize, | 2825 2 * kPointerSize, |
2795 1, | 2826 1, |
2796 14, | 2827 15, |
2797 { | 2828 { |
2798 B(LdaUndefined), // | 2829 B(LdaUndefined), // |
2799 B(Star), R(1), // | 2830 B(Star), R(1), // |
2800 B(LdaConstant), U8(0), // | 2831 B(LdaConstant), U8(0), // |
2801 B(CreateClosure), U8(0), // | 2832 B(CreateClosure), U8(0), // |
2802 B(Star), R(0), // | 2833 B(Star), R(0), // |
2803 B(Call), R(0), R(1), U8(0), // | 2834 B(Call), R(0), R(1), U8(0), U8(vector->GetIndex(slot)), // |
2804 B(Return) // | 2835 B(Return) // |
2805 }, | 2836 }, |
2806 1, | 2837 1, |
2807 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2838 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
2808 {"return (function(x){ return x; })(1)", | 2839 {"return (function(x){ return x; })(1)", |
2809 3 * kPointerSize, | 2840 3 * kPointerSize, |
2810 1, | 2841 1, |
2811 18, | 2842 19, |
2812 { | 2843 { |
2813 B(LdaUndefined), // | 2844 B(LdaUndefined), // |
2814 B(Star), R(1), // | 2845 B(Star), R(1), // |
2815 B(LdaConstant), U8(0), // | 2846 B(LdaConstant), U8(0), // |
2816 B(CreateClosure), U8(0), // | 2847 B(CreateClosure), U8(0), // |
2817 B(Star), R(0), // | 2848 B(Star), R(0), // |
2818 B(LdaSmi8), U8(1), // | 2849 B(LdaSmi8), U8(1), // |
2819 B(Star), R(2), // | 2850 B(Star), R(2), // |
2820 B(Call), R(0), R(1), U8(1), // | 2851 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot)), // |
2821 B(Return) // | 2852 B(Return) // |
2822 }, | 2853 }, |
2823 1, | 2854 1, |
2824 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 2855 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
2825 }; | 2856 }; |
2826 | 2857 |
2827 for (size_t i = 0; i < arraysize(snippets); i++) { | 2858 for (size_t i = 0; i < arraysize(snippets); i++) { |
2828 Handle<BytecodeArray> bytecode_array = | 2859 Handle<BytecodeArray> bytecode_array = |
2829 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2860 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2830 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2861 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2831 } | 2862 } |
2832 } | 2863 } |
2833 | 2864 |
2834 | 2865 |
2835 TEST(RegExpLiterals) { | 2866 TEST(RegExpLiterals) { |
2836 InitializedHandleScope handle_scope; | 2867 InitializedHandleScope handle_scope; |
2837 BytecodeGeneratorHelper helper; | 2868 BytecodeGeneratorHelper helper; |
2838 Zone zone; | 2869 Zone zone; |
2839 | 2870 |
2840 FeedbackVectorSpec feedback_spec(&zone); | 2871 FeedbackVectorSpec feedback_spec(&zone); |
2841 feedback_spec.AddLoadICSlot(); | 2872 FeedbackVectorSlot slot1 = feedback_spec.AddCallICSlot(); |
2842 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); | 2873 FeedbackVectorSlot slot2 = feedback_spec.AddLoadICSlot(); |
2843 | 2874 |
2844 Handle<i::TypeFeedbackVector> vector = | 2875 Handle<i::TypeFeedbackVector> vector = |
2845 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 2876 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
2846 | 2877 |
2847 ExpectedSnippet<const char*> snippets[] = { | 2878 ExpectedSnippet<const char*> snippets[] = { |
2848 {"return /ab+d/;", | 2879 {"return /ab+d/;", |
2849 1 * kPointerSize, | 2880 1 * kPointerSize, |
2850 1, | 2881 1, |
2851 10, | 2882 10, |
(...skipping 15 matching lines...) Expand all Loading... |
2867 B(Star), R(0), // | 2898 B(Star), R(0), // |
2868 B(LdaConstant), U8(1), // | 2899 B(LdaConstant), U8(1), // |
2869 B(CreateRegExpLiteral), U8(0), R(0), // | 2900 B(CreateRegExpLiteral), U8(0), R(0), // |
2870 B(Return), // | 2901 B(Return), // |
2871 }, | 2902 }, |
2872 2, | 2903 2, |
2873 {"i", "(\\w+)\\s(\\w+)"}}, | 2904 {"i", "(\\w+)\\s(\\w+)"}}, |
2874 {"return /ab+d/.exec('abdd');", | 2905 {"return /ab+d/.exec('abdd');", |
2875 3 * kPointerSize, | 2906 3 * kPointerSize, |
2876 1, | 2907 1, |
2877 26, | 2908 27, |
2878 { | 2909 { |
2879 B(LdaConstant), U8(0), // | 2910 B(LdaConstant), U8(0), // |
2880 B(Star), R(2), // | 2911 B(Star), R(2), // |
2881 B(LdaConstant), U8(1), // | 2912 B(LdaConstant), U8(1), // |
2882 B(CreateRegExpLiteral), U8(0), R(2), // | 2913 B(CreateRegExpLiteral), U8(0), R(2), // |
2883 B(Star), R(1), // | 2914 B(Star), R(1), // |
2884 B(LoadICSloppy), R(1), U8(2), U8(vector->GetIndex(slot2)), // | 2915 B(LoadICSloppy), R(1), U8(2), U8(vector->GetIndex(slot2)), // |
2885 B(Star), R(0), // | 2916 B(Star), R(0), // |
2886 B(LdaConstant), U8(3), // | 2917 B(LdaConstant), U8(3), // |
2887 B(Star), R(2), // | 2918 B(Star), R(2), // |
2888 B(Call), R(0), R(1), U8(1), // | 2919 B(Call), R(0), R(1), U8(1), U8(vector->GetIndex(slot1)), // |
2889 B(Return), // | 2920 B(Return), // |
2890 }, | 2921 }, |
2891 4, | 2922 4, |
2892 {"", "ab+d", "exec", "abdd"}}, | 2923 {"", "ab+d", "exec", "abdd"}}, |
2893 }; | 2924 }; |
2894 | 2925 |
2895 for (size_t i = 0; i < arraysize(snippets); i++) { | 2926 for (size_t i = 0; i < arraysize(snippets); i++) { |
2896 Handle<BytecodeArray> bytecode_array = | 2927 Handle<BytecodeArray> bytecode_array = |
2897 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2928 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2898 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2929 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3630 Handle<BytecodeArray> bytecode_array = | 3661 Handle<BytecodeArray> bytecode_array = |
3631 helper.MakeBytecode(snippets[i].code_snippet, "f"); | 3662 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
3632 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3663 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3633 } | 3664 } |
3634 } | 3665 } |
3635 | 3666 |
3636 | 3667 |
3637 TEST(ContextVariables) { | 3668 TEST(ContextVariables) { |
3638 InitializedHandleScope handle_scope; | 3669 InitializedHandleScope handle_scope; |
3639 BytecodeGeneratorHelper helper; | 3670 BytecodeGeneratorHelper helper; |
| 3671 Zone zone; |
| 3672 |
| 3673 FeedbackVectorSpec feedback_spec(&zone); |
| 3674 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); |
| 3675 |
| 3676 Handle<i::TypeFeedbackVector> vector = |
| 3677 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
3640 | 3678 |
3641 int closure = Register::function_closure().index(); | 3679 int closure = Register::function_closure().index(); |
3642 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 3680 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
3643 ExpectedSnippet<InstanceType> snippets[] = { | 3681 ExpectedSnippet<InstanceType> snippets[] = { |
3644 {"var a; return function() { a = 1; };", | 3682 {"var a; return function() { a = 1; };", |
3645 1 * kPointerSize, | 3683 1 * kPointerSize, |
3646 1, | 3684 1, |
3647 12, | 3685 12, |
3648 { | 3686 { |
3649 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 3687 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3685 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | 3723 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
3686 B(LdaConstant), U8(0), // | 3724 B(LdaConstant), U8(0), // |
3687 B(CreateClosure), U8(0), // | 3725 B(CreateClosure), U8(0), // |
3688 B(Return), // | 3726 B(Return), // |
3689 }, | 3727 }, |
3690 1, | 3728 1, |
3691 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3729 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
3692 {"var a; (function() { a = 2; })(); return a;", | 3730 {"var a; (function() { a = 2; })(); return a;", |
3693 3 * kPointerSize, | 3731 3 * kPointerSize, |
3694 1, | 3732 1, |
3695 24, | 3733 25, |
3696 { | 3734 { |
3697 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 3735 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
3698 R(closure), U8(1), // | 3736 R(closure), U8(1), // |
3699 B(PushContext), R(0), // | 3737 B(PushContext), R(0), // |
3700 B(LdaUndefined), // | 3738 B(LdaUndefined), // |
3701 B(Star), R(2), // | 3739 B(Star), R(2), // |
3702 B(LdaConstant), U8(0), // | 3740 B(LdaConstant), U8(0), // |
3703 B(CreateClosure), U8(0), // | 3741 B(CreateClosure), U8(0), // |
3704 B(Star), R(1), // | 3742 B(Star), R(1), // |
3705 B(Call), R(1), R(2), U8(0), // | 3743 B(Call), R(1), R(2), U8(0), U8(vector->GetIndex(slot)), // |
3706 B(LdaContextSlot), R(0), U8(first_context_slot), // | 3744 B(LdaContextSlot), R(0), U8(first_context_slot), // |
3707 B(Return), // | 3745 B(Return), // |
3708 }, | 3746 }, |
3709 1, | 3747 1, |
3710 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 3748 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
3711 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", | 3749 {"'use strict'; let a = 1; { let b = 2; return function() { a + b; }; }", |
3712 4 * kPointerSize, | 3750 4 * kPointerSize, |
3713 1, | 3751 1, |
3714 45, | 3752 45, |
3715 { | 3753 { |
3716 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 3754 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
3717 R(closure), U8(1), // | 3755 R(closure), U8(1), // |
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5210 for (size_t i = 0; i < arraysize(snippets); i++) { | 5248 for (size_t i = 0; i < arraysize(snippets); i++) { |
5211 Handle<BytecodeArray> bytecode_array = | 5249 Handle<BytecodeArray> bytecode_array = |
5212 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 5250 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
5213 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 5251 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
5214 } | 5252 } |
5215 } | 5253 } |
5216 | 5254 |
5217 } // namespace interpreter | 5255 } // namespace interpreter |
5218 } // namespace internal | 5256 } // namespace internal |
5219 } // namespace v8 | 5257 } // namespace v8 |
OLD | NEW |