Skip to content

Commit

Permalink
Slightly tweak error reporting for constructed function reference typ…
Browse files Browse the repository at this point in the history
…es in validation of continuation instructions. (bytecodealliance#21)
  • Loading branch information
dhil authored Oct 17, 2023
1 parent d5e5548 commit 6a0d990
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3449,9 +3449,9 @@ where
// Typed continuations operators.
fn visit_cont_new(&mut self, type_index: u32) -> Self::Output {
let fidx = self.cont_type_at(type_index)?.0;
let rt = RefType::indexed_func(false, fidx).unwrap(); // TODO(dhil): proper error handling
let rt = RefType::indexed_func(false, fidx).expect("type index is too large");
self.pop_operand(Some(ValType::Ref(rt)))?;
let result = RefType::indexed_func(false, type_index).unwrap(); // TODO(dhil): proper error handling
let result = RefType::indexed_func(false, type_index).expect("type index is too large");
self.push_operand(ValType::Ref(result))?;
Ok(())
}
Expand Down Expand Up @@ -3485,7 +3485,7 @@ where
None => {} // bot case
Some(rt) => {
let expected = ValType::Ref(
RefType::indexed_func(false, src_index).unwrap(), /* TODO(dhil): proper error handling */
RefType::indexed_func(false, src_index).expect("type index is too large"),
);
if !self.resources.matches(expected, ValType::Ref(rt)) {
bail!(
Expand All @@ -3504,7 +3504,7 @@ where
}

// Construct the result type.
let result_type = RefType::indexed_func(false, dst_index).unwrap(); // TODO(dhil): proper error handling
let result_type = RefType::indexed_func(false, dst_index).expect("type index is too large");

// Push the continuation reference.
self.push_operand(result_type)?;
Expand All @@ -3523,7 +3523,8 @@ where
}
fn visit_resume(&mut self, type_index: u32, resumetable: ResumeTable) -> Self::Output {
let ctft = self.func_repr_cont_type_at(type_index)?;
let expected = ValType::Ref(RefType::indexed_func(true, type_index).unwrap()); // TODO(dhil): proper error handling
let expected =
ValType::Ref(RefType::indexed_func(true, type_index).expect("type index is too large"));
match self.pop_ref()? {
None => {}
Some(rt) if self.resources.matches(ValType::Ref(rt), expected) => {
Expand Down Expand Up @@ -3558,7 +3559,8 @@ where
resumetable: ResumeTable,
) -> Self::Output {
let ctft = self.func_repr_cont_type_at(type_index)?;
let expected = ValType::Ref(RefType::indexed_func(true, type_index).unwrap()); // TODO(dhil): proper error handling
let expected =
ValType::Ref(RefType::indexed_func(true, type_index).expect("type index is too large"));
match self.pop_ref()? {
None => {}
Some(rt) if self.resources.matches(ValType::Ref(rt), expected) => {
Expand Down

0 comments on commit 6a0d990

Please sign in to comment.