mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix nested exception handlers
This commit is contained in:
parent
23c25c5d6e
commit
105c188953
|
@ -493,8 +493,15 @@ public class Decompiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close old bookmarks
|
// Close old bookmarks
|
||||||
|
List<TryCatchBookmark> removedBookmarks = new ArrayList<>();
|
||||||
for (int i = tryCatchBookmarks.size() - 1; i >= start; --i) {
|
for (int i = tryCatchBookmarks.size() - 1; i >= start; --i) {
|
||||||
TryCatchBookmark bookmark = tryCatchBookmarks.get(i);
|
TryCatchBookmark bookmark = tryCatchBookmarks.get(i);
|
||||||
|
bookmark.block.tryCatches.remove(bookmark);
|
||||||
|
removedBookmarks.add(bookmark);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.reverse(removedBookmarks);
|
||||||
|
for (TryCatchBookmark bookmark : removedBookmarks) {
|
||||||
Block block = stack.peek();
|
Block block = stack.peek();
|
||||||
while (block != bookmark.block) {
|
while (block != bookmark.block) {
|
||||||
TryCatchStatement tryCatchStmt = new TryCatchStatement();
|
TryCatchStatement tryCatchStmt = new TryCatchStatement();
|
||||||
|
@ -509,7 +516,6 @@ public class Decompiler {
|
||||||
}
|
}
|
||||||
block = block.parent;
|
block = block.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
TryCatchStatement tryCatchStmt = new TryCatchStatement();
|
TryCatchStatement tryCatchStmt = new TryCatchStatement();
|
||||||
tryCatchStmt.setExceptionType(bookmark.exceptionType);
|
tryCatchStmt.setExceptionType(bookmark.exceptionType);
|
||||||
tryCatchStmt.setExceptionVariable(bookmark.exceptionVariable);
|
tryCatchStmt.setExceptionVariable(bookmark.exceptionVariable);
|
||||||
|
@ -523,18 +529,15 @@ public class Decompiler {
|
||||||
if (!tryCatchStmt.getProtectedBody().isEmpty()) {
|
if (!tryCatchStmt.getProtectedBody().isEmpty()) {
|
||||||
blockPart.add(tryCatchStmt);
|
blockPart.add(tryCatchStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bookmark.block.tryCatches.remove(bookmark);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tryCatchBookmarks.subList(start, tryCatchBookmarks.size()).clear();
|
tryCatchBookmarks.subList(start, tryCatchBookmarks.size()).clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNewBookmarks(List<TryCatchBlock> tryCatchBlocks) {
|
private void createNewBookmarks(List<TryCatchBlock> tryCatchBlocks) {
|
||||||
// Add new bookmarks
|
// Add new bookmarks
|
||||||
for (int i = tryCatchBookmarks.size(); i < tryCatchBlocks.size(); ++i) {
|
for (int i = tryCatchBookmarks.size(); i < tryCatchBlocks.size(); ++i) {
|
||||||
TryCatchBlock tryCatch = tryCatchBlocks.get(i);
|
TryCatchBlock tryCatch = tryCatchBlocks.get(tryCatchBlocks.size() - 1 - i);
|
||||||
TryCatchBookmark bookmark = new TryCatchBookmark();
|
TryCatchBookmark bookmark = new TryCatchBookmark();
|
||||||
bookmark.block = stack.peek();
|
bookmark.block = stack.peek();
|
||||||
bookmark.offset = bookmark.block.body.size();
|
bookmark.offset = bookmark.block.body.size();
|
||||||
|
|
|
@ -82,6 +82,25 @@ public class VMTest {
|
||||||
assertEquals(23, a);
|
assertEquals(23, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void emptyTryCatchInsideFinally() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
try {
|
||||||
|
sb.append("before;");
|
||||||
|
try {
|
||||||
|
sb.append("inside;");
|
||||||
|
Integer.parseInt("not a number");
|
||||||
|
sb.append("ignore;");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
sb.append("after;");
|
||||||
|
} finally {
|
||||||
|
sb.append("finally;");
|
||||||
|
}
|
||||||
|
assertEquals("before;inside;after;finally;", sb.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void surrogateInStringLiteralsWork() {
|
public void surrogateInStringLiteralsWork() {
|
||||||
assertEquals(0xDDC2, "a\uDDC2b".charAt(1));
|
assertEquals(0xDDC2, "a\uDDC2b".charAt(1));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user