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
14 changes: 7 additions & 7 deletions crates/wasmparser/src/binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ impl<'a> BinaryReader<'a> {
}

#[inline]
fn expect_frame(&mut self, stack: &impl FrameStack, k: &FrameKind, found: &str) -> Result<()> {
fn expect_frame(&mut self, stack: &impl FrameStack, k: FrameKind, found: &str) -> Result<()> {
if stack.current_frame() == Some(k) {
return Ok(());
}
Expand Down Expand Up @@ -918,7 +918,7 @@ impl<'a> BinaryReader<'a> {
0x03 => visitor.visit_loop(self.read_block_type()?),
0x04 => visitor.visit_if(self.read_block_type()?),
0x05 => {
self.expect_frame(visitor, &FrameKind::If, "else")?;
self.expect_frame(visitor, FrameKind::If, "else")?;
visitor.visit_else()
}
0x06 => {
Expand All @@ -937,9 +937,9 @@ impl<'a> BinaryReader<'a> {
"legacy_exceptions feature required for catch instruction"
);
}
match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch") {
match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch") {
Ok(()) => (),
Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch")?,
Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch")?,
}
visitor.visit_catch(self.read_var_u32()?)
}
Expand All @@ -962,7 +962,7 @@ impl<'a> BinaryReader<'a> {
0x14 => visitor.visit_call_ref(self.read()?),
0x15 => visitor.visit_return_call_ref(self.read()?),
0x18 => {
self.expect_frame(visitor, &FrameKind::LegacyTry, "delegate")?;
self.expect_frame(visitor, FrameKind::LegacyTry, "delegate")?;
visitor.visit_delegate(self.read_var_u32()?)
}
0x19 => {
Expand All @@ -972,9 +972,9 @@ impl<'a> BinaryReader<'a> {
"legacy_exceptions feature required for catch_all instruction"
);
}
match self.expect_frame(visitor, &FrameKind::LegacyCatch, "catch_all") {
match self.expect_frame(visitor, FrameKind::LegacyCatch, "catch_all") {
Ok(()) => (),
Err(_) => self.expect_frame(visitor, &FrameKind::LegacyTry, "catch_all")?,
Err(_) => self.expect_frame(visitor, FrameKind::LegacyTry, "catch_all")?,
}
visitor.visit_catch_all()
}
Expand Down
16 changes: 8 additions & 8 deletions crates/wasmparser/src/readers/core/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ crate::for_each_operator!(define_operator);
/// requirements of the binary format.
pub trait FrameStack {
/// The current frame kind.
fn current_frame(&self) -> Option<&FrameKind>;
fn current_frame(&self) -> Option<FrameKind>;
}

/// Adapters from VisitOperators to FrameStacks
Expand All @@ -348,8 +348,8 @@ struct FrameStackAdapter<'a, T> {
}

impl<T> FrameStack for FrameStackAdapter<'_, T> {
fn current_frame(&self) -> Option<&FrameKind> {
self.stack.last()
fn current_frame(&self) -> Option<FrameKind> {
self.stack.last().copied()
}
}

Expand All @@ -359,8 +359,8 @@ struct SingleFrameAdapter<'a, T> {
}

impl<T> FrameStack for SingleFrameAdapter<'_, T> {
fn current_frame(&self) -> Option<&FrameKind> {
Some(&self.current_frame)
fn current_frame(&self) -> Option<FrameKind> {
Some(self.current_frame)
}
}

Expand Down Expand Up @@ -547,8 +547,8 @@ impl<'a> OperatorsReader<'a> {
}

impl<'a> FrameStack for OperatorsReader<'a> {
fn current_frame(&self) -> Option<&FrameKind> {
self.stack.last()
fn current_frame(&self) -> Option<FrameKind> {
self.stack.last().copied()
}
}

Expand Down Expand Up @@ -1051,7 +1051,7 @@ impl<'a> BinaryReader<'a> {
/// the `Operator`, or if the input is malformed.
pub fn peek_operator<T: FrameStack>(&self, stack: &T) -> Result<Operator<'a>> {
self.clone().visit_operator(&mut SingleFrameAdapter {
current_frame: *stack.current_frame().ok_or_else(|| {
current_frame: stack.current_frame().ok_or_else(|| {
format_err!(
self.original_position(),
"operators remaining after end of function body or expression"
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ impl ModuleState {
}

impl<'a> FrameStack for VisitConstOperator<'a> {
fn current_frame(&self) -> Option<&FrameKind> {
Some(&self.ops.get_frame(0)?.kind)
fn current_frame(&self) -> Option<FrameKind> {
Some(self.ops.get_frame(0)?.kind)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4380,7 +4380,7 @@ impl<R> FrameStack for WasmProposalValidator<'_, '_, R>
where
R: WasmModuleResources,
{
fn current_frame(&self) -> Option<&FrameKind> {
Some(&self.0.control.last()?.kind)
fn current_frame(&self) -> Option<FrameKind> {
Some(self.0.control.last()?.kind)
}
}