diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index ca68a2716..0a426fb6a 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1476,6 +1476,7 @@ func (v *VM) Call(ctx *Context, offset int) { newCtx.CheckReturn = false newCtx.local = nil newCtx.arguments = nil + newCtx.tryStack = NewStack("exception") v.istack.PushVal(newCtx) v.Jump(newCtx, offset) } @@ -1517,7 +1518,7 @@ func (v *VM) handleException() { pop := 0 ictx := v.istack.Peek(0).Value().(*Context) for ictx != nil { - e := ictx.tryStack.Peek(pop) + e := ictx.tryStack.Peek(0) for e != nil { ectx := e.Value().(*exceptionHandlingContext) if ectx.State == eFinally || (ectx.State == eCatch && !ectx.HasFinally()) { diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index 65c51e2d4..198d2183e 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1336,6 +1336,12 @@ func TestTRY(t *testing.T) { checkVMFailed(t, vm) }) }) + t.Run("ThrowInCall", func(t *testing.T) { + catchP := []byte{byte(opcode.CALL), 2, byte(opcode.PUSH1), byte(opcode.ADD), byte(opcode.THROW), byte(opcode.RET)} + inner := getTRYProgram(throw, catchP, []byte{byte(opcode.PUSH2)}) + // add 5 to the exception, mul to the result of inner finally (2) + getTRYTestFunc(47, inner, append(add5, byte(opcode.MUL)), add9)(t) + }) } func TestMEMCPY(t *testing.T) {