Skip to content

Commit

Permalink
Fix return value from find_handler_active
Browse files Browse the repository at this point in the history
This is supposed to be returning the offset of the activation, but was returning the offset in the valstack for a particular frame

(That this was not caught says we still have insufficient test coverage on exception handling)
  • Loading branch information
rdaum committed Jul 6, 2024
1 parent 4040de8 commit 2ef9dc3
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/kernel/src/vm/vm_unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,27 @@ impl VMExecState {
// Scan activation frames and their stacks, looking for the first catch handler that matches
// the error code.
// Iterate backwards.
for activation in self.stack.iter().rev() {
for (a, activation) in self.stack.iter().rev().enumerate() {
// Skip non-MOO frames, they can't have catch handlers.
let Frame::Moo(ref frame) = activation.frame else {
continue;
};
for handler in &frame.handler_stack {
if let HandlerType::Catch(cnt) = handler.handler_type {
// Found one, now scan forwards from 'cnt' backwards in the valstack looking for either the first
// non-list value, or a list containing the error code.
// TODO check for 'cnt' being too large. not sure how to handle, tho
// TODO this actually i think is wrong, it needs to pull two values off the stack
let i = handler.valstack_pos;
for j in (i - cnt)..i {
if let Variant::List(codes) = &frame.valstack[j].variant() {
if !codes.contains(&v_err(raise_code)) {
continue;
}
let HandlerType::Catch(cnt) = handler.handler_type else {
continue;
};
// Found one, now scan forwards from 'cnt' backwards in the valstack looking for either the first
// non-list value, or a list containing the error code.
// TODO check for 'cnt' being too large. not sure how to handle, tho
// TODO this actually i think is wrong, it needs to pull two values off the stack
let i = handler.valstack_pos;
for j in (i - cnt)..i {
if let Variant::List(codes) = &frame.valstack[j].variant() {
if !codes.contains(&v_err(raise_code)) {
continue;
}
return Some(i);
}
return Some(a);
}
}
}
Expand Down

0 comments on commit 2ef9dc3

Please sign in to comment.