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 "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/handles.h" | 7 #include "src/handles.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
| 10 #include "src/wasm/wasm-limits.h" |
10 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
11 #include "src/wasm/wasm-opcodes.h" | 12 #include "src/wasm/wasm-opcodes.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 namespace wasm { | 16 namespace wasm { |
16 | 17 |
17 #define WASM_INIT_EXPR_I32V_1(val) WASM_I32V_1(val), kExprEnd | 18 #define WASM_INIT_EXPR_I32V_1(val) WASM_I32V_1(val), kExprEnd |
18 #define WASM_INIT_EXPR_I32V_2(val) WASM_I32V_2(val), kExprEnd | 19 #define WASM_INIT_EXPR_I32V_2(val) WASM_I32V_2(val), kExprEnd |
19 #define WASM_INIT_EXPR_I32V_3(val) WASM_I32V_3(val), kExprEnd | 20 #define WASM_INIT_EXPR_I32V_3(val) WASM_I32V_3(val), kExprEnd |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 304 } |
304 } | 305 } |
305 | 306 |
306 TEST_F(WasmModuleVerifyTest, NGlobals) { | 307 TEST_F(WasmModuleVerifyTest, NGlobals) { |
307 static const byte data[] = { | 308 static const byte data[] = { |
308 kLocalF32, // memory type | 309 kLocalF32, // memory type |
309 0, // immutable | 310 0, // immutable |
310 WASM_INIT_EXPR_F32(7.7), // init | 311 WASM_INIT_EXPR_F32(7.7), // init |
311 }; | 312 }; |
312 | 313 |
313 for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) { | 314 for (uint32_t i = 0; i < kV8MaxWasmGlobals; i = i * 13 + 1) { |
314 std::vector<byte> buffer; | 315 std::vector<byte> buffer; |
315 size_t size = SizeOfVarInt(i) + i * sizeof(data); | 316 size_t size = SizeOfVarInt(i) + i * sizeof(data); |
316 const byte globals[] = {kGlobalSectionCode, U32V_5(size)}; | 317 const byte globals[] = {kGlobalSectionCode, U32V_5(size)}; |
317 for (size_t g = 0; g != sizeof(globals); ++g) { | 318 for (size_t g = 0; g != sizeof(globals); ++g) { |
318 buffer.push_back(globals[g]); | 319 buffer.push_back(globals[g]); |
319 } | 320 } |
320 AppendUint32v(buffer, i); // Number of globals. | 321 AppendUint32v(buffer, i); // Number of globals. |
321 for (uint32_t j = 0; j < i; j++) { | 322 for (uint32_t j = 0; j < i; j++) { |
322 buffer.insert(buffer.end(), data, data + sizeof(data)); | 323 buffer.insert(buffer.end(), data, data + sizeof(data)); |
323 } | 324 } |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 | 841 |
841 EXPECT_TRUE(sig != nullptr); | 842 EXPECT_TRUE(sig != nullptr); |
842 EXPECT_EQ(2u, sig->parameter_count()); | 843 EXPECT_EQ(2u, sig->parameter_count()); |
843 EXPECT_EQ(1u, sig->return_count()); | 844 EXPECT_EQ(1u, sig->return_count()); |
844 EXPECT_EQ(p0_type.type, sig->GetParam(0)); | 845 EXPECT_EQ(p0_type.type, sig->GetParam(0)); |
845 EXPECT_EQ(p1_type.type, sig->GetParam(1)); | 846 EXPECT_EQ(p1_type.type, sig->GetParam(1)); |
846 } | 847 } |
847 } | 848 } |
848 } | 849 } |
849 | 850 |
| 851 TEST_F(WasmSignatureDecodeTest, TooManyParams) { |
| 852 static const byte data[] = {kWasmFunctionTypeForm, |
| 853 WASM_I32V_3(kV8MaxWasmFunctionParams + 1), |
| 854 kLocalI32, 0}; |
| 855 FunctionSig* sig = |
| 856 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
| 857 EXPECT_FALSE(sig != nullptr); |
| 858 } |
| 859 |
| 860 TEST_F(WasmSignatureDecodeTest, TooManyReturns) { |
| 861 bool prev = FLAG_wasm_mv_prototype; |
| 862 for (int i = 0; i < 2; i++) { |
| 863 FLAG_wasm_mv_prototype = i != 0; |
| 864 const int max_return_count = |
| 865 static_cast<int>(FLAG_wasm_mv_prototype ? kV8MaxWasmFunctionMultiReturns |
| 866 : kV8MaxWasmFunctionReturns); |
| 867 byte data[] = {kWasmFunctionTypeForm, 0, WASM_I32V_3(max_return_count + 1), |
| 868 kLocalI32}; |
| 869 FunctionSig* sig = |
| 870 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); |
| 871 EXPECT_EQ(nullptr, sig); |
| 872 FLAG_wasm_mv_prototype = prev; |
| 873 } |
| 874 } |
| 875 |
850 TEST_F(WasmSignatureDecodeTest, Fail_off_end) { | 876 TEST_F(WasmSignatureDecodeTest, Fail_off_end) { |
851 byte data[256]; | 877 byte data[256]; |
852 for (int p = 0; p <= 255; p = p + 1 + p * 3) { | 878 for (int p = 0; p <= 255; p = p + 1 + p * 3) { |
853 for (int i = 0; i <= p; i++) data[i] = kLocalI32; | 879 for (int i = 0; i <= p; i++) data[i] = kLocalI32; |
854 data[0] = static_cast<byte>(p); | 880 data[0] = static_cast<byte>(p); |
855 | 881 |
856 for (int i = 0; i < p + 1; i++) { | 882 for (int i = 0; i < p + 1; i++) { |
857 // Should fall off the end for all signatures. | 883 // Should fall off the end for all signatures. |
858 FunctionSig* sig = DecodeWasmSignatureForTesting(zone(), data, data + i); | 884 FunctionSig* sig = DecodeWasmSignatureForTesting(zone(), data, data + i); |
859 EXPECT_EQ(nullptr, sig); | 885 EXPECT_EQ(nullptr, sig); |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- | 1504 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- |
1479 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- | 1505 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- |
1480 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- | 1506 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- |
1481 }; | 1507 }; |
1482 EXPECT_VERIFIES(data); | 1508 EXPECT_VERIFIES(data); |
1483 } | 1509 } |
1484 | 1510 |
1485 } // namespace wasm | 1511 } // namespace wasm |
1486 } // namespace internal | 1512 } // namespace internal |
1487 } // namespace v8 | 1513 } // namespace v8 |
OLD | NEW |