diff --git a/CHANGELOG.md b/CHANGELOG.md index cf06e7af0..73f5f585b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - GFX: Correct refreshing image when raw editing DefineExternalImage/2, DefineSubImage - GFX: DefineExternalImage/2, DefineSubImage disallow not working replace button in favor of raw editing - [#1795] AS3 P-code - optional (default parameter values) saving +- [#1785] AS1/2 try..catch block in for..in ## [16.0.4] - 2022-11-03 ### Fixed @@ -2484,6 +2485,7 @@ All notable changes to this project will be documented in this file. [#1857]: https://www.free-decompiler.com/flash/issues/1857 [#1818]: https://www.free-decompiler.com/flash/issues/1818 [#1795]: https://www.free-decompiler.com/flash/issues/1795 +[#1785]: https://www.free-decompiler.com/flash/issues/1785 [#1860]: https://www.free-decompiler.com/flash/issues/1860 [#1782]: https://www.free-decompiler.com/flash/issues/1782 [#1679]: https://www.free-decompiler.com/flash/issues/1679 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java index a0628fbbe..2fdd60a97 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf7/ActionTry.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.LocalDataArea; import com.jpexs.decompiler.flash.action.model.CastOpActionItem; import com.jpexs.decompiler.flash.action.model.DefineLocalActionItem; import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; +import com.jpexs.decompiler.flash.action.model.TemporaryRegister; import com.jpexs.decompiler.flash.action.model.clauses.TryActionItem; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParsedSymbol; @@ -290,7 +291,6 @@ public class ActionTry extends Action implements GraphSourceItemContainer { if (catchBlockFlag) { List body = contents.get(1); if (catchInRegisterFlag) { - //catchName = new DirectValueActionItem(this, lineStartItem, -1, new RegisterNumber(this.catchRegister), new ArrayList<>()); if (body.size() >= 2) { int pos = 0; loopex: @@ -298,9 +298,20 @@ public class ActionTry extends Action implements GraphSourceItemContainer { PushItem pi = (PushItem) body.get(pos); if (pi.value instanceof CastOpActionItem) { CastOpActionItem co = (CastOpActionItem) pi.value; - if ((co.object instanceof DirectValueActionItem) && (((DirectValueActionItem) co.object).value instanceof RegisterNumber)) { - RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) co.object).value; - if (rn.number == catchRegister) { + if (((co.object instanceof DirectValueActionItem) && (((DirectValueActionItem) co.object).value instanceof RegisterNumber)) + || (co.object instanceof TemporaryRegister) //Can be in for in loop + ) { + int regNumber; + + if (co.object instanceof TemporaryRegister) { + TemporaryRegister tr = (TemporaryRegister) co.object; + regNumber = tr.getRegId(); + } else { + RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) co.object).value; + regNumber = rn.number; + } + + if (regNumber == catchRegister) { catchExceptionTypes.add(co.constructor); if (body.get(pos + 1) instanceof IfItem) { IfItem ifi = (IfItem) body.get(pos + 1); @@ -348,11 +359,17 @@ public class ActionTry extends Action implements GraphSourceItemContainer { } } } - } + break; + } else { + break; } + } else { + break; } + } else { + break; } } if (body.get(pos) instanceof DefineLocalActionItem) { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java index 52d65f3ed..46bc84fe3 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -2393,4 +2393,21 @@ public class ActionScript2Test extends ActionScript2TestBase { + "var b = 5.2.toString();\r\n" ); } + + @Test + public void frame86_tryInsideForInTest() { + compareSrc(86, "trace(\"tryInsideForInTest\");\r\n" + + "var obj = {};\r\n" + + "for(var thing in obj)\r\n" + + "{\r\n" + + "try\r\n" + + "{\r\n" + + "trace(\"a\");\r\n" + + "}\r\n" + + "catch(error:Object)\r\n" + + "{\r\n" + + "}\r\n" + + "}\r\n" + ); + } } diff --git a/libsrc/ffdec_lib/testdata/as2/as2.fla b/libsrc/ffdec_lib/testdata/as2/as2.fla index ebcc85512..2e34c6cc5 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.fla and b/libsrc/ffdec_lib/testdata/as2/as2.fla differ diff --git a/libsrc/ffdec_lib/testdata/as2/as2.swf b/libsrc/ffdec_lib/testdata/as2/as2.swf index d2e3f2c37..346501e75 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.swf and b/libsrc/ffdec_lib/testdata/as2/as2.swf differ