Skip to content

Commit

Permalink
Cleanup vm stack on function return
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Mar 1, 2022
1 parent 3fe7d09 commit 5737cd9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,8 @@ impl Context {
);
}

let start_stack_size = self.vm.stack.len();

while self.vm.frame().pc < self.vm.frame().code.code.len() {
let result = if self.vm.trace {
let mut pc = self.vm.frame().pc;
Expand Down Expand Up @@ -1496,6 +1498,7 @@ impl Context {
match result {
Ok(ShouldExit::True) => {
let result = self.vm.pop();
self.vm.stack.truncate(start_stack_size);
return Ok((result, ReturnType::Normal));
}
Ok(ShouldExit::False) => {}
Expand Down Expand Up @@ -1543,6 +1546,7 @@ impl Context {
self.vm.frame_mut().finally_return = FinallyReturn::Err;
self.vm.push(e);
} else {
self.vm.stack.truncate(start_stack_size);
return Err(e);
}
}
Expand Down Expand Up @@ -1576,6 +1580,8 @@ impl Context {
return Ok((JsValue::undefined(), ReturnType::Normal));
}

Ok((self.vm.pop(), ReturnType::Normal))
let result = self.vm.pop();
self.vm.stack.truncate(start_stack_size);
Ok((result, ReturnType::Normal))
}
}

0 comments on commit 5737cd9

Please sign in to comment.