Skip to content

Commit

Permalink
[core] Add CallFrame.setResultIfNoException()
Browse files Browse the repository at this point in the history
Also fix test when some test targets throwing exception but still shows success.
  • Loading branch information
canyie committed Dec 13, 2021
1 parent fdd4bd6 commit 16b5520
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Arg0Test() {

@Override public void afterCall(Pine.CallFrame callFrame) throws Throwable {
super.afterCall(callFrame);
callFrame.setResult(SUCCESS);
callFrame.setResultIfNoException(SUCCESS);
}

private static int target() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ private boolean target() {

@Override public void afterCall(Pine.CallFrame callFrame) throws Throwable {
super.afterCall(callFrame);
callFrame.setResult(true);
callFrame.setResultIfNoException(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public boolean target() {

@Override public void afterCall(Pine.CallFrame callFrame) throws Throwable {
super.afterCall(callFrame);
callFrame.setResult(true);
callFrame.setResultIfNoException(true);
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/top/canyie/pine/Pine.java
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,13 @@ public void setResult(Object result) {
this.returnEarly = true;
}

public void setResultIfNoException(Object result) {
if (this.throwable == null) {
this.result = result;
this.returnEarly = true;
}
}

public Throwable getThrowable() {
return throwable;
}
Expand Down

0 comments on commit 16b5520

Please sign in to comment.