Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1410953003: [Interpreter] Adds delete operator to interpreter. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 1885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
1886 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1886 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1887 } 1887 }
1888 } 1888 }
1889 1889
1890 1890
1891 TEST(UnaryOperators) { 1891 TEST(UnaryOperators) {
1892 InitializedHandleScope handle_scope; 1892 InitializedHandleScope handle_scope;
1893 BytecodeGeneratorHelper helper; 1893 BytecodeGeneratorHelper helper;
1894 1894
1895 ExpectedSnippet<int> snippets[] = { 1895 ExpectedSnippet<int> snippets[] = {{"var x = 0;"
rmcilroy 2015/10/21 14:52:54 Could you restore this to the previous indenting p
mythria 2015/10/23 14:48:01 Done.
1896 {"var x = 0;" 1896 "while (x != 10) {"
1897 "while (x != 10) {" 1897 " x = x + 10;"
1898 " x = x + 10;" 1898 "}"
1899 "}" 1899 "return x;",
1900 "return x;", 1900 2 * kPointerSize,
1901 1,
1902 29,
1903 {
1904 B(LdaZero), //
1905 B(Star), R(0), //
1906 B(Jump), U8(12), //
1907 B(Ldar), R(0), //
1908 B(Star), R(1), //
1909 B(LdaSmi8), U8(10), //
1910 B(Add), R(1), //
1911 B(Star), R(0), //
1912 B(Ldar), R(0), //
1913 B(Star), R(1), //
1914 B(LdaSmi8), U8(10), //
1915 B(TestEqual), R(1), //
1916 B(LogicalNot), //
1917 B(JumpIfTrue), U8(-19), //
1918 B(Ldar), R(0), //
1919 B(Return), //
1920 },
1921 0},
1922 {"var x = false;"
1923 "do {"
1924 " x = !x;"
1925 "} while(x == false);"
1926 "return x;",
1927 2 * kPointerSize,
1928 1,
1929 20,
1930 {
1931 B(LdaFalse), //
1932 B(Star), R(0), //
1933 B(Ldar), R(0), //
1934 B(LogicalNot), //
1935 B(Star), R(0), //
1936 B(Ldar), R(0), //
1937 B(Star), R(1), //
1938 B(LdaFalse), //
1939 B(TestEqual), R(1), //
1940 B(JumpIfTrue), U8(-12), //
1941 B(Ldar), R(0), //
1942 B(Return), //
1943 },
1944 0},
1945 {"var x = 101;"
1946 "return void(x * 3);",
1947 2 * kPointerSize,
1948 1,
1949 14,
1950 {
1951 B(LdaSmi8), U8(101), //
1952 B(Star), R(0), //
1953 B(Ldar), R(0), //
1954 B(Star), R(1), //
1955 B(LdaSmi8), U8(3), //
1956 B(Mul), R(1), //
1957 B(LdaUndefined), //
1958 B(Return), //
1959 },
1960 0},
1961 {"var x = 1234;"
1962 "var y = void (x * x - 1);"
1963 "return y;",
1964 4 * kPointerSize,
1965 1,
1966 24,
1967 {
1968 B(LdaConstant), U8(0), //
1969 B(Star), R(0), //
1970 B(Ldar), R(0), //
1971 B(Star), R(3), //
1972 B(Ldar), R(0), //
1973 B(Mul), R(3), //
1974 B(Star), R(2), //
1975 B(LdaSmi8), U8(1), //
1976 B(Sub), R(2), //
1977 B(LdaUndefined), //
1978 B(Star), R(1), //
1979 B(Ldar), R(1), //
1980 B(Return), //
1981 },
1982 1,
1983 {1234}},
1984 {"var x = 13;"
1985 "return typeof(x);",
1986 1 * kPointerSize,
1987 1,
1988 8,
1989 {
1990 B(LdaSmi8), U8(13), //
1991 B(Star), R(0), //
1992 B(Ldar), R(0), //
1993 B(TypeOf), //
1994 B(Return), //
1995 },
1996 0},
1997 {"var x = 13;"
1998 "return ~x;",
1999 2 * kPointerSize,
2000 1,
2001 13,
2002 {
2003 B(LdaSmi8), U8(13), //
2004 B(Star), R(0), //
2005 B(Ldar), R(0), //
2006 B(Star), R(1), //
2007 B(LdaSmi8), U8(-1), //
2008 B(BitwiseXor), R(1), //
2009 B(Return), //
2010 },
2011 0},
2012 {"var x = 13;"
2013 "return +x;",
2014 2 * kPointerSize,
2015 1,
2016 13,
2017 {
2018 B(LdaSmi8), U8(13), //
2019 B(Star), R(0), //
2020 B(Ldar), R(0), //
2021 B(Star), R(1), //
2022 B(LdaSmi8), U8(1), //
2023 B(Mul), R(1), //
2024 B(Return), //
2025 },
2026 0},
2027 {"var x = 13;"
2028 "return -x;",
2029 2 * kPointerSize,
2030 1,
2031 13,
2032 {
2033 B(LdaSmi8), U8(13), //
2034 B(Star), R(0), //
2035 B(Ldar), R(0), //
2036 B(Star), R(1), //
2037 B(LdaSmi8), U8(-1), //
2038 B(Mul), R(1), //
2039 B(Return), //
2040 },
2041 0}};
2042
2043
2044 for (size_t i = 0; i < arraysize(snippets); i++) {
2045 Handle<BytecodeArray> bytecode_array =
2046 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2047 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2048 }
2049 }
2050
2051
2052 TEST(UnaryDeleteOperator) {
2053 InitializedHandleScope handle_scope;
2054 BytecodeGeneratorHelper helper;
2055
2056 int deep_elements_flags =
2057 ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos;
2058
2059 ExpectedSnippet<InstanceType> snippets[] = {
2060 {"var a = {x:13, y:14}; return delete a.x;",
rmcilroy 2015/10/21 14:52:54 Could you add tests for the different types of del
mythria 2015/10/23 14:48:01 Done.
1901 2 * kPointerSize, 2061 2 * kPointerSize,
1902 1, 2062 1,
1903 29, 2063 16,
1904 { 2064 {B(LdaConstant), U8(0), //
1905 B(LdaZero), // 2065 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
1906 B(Star), R(0), // 2066 B(Star), R(0), //
1907 B(Jump), U8(12), // 2067 B(Ldar), R(0), //
1908 B(Ldar), R(0), // 2068 B(Star), R(1), //
1909 B(Star), R(1), // 2069 B(LdaConstant), U8(1), //
1910 B(LdaSmi8), U8(10), // 2070 B(DeletePropertySloppy), R(1), //
1911 B(Add), R(1), // 2071 B(Return)},
1912 B(Star), R(0), // 2072 2,
1913 B(Ldar), R(0), // 2073 {InstanceType::FIXED_ARRAY_TYPE,
1914 B(Star), R(1), // 2074 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}},
1915 B(LdaSmi8), U8(10), // 2075 {"'use strict'; var a = {x:13, y:14}; return delete a.x;",
1916 B(TestEqual), R(1), //
1917 B(LogicalNot), //
1918 B(JumpIfTrue), U8(-19), //
1919 B(Ldar), R(0), //
1920 B(Return), //
1921 },
1922 0},
1923 {"var x = false;"
1924 "do {"
1925 " x = !x;"
1926 "} while(x == false);"
1927 "return x;",
1928 2 * kPointerSize, 2076 2 * kPointerSize,
1929 1, 2077 1,
1930 20, 2078 18,
1931 { 2079 {B(LdaConstant), U8(0), B(LdaConstant), U8(1), //
1932 B(LdaFalse), // 2080 B(CreateObjectLiteral), U8(0), U8(deep_elements_flags), //
1933 B(Star), R(0), // 2081 B(Star), R(0), //
1934 B(Ldar), R(0), // 2082 B(Ldar), R(0), //
1935 B(LogicalNot), // 2083 B(Star), R(1), //
1936 B(Star), R(0), // 2084 B(LdaConstant), U8(2), //
1937 B(Ldar), R(0), // 2085 B(DeletePropertyStrict), R(1), //
1938 B(Star), R(1), // 2086 B(Return)},
1939 B(LdaFalse), // 2087 3,
1940 B(TestEqual), R(1), // 2088 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE,
1941 B(JumpIfTrue), U8(-12), // 2089 InstanceType::FIXED_ARRAY_TYPE,
1942 B(Ldar), R(0), // 2090 InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}};
1943 B(Return), //
1944 },
1945 0},
1946 {"var x = 101;"
1947 "return void(x * 3);",
1948 2 * kPointerSize,
1949 1,
1950 14,
1951 {
1952 B(LdaSmi8), U8(101), //
1953 B(Star), R(0), //
1954 B(Ldar), R(0), //
1955 B(Star), R(1), //
1956 B(LdaSmi8), U8(3), //
1957 B(Mul), R(1), //
1958 B(LdaUndefined), //
1959 B(Return), //
1960 },
1961 0},
1962 {"var x = 1234;"
1963 "var y = void (x * x - 1);"
1964 "return y;",
1965 4 * kPointerSize,
1966 1,
1967 24,
1968 {
1969 B(LdaConstant), U8(0), //
1970 B(Star), R(0), //
1971 B(Ldar), R(0), //
1972 B(Star), R(3), //
1973 B(Ldar), R(0), //
1974 B(Mul), R(3), //
1975 B(Star), R(2), //
1976 B(LdaSmi8), U8(1), //
1977 B(Sub), R(2), //
1978 B(LdaUndefined), //
1979 B(Star), R(1), //
1980 B(Ldar), R(1), //
1981 B(Return), //
1982 },
1983 1,
1984 {1234}},
1985 {"var x = 13;"
1986 "return typeof(x);",
1987 1 * kPointerSize,
1988 1,
1989 8,
1990 {
1991 B(LdaSmi8), U8(13), //
1992 B(Star), R(0), //
1993 B(Ldar), R(0), //
1994 B(TypeOf), //
1995 B(Return), //
1996 },
1997 0},
1998 };
1999 2091
2000 for (size_t i = 0; i < arraysize(snippets); i++) { 2092 for (size_t i = 0; i < arraysize(snippets); i++) {
2001 Handle<BytecodeArray> bytecode_array = 2093 Handle<BytecodeArray> bytecode_array =
2002 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 2094 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
2003 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 2095 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
2004 } 2096 }
2005 } 2097 }
2006 2098
2007 2099
2008 TEST(FunctionLiterals) { 2100 TEST(FunctionLiterals) {
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 for (size_t i = 0; i < arraysize(snippets); i++) { 3115 for (size_t i = 0; i < arraysize(snippets); i++) {
3024 Handle<BytecodeArray> bytecode_array = 3116 Handle<BytecodeArray> bytecode_array =
3025 helper.MakeBytecodeForFunction(snippets[i].code_snippet); 3117 helper.MakeBytecodeForFunction(snippets[i].code_snippet);
3026 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 3118 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
3027 } 3119 }
3028 } 3120 }
3029 3121
3030 } // namespace interpreter 3122 } // namespace interpreter
3031 } // namespace internal 3123 } // namespace internal
3032 } // namespace v8 3124 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698