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 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 1, | 1835 1, |
1836 8, | 1836 8, |
1837 { | 1837 { |
1838 B(LdaSmi8), U8(13), // | 1838 B(LdaSmi8), U8(13), // |
1839 B(Star), R(0), // TODO(oth): Ldar R(X) following Star R(X) | 1839 B(Star), R(0), // TODO(oth): Ldar R(X) following Star R(X) |
1840 B(Ldar), R(0), // could be culled in bytecode array builder. | 1840 B(Ldar), R(0), // could be culled in bytecode array builder. |
1841 B(TypeOf), // | 1841 B(TypeOf), // |
1842 B(Return), // | 1842 B(Return), // |
1843 }, | 1843 }, |
1844 0}, | 1844 0}, |
| 1845 {"var x = 13;" |
| 1846 "return ~x;", |
| 1847 1 * kPointerSize, |
| 1848 1, |
| 1849 9, |
| 1850 { |
| 1851 B(LdaSmi8), U8(13), // |
| 1852 B(Star), R(0), // |
| 1853 B(LdaSmi8), U8(-1), // |
| 1854 B(BitwiseXor), R(0), // |
| 1855 B(Return), // |
| 1856 }, |
| 1857 0}, |
| 1858 {"var x = 13;" |
| 1859 "return +x;", |
| 1860 1 * kPointerSize, |
| 1861 1, |
| 1862 9, |
| 1863 { |
| 1864 B(LdaSmi8), U8(13), // |
| 1865 B(Star), R(0), // |
| 1866 B(LdaSmi8), U8(1), // |
| 1867 B(Mul), R(0), // |
| 1868 B(Return), // |
| 1869 }, |
| 1870 0}, |
| 1871 {"var x = 13;" |
| 1872 "return -x;", |
| 1873 1 * kPointerSize, |
| 1874 1, |
| 1875 9, |
| 1876 { |
| 1877 B(LdaSmi8), U8(13), // |
| 1878 B(Star), R(0), // |
| 1879 B(LdaSmi8), U8(-1), // |
| 1880 B(Mul), R(0), // |
| 1881 B(Return), // |
| 1882 }, |
| 1883 0}}; |
| 1884 |
| 1885 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 1886 Handle<BytecodeArray> bytecode_array = |
| 1887 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 1888 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 1889 } |
| 1890 } |
| 1891 |
| 1892 |
| 1893 TEST(Delete) { |
| 1894 InitializedHandleScope handle_scope; |
| 1895 BytecodeGeneratorHelper helper; |
| 1896 |
| 1897 int deep_elements_flags = |
| 1898 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
| 1899 int closure = Register::function_closure().index(); |
| 1900 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 1901 |
| 1902 ExpectedSnippet<InstanceType> snippets[] = { |
| 1903 {"var a = {x:13, y:14}; return delete a.x;", |
| 1904 1 * kPointerSize, |
| 1905 1, |
| 1906 12, |
| 1907 { |
| 1908 B(LdaConstant), U8(0), // |
| 1909 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
| 1910 B(Star), R(0), // |
| 1911 B(LdaConstant), U8(1), // |
| 1912 B(DeletePropertySloppy), R(0), // |
| 1913 B(Return) |
| 1914 }, |
| 1915 2, |
| 1916 {InstanceType::FIXED_ARRAY_TYPE, |
| 1917 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 1918 {"'use strict'; var a = {x:13, y:14}; return delete a.x;", |
| 1919 1 * kPointerSize, |
| 1920 1, |
| 1921 12, |
| 1922 { |
| 1923 B(LdaConstant), U8(0), // |
| 1924 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
| 1925 B(Star), R(0), // |
| 1926 B(LdaConstant), U8(1), // |
| 1927 B(DeletePropertyStrict), R(0), // |
| 1928 B(Return) |
| 1929 }, |
| 1930 2, |
| 1931 {InstanceType::FIXED_ARRAY_TYPE, |
| 1932 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 1933 {"var a = {1:13, 2:14}; return delete a[2];", |
| 1934 1 * kPointerSize, |
| 1935 1, |
| 1936 12, |
| 1937 { |
| 1938 B(LdaConstant), U8(0), // |
| 1939 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
| 1940 B(Star), R(0), // |
| 1941 B(LdaSmi8), U8(2), // |
| 1942 B(DeletePropertySloppy), R(0), // |
| 1943 B(Return) |
| 1944 }, |
| 1945 1, |
| 1946 {InstanceType::FIXED_ARRAY_TYPE}}, |
| 1947 {"var a = 10; return delete a;", |
| 1948 1 * kPointerSize, |
| 1949 1, |
| 1950 6, |
| 1951 { |
| 1952 B(LdaSmi8), U8(10), // |
| 1953 B(Star), R(0), // |
| 1954 B(LdaFalse), // |
| 1955 B(Return) |
| 1956 }, |
| 1957 0}, |
| 1958 {"'use strict';" |
| 1959 "var a = {1:10};" |
| 1960 "(function f1() {return a;});" |
| 1961 "return delete a[1];", |
| 1962 2 * kPointerSize, |
| 1963 1, |
| 1964 29, |
| 1965 { |
| 1966 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 1967 R(closure), U8(1), // |
| 1968 B(PushContext), R(0), // |
| 1969 B(LdaConstant), U8(0), // |
| 1970 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), // |
| 1971 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 1972 B(LdaConstant), U8(1), // |
| 1973 B(CreateClosure), U8(0), // |
| 1974 B(LdaContextSlot), R(0), U8(first_context_slot), // |
| 1975 B(Star), R(1), // |
| 1976 B(LdaSmi8), U8(1), // |
| 1977 B(DeletePropertyStrict), R(1), // |
| 1978 B(Return) |
| 1979 }, |
| 1980 2, |
| 1981 {InstanceType::FIXED_ARRAY_TYPE, |
| 1982 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 1983 {"return delete 'test';", |
| 1984 0 * kPointerSize, |
| 1985 1, |
| 1986 2, |
| 1987 { |
| 1988 B(LdaTrue), // |
| 1989 B(Return) |
| 1990 }, |
| 1991 0}, |
1845 }; | 1992 }; |
1846 | 1993 |
1847 for (size_t i = 0; i < arraysize(snippets); i++) { | 1994 for (size_t i = 0; i < arraysize(snippets); i++) { |
1848 Handle<BytecodeArray> bytecode_array = | 1995 Handle<BytecodeArray> bytecode_array = |
1849 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 1996 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
1850 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 1997 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
1851 } | 1998 } |
1852 } | 1999 } |
1853 | 2000 |
1854 | 2001 |
| 2002 TEST(GlobalDelete) { |
| 2003 InitializedHandleScope handle_scope; |
| 2004 BytecodeGeneratorHelper helper; |
| 2005 Zone zone; |
| 2006 |
| 2007 int context = Register::function_context().index(); |
| 2008 int global_object_index = Context::GLOBAL_OBJECT_INDEX; |
| 2009 FeedbackVectorSpec feedback_spec(&zone); |
| 2010 FeedbackVectorSlot slot = feedback_spec.AddLoadICSlot(); |
| 2011 |
| 2012 Handle<i::TypeFeedbackVector> vector = |
| 2013 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 2014 |
| 2015 ExpectedSnippet<InstanceType> snippets[] = { |
| 2016 {"var a = {x:13, y:14};\n function f() { return delete a.x; };\n f();", |
| 2017 1 * kPointerSize, |
| 2018 1, |
| 2019 10, |
| 2020 { |
| 2021 B(LdaGlobalSloppy), U8(0), U8(vector->GetIndex(slot)), // |
| 2022 B(Star), R(0), // |
| 2023 B(LdaConstant), U8(1), // |
| 2024 B(DeletePropertySloppy), R(0), // |
| 2025 B(Return) |
| 2026 }, |
| 2027 2, |
| 2028 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
| 2029 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2030 {"a = {1:13, 2:14};\n" |
| 2031 "function f() {'use strict'; return delete a[1];};\n f();", |
| 2032 1 * kPointerSize, |
| 2033 1, |
| 2034 10, |
| 2035 { |
| 2036 B(LdaGlobalStrict), U8(0), U8(vector->GetIndex(slot)), // |
| 2037 B(Star), R(0), // |
| 2038 B(LdaSmi8), U8(1), // |
| 2039 B(DeletePropertyStrict), R(0), // |
| 2040 B(Return) |
| 2041 }, |
| 2042 1, |
| 2043 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2044 {"var a = {x:13, y:14};\n function f() { return delete a; };\n f();", |
| 2045 1 * kPointerSize, |
| 2046 1, |
| 2047 10, |
| 2048 { |
| 2049 B(LdaContextSlot), R(context), U8(global_object_index), // |
| 2050 B(Star), R(0), // |
| 2051 B(LdaConstant), U8(0), // |
| 2052 B(DeletePropertySloppy), R(0), // |
| 2053 B(Return) |
| 2054 }, |
| 2055 1, |
| 2056 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 2057 {"b = 30;\n function f() { return delete b; };\n f();", |
| 2058 1 * kPointerSize, |
| 2059 1, |
| 2060 10, |
| 2061 { |
| 2062 B(LdaContextSlot), R(context), U8(global_object_index), // |
| 2063 B(Star), R(0), // |
| 2064 B(LdaConstant), U8(0), // |
| 2065 B(DeletePropertySloppy), R(0), // |
| 2066 B(Return) |
| 2067 }, |
| 2068 1, |
| 2069 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}}; |
| 2070 |
| 2071 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2072 Handle<BytecodeArray> bytecode_array = |
| 2073 helper.MakeBytecode(snippets[i].code_snippet, "f"); |
| 2074 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2075 } |
| 2076 } |
| 2077 |
| 2078 |
1855 TEST(FunctionLiterals) { | 2079 TEST(FunctionLiterals) { |
1856 InitializedHandleScope handle_scope; | 2080 InitializedHandleScope handle_scope; |
1857 BytecodeGeneratorHelper helper; | 2081 BytecodeGeneratorHelper helper; |
1858 | 2082 |
1859 ExpectedSnippet<InstanceType> snippets[] = { | 2083 ExpectedSnippet<InstanceType> snippets[] = { |
1860 {"return function(){ }", | 2084 {"return function(){ }", |
1861 0, | 2085 0, |
1862 1, | 2086 1, |
1863 5, | 2087 5, |
1864 { | 2088 { |
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3606 for (size_t i = 0; i < arraysize(snippets); i++) { | 3830 for (size_t i = 0; i < arraysize(snippets); i++) { |
3607 Handle<BytecodeArray> bytecode_array = | 3831 Handle<BytecodeArray> bytecode_array = |
3608 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3832 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3609 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3833 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3610 } | 3834 } |
3611 } | 3835 } |
3612 | 3836 |
3613 } // namespace interpreter | 3837 } // namespace interpreter |
3614 } // namespace internal | 3838 } // namespace internal |
3615 } // namespace v8 | 3839 } // namespace v8 |
OLD | NEW |