Skip to content

Commit

Permalink
fix(vm): off-by-one in code block stringification. (#1999)
Browse files Browse the repository at this point in the history
Acked-by: Taylor Sutton <[email protected]>

This Pull Request fixes/closes #1998 

The call to retrieve operands modifies pc, setting it to the index of
the *next* instruction. So, we save its initial value and use that
for printing.
  • Loading branch information
tsutton committed Apr 2, 2022
1 parent f233e9c commit 998a7b1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion boa_engine/src/vm/code_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ impl ToInternedString for CodeBlock {
while pc < self.code.len() {
let opcode: Opcode = self.code[pc].try_into().expect("invalid opcode");
let opcode = opcode.as_str();
let previous_pc = pc;
let operands = self.instruction_operands(&mut pc, interner);
f.push_str(&format!(
"{pc:06} {count:04} {opcode:<27}{operands}\n",
"{previous_pc:06} {count:04} {opcode:<27}{operands}\n",
));
count += 1;
}
Expand Down

0 comments on commit 998a7b1

Please sign in to comment.