mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Copy exception variables when splitting async programs. Fix https://github.com/konsoletyper/teavm/issues/230
This commit is contained in:
parent
58563a3e2d
commit
f6103ec00b
|
@ -95,6 +95,10 @@ public class AsyncProgramSplitter {
|
|||
|
||||
// If we met asynchronous invocation...
|
||||
// Copy portion of current block from last occurrence (or from start) to i'th instruction.
|
||||
if (sourceBlock.getExceptionVariable() != null) {
|
||||
targetBlock.setExceptionVariable(targetBlock.getProgram().variableAt(
|
||||
sourceBlock.getExceptionVariable().getIndex()));
|
||||
}
|
||||
targetBlock.addAll(ProgramUtils.copyInstructions(last, insn, targetBlock.getProgram()));
|
||||
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock,
|
||||
targetBlock.getProgram()));
|
||||
|
@ -140,6 +144,11 @@ public class AsyncProgramSplitter {
|
|||
step.targetPart = part;
|
||||
part.originalBlocks[targetBlock.getIndex()] = step.source;
|
||||
}
|
||||
|
||||
if (sourceBlock.getExceptionVariable() != null) {
|
||||
targetBlock.setExceptionVariable(targetBlock.getProgram().variableAt(
|
||||
sourceBlock.getExceptionVariable().getIndex()));
|
||||
}
|
||||
targetBlock.addAll(ProgramUtils.copyInstructions(last, null, targetBlock.getProgram()));
|
||||
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock, targetBlock.getProgram()));
|
||||
targetBlock.setExceptionVariable(sourceBlock.getExceptionVariable());
|
||||
|
|
|
@ -165,12 +165,28 @@ public class VMTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SkipJVM
|
||||
public void asyncExceptionHandler() {
|
||||
try {
|
||||
throw new RuntimeException("OK");
|
||||
} catch (RuntimeException e) {
|
||||
assertEquals("OK", suspendAndReturn(e).getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
private static native void throwExceptionAsync();
|
||||
private static void throwExceptionAsync(AsyncCallback<Void> callback) {
|
||||
callback.error(new RuntimeException("OK"));
|
||||
}
|
||||
|
||||
@Async
|
||||
private static native <T> T suspendAndReturn(T value);
|
||||
private static <T> void suspendAndReturn(T value, AsyncCallback<T> callback) {
|
||||
callback.complete(value);
|
||||
}
|
||||
|
||||
@JSBody(script = "return [1, 2]")
|
||||
private static native int[] createArray();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user