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

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 2222193004: [WASM] Exception handling prototype. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addresses comments Created 4 years, 4 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
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 1822
1823 EXPECT_FAILURE_INLINE( 1823 EXPECT_FAILURE_INLINE(
1824 sigs.i_i(), 1824 sigs.i_i(),
1825 WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); 1825 WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0)));
1826 1826
1827 EXPECT_FAILURE_INLINE( 1827 EXPECT_FAILURE_INLINE(
1828 sigs.i_i(), 1828 sigs.i_i(),
1829 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); 1829 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0)));
1830 } 1830 }
1831 1831
1832 TEST_F(AstDecoderTest, Throw) {
1833 FLAG_wasm_eh_prototype = true;
1834 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprThrow);
1835
1836 // TODO(jpp): can't throw d, f, or l.
1837 EXPECT_VERIFIES_INLINE(sigs.i_d(), WASM_GET_LOCAL(0), kExprThrow,
1838 WASM_I32V(0));
1839 EXPECT_VERIFIES_INLINE(sigs.i_f(), WASM_GET_LOCAL(0), kExprThrow,
1840 WASM_I32V(0));
1841 EXPECT_VERIFIES_INLINE(sigs.l_l(), WASM_GET_LOCAL(0), kExprThrow,
1842 WASM_I64V(0));
1843 }
1844
1845 #define WASM_CATCH(local) kExprCatch, static_cast<byte>(local)
1846 TEST_F(AstDecoderTest, TryCatch) {
1847 FLAG_wasm_eh_prototype = true;
1848 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprTryCatch, WASM_CATCH(0), kExprEnd);
1849
1850 // Missing catch.
1851 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTryCatch, kExprEnd);
1852
1853 // Missing end.
1854 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatch, WASM_CATCH(0));
1855
1856 // Double catch.
1857 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatch, WASM_CATCH(0), WASM_CATCH(0),
1858 kExprEnd);
1859
1860 // Unexpected finally.
1861 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatch, WASM_CATCH(0), kExprFinally,
1862 kExprEnd);
1863 }
1864
1865 TEST_F(AstDecoderTest, TryFinally) {
1866 FLAG_wasm_eh_prototype = true;
1867 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprTryFinally, kExprFinally, kExprEnd);
1868
1869 // Mising finally.
1870 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTryFinally, kExprEnd);
1871
1872 // Missing end.
1873 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTryFinally, kExprFinally);
1874
1875 // Double finally.
1876 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTryFinally, kExprFinally, kExprFinally,
1877 kExprEnd);
1878
1879 // Unexpected catch.
1880 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatch, WASM_CATCH(0), kExprFinally,
1881 kExprEnd);
1882 }
1883
1884 TEST_F(AstDecoderTest, TryCatchFinally) {
1885 FLAG_wasm_eh_prototype = true;
1886 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprTryCatchFinally, WASM_CATCH(0),
1887 kExprFinally, kExprEnd);
1888
1889 // Missing catch.
1890 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, kExprFinally,
1891 kExprEnd);
1892
1893 // Double catch.
1894 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, WASM_CATCH(0),
1895 WASM_CATCH(0), kExprFinally, kExprEnd);
1896
1897 // Missing finally.
1898 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, WASM_CATCH(0),
1899 kExprEnd);
1900
1901 // Double finally.
1902 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, WASM_CATCH(0),
1903 kExprFinally, kExprFinally, kExprEnd);
1904
1905 // Finally before catch.
1906 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, kExprFinally,
1907 WASM_CATCH(0), kExprEnd);
1908
1909 // Missing both try and finally.
1910 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, kExprEnd);
1911
1912 // Missing end.
1913 EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTryCatchFinally, WASM_CATCH(0),
1914 kExprFinally);
1915 }
1916
1832 class WasmOpcodeLengthTest : public TestWithZone { 1917 class WasmOpcodeLengthTest : public TestWithZone {
1833 public: 1918 public:
1834 WasmOpcodeLengthTest() : TestWithZone() {} 1919 WasmOpcodeLengthTest() : TestWithZone() {}
1835 }; 1920 };
1836 1921
1837 #define EXPECT_LENGTH(expected, opcode) \ 1922 #define EXPECT_LENGTH(expected, opcode) \
1838 { \ 1923 { \
1839 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ 1924 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \
1840 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 1925 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
1841 } 1926 }
1842 1927
1843 #define EXPECT_LENGTH_N(expected, ...) \ 1928 #define EXPECT_LENGTH_N(expected, ...) \
1844 { \ 1929 { \
1845 static const byte code[] = {__VA_ARGS__}; \ 1930 static const byte code[] = {__VA_ARGS__}; \
1846 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 1931 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
1847 } 1932 }
1848 1933
1849 TEST_F(WasmOpcodeLengthTest, Statements) { 1934 TEST_F(WasmOpcodeLengthTest, Statements) {
1850 EXPECT_LENGTH(1, kExprNop); 1935 EXPECT_LENGTH(1, kExprNop);
1851 EXPECT_LENGTH(1, kExprBlock); 1936 EXPECT_LENGTH(1, kExprBlock);
1852 EXPECT_LENGTH(1, kExprLoop); 1937 EXPECT_LENGTH(1, kExprLoop);
1853 EXPECT_LENGTH(1, kExprIf); 1938 EXPECT_LENGTH(1, kExprIf);
1854 EXPECT_LENGTH(1, kExprElse); 1939 EXPECT_LENGTH(1, kExprElse);
1855 EXPECT_LENGTH(1, kExprEnd); 1940 EXPECT_LENGTH(1, kExprEnd);
1856 EXPECT_LENGTH(1, kExprSelect); 1941 EXPECT_LENGTH(1, kExprSelect);
1857 EXPECT_LENGTH(3, kExprBr); 1942 EXPECT_LENGTH(3, kExprBr);
1858 EXPECT_LENGTH(3, kExprBrIf); 1943 EXPECT_LENGTH(3, kExprBrIf);
1944 EXPECT_LENGTH(1, kExprThrow);
1945 EXPECT_LENGTH(1, kExprTryCatch);
1946 EXPECT_LENGTH(1, kExprTryFinally);
1947 EXPECT_LENGTH(1, kExprTryCatchFinally);
1948 EXPECT_LENGTH(2, kExprCatch);
1949 EXPECT_LENGTH(1, kExprFinally);
1859 } 1950 }
1860 1951
1861 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { 1952 TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
1862 EXPECT_LENGTH(2, kExprI8Const); 1953 EXPECT_LENGTH(2, kExprI8Const);
1863 EXPECT_LENGTH(5, kExprF32Const); 1954 EXPECT_LENGTH(5, kExprF32Const);
1864 EXPECT_LENGTH(9, kExprF64Const); 1955 EXPECT_LENGTH(9, kExprF64Const);
1865 EXPECT_LENGTH(2, kExprGetLocal); 1956 EXPECT_LENGTH(2, kExprGetLocal);
1866 EXPECT_LENGTH(2, kExprSetLocal); 1957 EXPECT_LENGTH(2, kExprSetLocal);
1867 EXPECT_LENGTH(2, kExprGetGlobal); 1958 EXPECT_LENGTH(2, kExprGetGlobal);
1868 EXPECT_LENGTH(2, kExprSetGlobal); 1959 EXPECT_LENGTH(2, kExprSetGlobal);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 EXPECT_ARITY(1, kExprBrTable); 2181 EXPECT_ARITY(1, kExprBrTable);
2091 2182
2092 EXPECT_ARITY(1, kExprBr, ARITY_1); 2183 EXPECT_ARITY(1, kExprBr, ARITY_1);
2093 EXPECT_ARITY(2, kExprBrIf, ARITY_1); 2184 EXPECT_ARITY(2, kExprBrIf, ARITY_1);
2094 EXPECT_ARITY(2, kExprBrTable, ARITY_1); 2185 EXPECT_ARITY(2, kExprBrTable, ARITY_1);
2095 2186
2096 { 2187 {
2097 EXPECT_ARITY(0, kExprReturn, ARITY_0); 2188 EXPECT_ARITY(0, kExprReturn, ARITY_0);
2098 EXPECT_ARITY(1, kExprReturn, ARITY_1); 2189 EXPECT_ARITY(1, kExprReturn, ARITY_1);
2099 } 2190 }
2191
2192 EXPECT_ARITY(0, kExprThrow);
2193 EXPECT_ARITY(0, kExprTryCatch);
2194 EXPECT_ARITY(0, kExprTryFinally);
2195 EXPECT_ARITY(0, kExprTryCatchFinally);
2196 EXPECT_ARITY(1, kExprCatch, 2);
2197 EXPECT_ARITY(0, kExprFinally);
2100 } 2198 }
2101 2199
2102 TEST_F(WasmOpcodeArityTest, Misc) { 2200 TEST_F(WasmOpcodeArityTest, Misc) {
2103 EXPECT_ARITY(0, kExprI8Const); 2201 EXPECT_ARITY(0, kExprI8Const);
2104 EXPECT_ARITY(0, kExprI32Const); 2202 EXPECT_ARITY(0, kExprI32Const);
2105 EXPECT_ARITY(0, kExprF32Const); 2203 EXPECT_ARITY(0, kExprF32Const);
2106 EXPECT_ARITY(0, kExprI64Const); 2204 EXPECT_ARITY(0, kExprI64Const);
2107 EXPECT_ARITY(0, kExprF64Const); 2205 EXPECT_ARITY(0, kExprF64Const);
2108 EXPECT_ARITY(0, kExprGetLocal); 2206 EXPECT_ARITY(0, kExprGetLocal);
2109 EXPECT_ARITY(1, kExprSetLocal); 2207 EXPECT_ARITY(1, kExprSetLocal);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2464 iter.next(); 2562 iter.next();
2465 EXPECT_TRUE(iter.has_next()); 2563 EXPECT_TRUE(iter.has_next());
2466 EXPECT_EQ(kExprI8Const, iter.current()); 2564 EXPECT_EQ(kExprI8Const, iter.current());
2467 iter.next(); 2565 iter.next();
2468 EXPECT_FALSE(iter.has_next()); 2566 EXPECT_FALSE(iter.has_next());
2469 } 2567 }
2470 2568
2471 } // namespace wasm 2569 } // namespace wasm
2472 } // namespace internal 2570 } // namespace internal
2473 } // namespace v8 2571 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698