diff options
Diffstat (limited to 'deps/v8/test/unittests/wasm/module-decoder-unittest.cc')
-rw-r--r-- | deps/v8/test/unittests/wasm/module-decoder-unittest.cc | 83 |
1 files changed, 74 insertions, 9 deletions
diff --git a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc index 4493fcf1dd..25eb121074 100644 --- a/deps/v8/test/unittests/wasm/module-decoder-unittest.cc +++ b/deps/v8/test/unittests/wasm/module-decoder-unittest.cc @@ -343,6 +343,22 @@ TEST_F(WasmModuleVerifyTest, FuncRefGlobal) { } } +TEST_F(WasmModuleVerifyTest, InvalidFuncRefGlobal) { + WASM_FEATURE_SCOPE(anyref); + static const byte data[] = { + // sig#0 --------------------------------------------------------------- + SIGNATURES_SECTION_VOID_VOID, + // funcs --------------------------------------------------------------- + TWO_EMPTY_FUNCTIONS(SIG_INDEX(0)), + SECTION(Global, // -- + ENTRY_COUNT(1), // -- + kLocalFuncRef, // local type + 0, // immutable + WASM_INIT_EXPR_REF_FUNC(7)), // invalid function index + TWO_EMPTY_BODIES}; + EXPECT_FAILURE(data); +} + TEST_F(WasmModuleVerifyTest, AnyRefGlobalWithGlobalInit) { WASM_FEATURE_SCOPE(anyref); static const byte data[] = { @@ -439,17 +455,15 @@ TEST_F(WasmModuleVerifyTest, ExportMutableGlobal) { } } -static void AppendUint32v( - std::vector<byte>& buffer, // NOLINT(runtime/references) - uint32_t val) { +static void AppendUint32v(std::vector<byte>* buffer, uint32_t val) { while (true) { uint32_t next = val >> 7; uint32_t out = val & 0x7F; if (next) { - buffer.push_back(static_cast<byte>(0x80 | out)); + buffer->push_back(static_cast<byte>(0x80 | out)); val = next; } else { - buffer.push_back(static_cast<byte>(out)); + buffer->push_back(static_cast<byte>(out)); break; } } @@ -469,7 +483,7 @@ TEST_F(WasmModuleVerifyTest, NGlobals) { for (size_t g = 0; g != sizeof(globals); ++g) { buffer.push_back(globals[g]); } - AppendUint32v(buffer, i); // Number of globals. + AppendUint32v(&buffer, i); // Number of globals. for (uint32_t j = 0; j < i; j++) { buffer.insert(buffer.end(), data, data + sizeof(data)); } @@ -1072,6 +1086,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTables) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 1 WASM_INIT_EXPR_I32V_1(7), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0)), // entry 1 @@ -1118,15 +1133,18 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTables) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 1 WASM_INIT_EXPR_I32V_1(7), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0), // entry 1 TABLE_INDEX(2), // element for table 2 WASM_INIT_EXPR_I32V_1(12), // index + kExternalFunction, // type 1, // elements count FUNC_INDEX(0), // function TABLE_INDEX(3), // element for table 1 WASM_INIT_EXPR_I32V_1(17), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0)), // entry 1 @@ -1159,6 +1177,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMultipleTablesArbitraryOrder) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 0 WASM_INIT_EXPR_I32V_1(7), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0), // entry 1 @@ -1205,10 +1224,12 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) { 4, // entry count TABLE_INDEX(2), // element for table 0 WASM_INIT_EXPR_I32V_1(10), // index + kExternalFunction, // type 1, // elements count FUNC_INDEX(0), // function TABLE_INDEX(3), // element for table 1 WASM_INIT_EXPR_I32V_1(17), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0), // entry 1 @@ -1218,6 +1239,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionMixedTablesArbitraryOrder) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 1 WASM_INIT_EXPR_I32V_1(7), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0)), // entry 1 @@ -1248,6 +1270,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitAnyRefTableWithFuncRef) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 1 WASM_INIT_EXPR_I32V_1(7), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0)), // entry 1 @@ -1295,6 +1318,7 @@ TEST_F(WasmModuleVerifyTest, ElementSectionDontInitAnyRefImportedTable) { FUNC_INDEX(0), // function TABLE_INDEX(1), // element for table 1 WASM_INIT_EXPR_I32V_1(17), // index + kExternalFunction, // type 2, // elements count FUNC_INDEX(0), // entry 0 FUNC_INDEX(0)), // entry 1 @@ -2345,7 +2369,7 @@ TEST_F(WasmModuleVerifyTest, PassiveDataSegment) { EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5); } -TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { +TEST_F(WasmModuleVerifyTest, ActiveElementSegmentWithElements) { static const byte data[] = { // sig#0 ----------------------------------------------------------------- SIGNATURES_SECTION_VOID_VOID, @@ -2354,7 +2378,8 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { // table declaration ----------------------------------------------------- SECTION(Table, ENTRY_COUNT(1), kLocalFuncRef, 0, 1), // element segments ----------------------------------------------------- - SECTION(Element, ENTRY_COUNT(1), PASSIVE, kLocalFuncRef, U32V_1(3), + SECTION(Element, ENTRY_COUNT(1), ACTIVE_WITH_ELEMENTS, TABLE_INDEX0, + WASM_INIT_EXPR_I32V_1(0), kLocalFuncRef, U32V_1(3), REF_FUNC_ELEMENT(0), REF_FUNC_ELEMENT(0), REF_NULL_ELEMENT), // code ------------------------------------------------------------------ ONE_EMPTY_BODY}; @@ -2364,6 +2389,26 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5); } +TEST_F(WasmModuleVerifyTest, PassiveElementSegment) { + static const byte data[] = { + // sig#0 ----------------------------------------------------------------- + SIGNATURES_SECTION_VOID_VOID, + // funcs ----------------------------------------------------------------- + ONE_EMPTY_FUNCTION(SIG_INDEX(0)), + // table declaration ----------------------------------------------------- + SECTION(Table, ENTRY_COUNT(1), kLocalFuncRef, 0, 1), + // element segments ----------------------------------------------------- + SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kLocalFuncRef, + U32V_1(3), REF_FUNC_ELEMENT(0), REF_FUNC_ELEMENT(0), + REF_NULL_ELEMENT), + // code ------------------------------------------------------------------ + ONE_EMPTY_BODY}; + EXPECT_FAILURE(data); + WASM_FEATURE_SCOPE(bulk_memory); + EXPECT_VERIFIES(data); + EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5); +} + TEST_F(WasmModuleVerifyTest, PassiveElementSegmentAnyRef) { static const byte data[] = { // sig#0 ----------------------------------------------------------------- @@ -2373,13 +2418,33 @@ TEST_F(WasmModuleVerifyTest, PassiveElementSegmentAnyRef) { // table declaration ----------------------------------------------------- SECTION(Table, ENTRY_COUNT(1), kLocalFuncRef, 0, 1), // element segments ----------------------------------------------------- - SECTION(Element, ENTRY_COUNT(1), PASSIVE, kLocalAnyRef, U32V_1(0)), + SECTION(Element, ENTRY_COUNT(1), PASSIVE_WITH_ELEMENTS, kLocalAnyRef, + U32V_1(0)), // code ------------------------------------------------------------------ ONE_EMPTY_BODY}; WASM_FEATURE_SCOPE(bulk_memory); EXPECT_FAILURE(data); } +TEST_F(WasmModuleVerifyTest, PassiveElementSegmentWithIndices) { + static const byte data[] = { + // sig#0 ----------------------------------------------------------------- + SIGNATURES_SECTION_VOID_VOID, + // funcs ----------------------------------------------------------------- + ONE_EMPTY_FUNCTION(SIG_INDEX(0)), + // table declaration ----------------------------------------------------- + SECTION(Table, ENTRY_COUNT(1), kLocalFuncRef, 0, 1), + // element segments ----------------------------------------------------- + SECTION(Element, ENTRY_COUNT(1), PASSIVE, kExternalFunction, + ENTRY_COUNT(3), U32V_1(0), U32V_1(0), U32V_1(0)), + // code ------------------------------------------------------------------ + ONE_EMPTY_BODY}; + EXPECT_FAILURE(data); + WASM_FEATURE_SCOPE(bulk_memory); + EXPECT_VERIFIES(data); + EXPECT_OFF_END_FAILURE(data, arraysize(data) - 5); +} + TEST_F(WasmModuleVerifyTest, DataCountSectionCorrectPlacement) { static const byte data[] = {SECTION(Element, ENTRY_COUNT(0)), SECTION(DataCount, ENTRY_COUNT(0)), |