Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Allow throw in SYSCALLs (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Jun 23, 2020
1 parent 446fd24 commit baf4989
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/neo-vm/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ private void ExecuteInstruction(Instruction instruction)
}
case OpCode.THROW:
{
UncaughtException = Pop();
HandleException();
Throw(Pop());
return;
}
case OpCode.TRY:
Expand Down Expand Up @@ -1448,5 +1447,11 @@ public void Push(StackItem item)
{
CurrentContext.EvaluationStack.Push(item);
}

public void Throw(StackItem ex)
{
UncaughtException = ex;
HandleException();
}
}
}
58 changes: 58 additions & 0 deletions tests/neo-vm.Tests/Tests/OpCodes/Control/TRY_CATCH.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,64 @@
"category": "Control",
"name": "TRY_CATCH",
"tests": [
{
"name": "try catch with syscall exception",
"script": [
"TRY",
"0x0a00",
"SYSCALL",
"0xdeaddead",
"ENDTRY",
"0x05",
"PUSH1",
"ENDTRY",
"0x02",
"PUSH2"
],
"steps": [
{
"actions": [
"stepInto",
"stepInto",
"stepInto"
],
"result": {
"state": "BREAK",
"invocationStack": [
{
"instructionPointer": 13,
"nextInstruction": "PUSH2",
"evaluationStack": [
{
"type": "ByteString",
"value": "0x6572726f72"
}
]
}
]
}
},
{
"actions": [
"stepInto",
"stepInto"
],
"result": {
"state": "HALT",
"resultStack": [
{
"type": "integer",
"value": 2
},
{
"type": "ByteString",
"value": "0x6572726f72"
}
]
}
}
]
},
{
"name": "try catch without exception",
"script": [
Expand Down
6 changes: 6 additions & 0 deletions tests/neo-vm.Tests/Types/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ protected override void OnSysCall(uint method)
return;
}

if (method == 0xaddeadde)
{
Throw("error");
return;
}

throw new System.Exception();
}
}
Expand Down

0 comments on commit baf4989

Please sign in to comment.