Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3910,13 +3910,7 @@ impl ComponentState {
) -> Result<ComponentDefinedType> {
match ty {
crate::ComponentDefinedType::Primitive(ty) => {
if ty == crate::PrimitiveValType::ErrorContext && !self.features.cm_error_context()
{
bail!(
offset,
"`error-context` requires the component model error-context feature"
)
}
self.check_primitive_type(ty, offset)?;
Ok(ComponentDefinedType::Primitive(ty))
}
crate::ComponentDefinedType::Record(fields) => {
Expand Down Expand Up @@ -4184,7 +4178,10 @@ impl ComponentState {
offset: usize,
) -> Result<ComponentValType> {
Ok(match ty {
crate::ComponentValType::Primitive(pt) => ComponentValType::Primitive(pt),
crate::ComponentValType::Primitive(pt) => {
self.check_primitive_type(pt, offset)?;
ComponentValType::Primitive(pt)
}
crate::ComponentValType::Type(idx) => {
ComponentValType::Type(self.defined_type_at(idx, offset)?)
}
Expand Down Expand Up @@ -4470,6 +4467,16 @@ impl ComponentState {
}
Ok(())
}

fn check_primitive_type(&self, ty: crate::PrimitiveValType, offset: usize) -> Result<()> {
if ty == crate::PrimitiveValType::ErrorContext && !self.features.cm_error_context() {
bail!(
offset,
"`error-context` requires the component model error-context feature"
)
}
Ok(())
}
}

impl InternRecGroup for ComponentState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
;; RUN: wast --assert default --snapshot tests/snapshots % -f=-cm-error-context

;; error-context.new
(assert_invalid
(component
(import "x" (func (param "x" error-context)))
)
"requires the component model error-context feature"
)

;; error-context.new
(assert_invalid
(component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,34 @@
"line": 5,
"filename": "error-context.0.wasm",
"module_type": "binary",
"text": "`error-context.new` requires the component model error-context feature"
"text": "requires the component model error-context feature"
},
{
"type": "assert_invalid",
"line": 19,
"line": 13,
"filename": "error-context.1.wasm",
"module_type": "binary",
"text": "`error-context.debug-message` requires the component model error-context feature"
"text": "`error-context.new` requires the component model error-context feature"
},
{
"type": "assert_invalid",
"line": 36,
"line": 27,
"filename": "error-context.2.wasm",
"module_type": "binary",
"text": "`error-context.drop` requires the component model error-context feature"
"text": "`error-context.debug-message` requires the component model error-context feature"
},
{
"type": "assert_invalid",
"line": 48,
"line": 44,
"filename": "error-context.3.wasm",
"module_type": "binary",
"text": "`error-context.drop` requires the component model error-context feature"
},
{
"type": "assert_invalid",
"line": 56,
"filename": "error-context.4.wasm",
"module_type": "binary",
"text": "requires the component model error-context feature"
}
]
Expand Down