Skip to content

Commit 570202a

Browse files
committed
add bytecodeOffset to the Instruction object
1 parent 93030ad commit 570202a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/instruction-parser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ const opcodeMnemonics = [
4747
];
4848

4949
class Instruction {
50-
constructor(opcode, operands) {
50+
constructor(opcode, operands, bytecodeOffset) {
5151
if (typeof opcode !== 'number') throw TypeError('opcode must be a number');
5252
if (!Array.isArray(operands)) throw TypeError('operands must be an array');
5353

5454
this.opcode = opcode;
5555
this.operands = operands;
56+
this.bytecodeOffset = bytecodeOffset;
5657
}
5758

5859
toString() {
@@ -163,7 +164,7 @@ class InstructionParser {
163164

164165
while (offset < bytecode.length) {
165166
const current = bytecode[offset++];
166-
const instruction = new Instruction(current, []);
167+
const instruction = new Instruction(current, [], offset - 1);
167168

168169
switch (current) {
169170
// https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5.lookupswitch

0 commit comments

Comments
 (0)