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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 1802 {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
1803 }; | 1803 }; |
1804 | 1804 |
1805 for (size_t i = 0; i < arraysize(snippets); i++) { | 1805 for (size_t i = 0; i < arraysize(snippets); i++) { |
1806 Handle<BytecodeArray> bytecode_array = | 1806 Handle<BytecodeArray> bytecode_array = |
1807 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1807 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
1808 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1808 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1809 } | 1809 } |
1810 } | 1810 } |
1811 | 1811 |
| 1812 |
| 1813 TEST(ArrayLiterals) { |
| 1814 InitializedHandleScope handle_scope; |
| 1815 BytecodeGeneratorHelper helper; |
| 1816 |
| 1817 int simple_flags = |
| 1818 ArrayLiteral::kDisableMementos | ArrayLiteral::kShallowElements; |
| 1819 int deep_elements_flags = ArrayLiteral::kDisableMementos; |
| 1820 ExpectedSnippet<InstanceType> snippets[] = { |
| 1821 {"return [ 1, 2 ];", |
| 1822 0, |
| 1823 1, |
| 1824 6, |
| 1825 { |
| 1826 B(LdaConstant), U8(0), // |
| 1827 B(CreateArrayLiteral), U8(0), U8(simple_flags), // |
| 1828 B(Return) // |
| 1829 }, |
| 1830 1, |
| 1831 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 1832 {"var a = 1; return [ a, a + 1 ];", |
| 1833 4 * kPointerSize, |
| 1834 1, |
| 1835 37, |
| 1836 { |
| 1837 B(LdaSmi8), U8(1), // |
| 1838 B(Star), R(0), // |
| 1839 B(LdaConstant), U8(0), // |
| 1840 B(CreateArrayLiteral), U8(0), U8(3), // |
| 1841 B(Star), R(2), // |
| 1842 B(LdaZero), // |
| 1843 B(Star), R(1), // |
| 1844 B(Ldar), R(0), // |
| 1845 B(KeyedStoreICGeneric), R(2), R(1), // |
| 1846 B(LdaSmi8), U8(1), // |
| 1847 B(Star), R(1), // |
| 1848 B(Ldar), R(0), // |
| 1849 B(Star), R(3), // |
| 1850 B(LdaSmi8), U8(1), // |
| 1851 B(Add), R(3), // |
| 1852 B(KeyedStoreICGeneric), R(2), R(1), // |
| 1853 B(Ldar), R(2), // |
| 1854 B(Return) // |
| 1855 }, |
| 1856 1, |
| 1857 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 1858 {"return [ [ 1, 2 ], [ 3 ] ];", |
| 1859 0, |
| 1860 1, |
| 1861 6, |
| 1862 { |
| 1863 B(LdaConstant), U8(0), // |
| 1864 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), // |
| 1865 B(Return) // |
| 1866 }, |
| 1867 1, |
| 1868 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 1869 {"var a = 1; return [ [ a, 2 ], [ a + 2 ] ];", |
| 1870 6 * kPointerSize, |
| 1871 1, |
| 1872 67, |
| 1873 { |
| 1874 B(LdaSmi8), U8(1), // |
| 1875 B(Star), R(0), // |
| 1876 B(LdaConstant), U8(0), // |
| 1877 B(CreateArrayLiteral), U8(2), U8(deep_elements_flags), // |
| 1878 B(Star), R(2), // |
| 1879 B(LdaZero), // |
| 1880 B(Star), R(1), // |
| 1881 B(LdaConstant), U8(1), // |
| 1882 B(CreateArrayLiteral), U8(0), U8(simple_flags), // |
| 1883 B(Star), R(4), // |
| 1884 B(LdaZero), // |
| 1885 B(Star), R(3), // |
| 1886 B(Ldar), R(0), // |
| 1887 B(KeyedStoreICGeneric), R(4), R(3), // |
| 1888 B(Ldar), R(4), // |
| 1889 B(KeyedStoreICGeneric), R(2), R(1), // |
| 1890 B(LdaSmi8), U8(1), // |
| 1891 B(Star), R(1), // |
| 1892 B(LdaConstant), U8(2), // |
| 1893 B(CreateArrayLiteral), U8(1), U8(simple_flags), // |
| 1894 B(Star), R(4), // |
| 1895 B(LdaZero), // |
| 1896 B(Star), R(3), // |
| 1897 B(Ldar), R(0), // |
| 1898 B(Star), R(5), // |
| 1899 B(LdaSmi8), U8(2), // |
| 1900 B(Add), R(5), // |
| 1901 B(KeyedStoreICGeneric), R(4), R(3), // |
| 1902 B(Ldar), R(4), // |
| 1903 B(KeyedStoreICGeneric), R(2), R(1), // |
| 1904 B(Ldar), R(2), // |
| 1905 B(Return), // |
| 1906 }, |
| 1907 3, |
| 1908 {InstanceType::FIXED_ARRAY_TYPE, InstanceType::FIXED_ARRAY_TYPE, |
| 1909 InstanceType::FIXED_ARRAY_TYPE}}, |
| 1910 }; |
| 1911 |
| 1912 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1913 Handle<BytecodeArray> bytecode_array = |
| 1914 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 1915 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1916 } |
| 1917 } |
| 1918 |
1812 } // namespace interpreter | 1919 } // namespace interpreter |
1813 } // namespace internal | 1920 } // namespace internal |
1814 } // namespace v8 | 1921 } // namespace v8 |
OLD | NEW |