When copying basic blocks in async splitter, copy exception variable as well. Fix https://github.com/konsoletyper/teavm/issues/230

This commit is contained in:
Alexey Andreev 2017-01-24 23:59:54 +03:00
parent c7829a77cf
commit 02d8439920
3 changed files with 25 additions and 4 deletions

View File

@ -142,6 +142,7 @@ public class AsyncProgramSplitter {
}
targetBlock.addAll(ProgramUtils.copyInstructions(last, null, targetBlock.getProgram()));
targetBlock.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(sourceBlock, targetBlock.getProgram()));
targetBlock.setExceptionVariable(sourceBlock.getExceptionVariable());
for (TryCatchBlock tryCatch : targetBlock.getTryCatchBlocks()) {
if (tryCatch.getHandler() != null) {
Step next = new Step();

View File

@ -38,6 +38,7 @@ public class ProgramNodeSplittingBackend implements GraphSplittingBackend {
BasicBlock blockCopy = program.createBasicBlock();
blockCopy.addAll(ProgramUtils.copyInstructions(block.getFirstInstruction(), null, program));
blockCopy.getTryCatchBlocks().addAll(ProgramUtils.copyTryCatches(block, program));
blockCopy.setExceptionVariable(block.getExceptionVariable());
copies[i] = blockCopy.getIndex();
map.put(nodes[i], copies[i] + 1);
}
@ -45,11 +46,11 @@ public class ProgramNodeSplittingBackend implements GraphSplittingBackend {
int mappedIndex = map.get(block);
return mappedIndex == 0 ? block : mappedIndex - 1;
});
for (int i = 0; i < copies.length; ++i) {
copyBlockMapper.transform(program.basicBlockAt(copies[i]));
for (int copy : copies) {
copyBlockMapper.transform(program.basicBlockAt(copy));
}
for (int i = 0; i < domain.length; ++i) {
copyBlockMapper.transform(program.basicBlockAt(domain[i]));
for (int domainNode : domain) {
copyBlockMapper.transform(program.basicBlockAt(domainNode));
}
return copies;
}

View File

@ -18,9 +18,11 @@ package org.teavm.vm;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.teavm.interop.Async;
import org.teavm.jso.JSBody;
import org.teavm.junit.SkipJVM;
import org.teavm.junit.TeaVMTestRunner;
import org.teavm.platform.async.AsyncCallback;
@RunWith(TeaVMTestRunner.class)
public class VMTest {
@ -152,6 +154,23 @@ public class VMTest {
assertEquals(30, s);
}
@Test
@SkipJVM
public void asyncTryCatch() {
try {
throwExceptionAsync();
fail("Exception should have been thrown");
} catch (RuntimeException e) {
assertEquals("OK", e.getMessage());
}
}
@Async
private static native void throwExceptionAsync();
private static void throwExceptionAsync(AsyncCallback<Void> callback) {
callback.error(new RuntimeException("OK"));
}
@JSBody(script = "return [1, 2]")
private static native int[] createArray();