diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc index be4d8ef833..61fc2619d1 100644 --- a/src/wasm/module-decoder.cc +++ b/src/wasm/module-decoder.cc @@ -920,6 +920,13 @@ class ModuleDecoderImpl : public Decoder { ? consume_element_expr() : WasmInitExpr::RefFuncConst(consume_element_func_index()); if (failed()) return; + if (!IsSubtypeOf(TypeOf(init), segment.type, module_.get())) { + errorf(pc_, + "Invalid type in the init expression. The expected type is " + "'%s', but the actual type is '%s'.", + segment.type.name().c_str(), TypeOf(init).name().c_str()); + return; + } segment.entries.push_back(std::move(init)); } module_->elem_segments.push_back(std::move(segment)); diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc index 2547fe9a85..f6ac1d8e74 100644 --- a/test/unittests/wasm/module-decoder-unittest.cc +++ b/test/unittests/wasm/module-decoder-unittest.cc @@ -1860,6 +1860,47 @@ TEST_F(WasmModuleVerifyTest, ElementSectionInitExternRefTableWithFuncRef) { "Instead, table 0 of type externref is referenced."); } +TEST_F(WasmModuleVerifyTest, ElementSectionInitFuncRefTableWithFuncRefNull) { + WASM_FEATURE_SCOPE(reftypes); + static const byte data[] = { + // table declaration --------------------------------------------------- + SECTION(Table, ENTRY_COUNT(1), // section header + kFuncRefCode, 0, 9), // table 0 + // elements ------------------------------------------------------------ + SECTION(Element, + ENTRY_COUNT(1), // entry count + ACTIVE_WITH_ELEMENTS, TABLE_INDEX0, // element for table 0 + WASM_INIT_EXPR_I32V_1(0), // index + kFuncRefCode, // . + 1, // elements count + WASM_INIT_EXPR_FUNC_REF_NULL) // function + }; + + EXPECT_VERIFIES(data); +} + +TEST_F(WasmModuleVerifyTest, ElementSectionInitFuncRefTableWithExternRefNull) { + WASM_FEATURE_SCOPE(reftypes); + static const byte data[] = { + // table declaration --------------------------------------------------- + SECTION(Table, ENTRY_COUNT(1), // section header + kFuncRefCode, 0, 9), // table 0 + // elements ------------------------------------------------------------ + SECTION(Element, + ENTRY_COUNT(1), // entry count + ACTIVE_WITH_ELEMENTS, TABLE_INDEX0, // element for table 0 + WASM_INIT_EXPR_I32V_1(0), // index + kFuncRefCode, // . + 1, // elements count + WASM_INIT_EXPR_EXTERN_REF_NULL) // function + }; + + EXPECT_FAILURE_WITH_MSG( + data, + "Invalid type in the init expression. The expected " + "type is 'funcref', but the actual type is 'externref'."); +} + TEST_F(WasmModuleVerifyTest, ElementSectionDontInitExternRefImportedTable) { // Test that imported tables of type ExternRef cannot be initialized in the // elements section. diff --git a/test/wasm-spec-tests/wasm-spec-tests.status b/test/wasm-spec-tests/wasm-spec-tests.status index 75962cf9bc..f60cc8ac97 100644 --- a/test/wasm-spec-tests/wasm-spec-tests.status +++ b/test/wasm-spec-tests/wasm-spec-tests.status @@ -7,7 +7,6 @@ 'skip-stack-guard-page': [PASS, ['((arch == ppc or arch == ppc64 or arch == s390 or arch == s390x) and simulator_run)', SKIP]], # TODO(v8:10994): Failing spec test after update. 'proposals/js-types/data': [FAIL], - 'elem': [FAIL], # Missing rebase in the proposal repository. 'proposals/js-types/table': [FAIL],