From b3f662327ca6eb329093a274823296b314190169 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 16 Apr 2015 23:09:32 +0300 Subject: [PATCH] Fix bug in try/catch generator --- .../main/java/org/teavm/javascript/Decompiler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java index 73e5569db..f2f1f2ea6 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Decompiler.java @@ -370,6 +370,8 @@ public class Decompiler { generator.nextBlock = tmp >= 0 && next < indexer.size() ? program.basicBlockAt(tmp) : null; } + closeExpiredBookmarks(generator, generator.currentBlock.getTryCatchBlocks()); + List inheritedBookmarks = new ArrayList<>(); Block block = stack.peek(); while (block.end == i) { @@ -419,8 +421,7 @@ public class Decompiler { stack.push(newBlock); block = newBlock; } - - updateTryCatchBookmarks(generator, generator.currentBlock.getTryCatchBlocks()); + createNewBookmarks(generator.currentBlock.getTryCatchBlocks()); if (node >= 0) { generator.statements.clear(); @@ -453,7 +454,7 @@ public class Decompiler { return result; } - private void updateTryCatchBookmarks(StatementGenerator generator, List tryCatchBlocks) { + private void closeExpiredBookmarks(StatementGenerator generator, List tryCatchBlocks) { tryCatchBlocks = new ArrayList<>(tryCatchBlocks); Collections.reverse(tryCatchBlocks); @@ -510,8 +511,11 @@ public class Decompiler { tryCatchBookmarks.subList(start, tryCatchBookmarks.size()).clear(); + } + + private void createNewBookmarks(List tryCatchBlocks) { // Add new bookmarks - for (int i = start; i < tryCatchBlocks.size(); ++i) { + for (int i = tryCatchBookmarks.size(); i < tryCatchBlocks.size(); ++i) { TryCatchBlock tryCatch = tryCatchBlocks.get(i); TryCatchBookmark bookmark = new TryCatchBookmark(); bookmark.block = stack.peek();