mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -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...
|
// If we met asynchronous invocation...
|
||||||
// Copy portion of current block from last occurrence (or from start) to i'th instruction.
|
// 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.addAll(ProgramUtils.copyInstructions(last, insn, targetBlock.getProgram()));
|
||||||
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock,
|
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock,
|
||||||
targetBlock.getProgram()));
|
targetBlock.getProgram()));
|
||||||
|
@ -140,6 +144,11 @@ public class AsyncProgramSplitter {
|
||||||
step.targetPart = part;
|
step.targetPart = part;
|
||||||
part.originalBlocks[targetBlock.getIndex()] = step.source;
|
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.addAll(ProgramUtils.copyInstructions(last, null, targetBlock.getProgram()));
|
||||||
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock, targetBlock.getProgram()));
|
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock, targetBlock.getProgram()));
|
||||||
targetBlock.setExceptionVariable(sourceBlock.getExceptionVariable());
|
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
|
@Async
|
||||||
private static native void throwExceptionAsync();
|
private static native void throwExceptionAsync();
|
||||||
private static void throwExceptionAsync(AsyncCallback<Void> callback) {
|
private static void throwExceptionAsync(AsyncCallback<Void> callback) {
|
||||||
callback.error(new RuntimeException("OK"));
|
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]")
|
@JSBody(script = "return [1, 2]")
|
||||||
private static native int[] createArray();
|
private static native int[] createArray();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user