Fixed tests.

This commit is contained in:
Jindra Petřík
2025-09-30 21:39:32 +02:00
parent dccf870ce0
commit 5db66ae32b
7 changed files with 81 additions and 4 deletions

View File

@@ -1871,10 +1871,27 @@ public class AVM2Graph extends Graph {
}
List<GraphTargetItem> caseValuesMap = caseValuesMapLeft;
//Only handle switches with more than 2 branches
if (caseValuesMap.size() <= 2) {
stack.push(set);
return ret;
//It's not switch, it's an If
if (caseBodyParts.size() == 2) {
boolean isIf = false;
for (GraphPart r : part.refs) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates, false)) {
isIf = true;
break;
}
}
if (!isIf) {
for (GraphPart r : caseBodyParts.get(1).refs) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates, false)) {
isIf = true;
break;
}
}
}
if (isIf) {
stack.push(firstSet);
return ret;
}
}
//determine whether local register are on left or on right side of === operator

View File

@@ -1246,6 +1246,24 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile
false);
}
@Test
public void testIfInsteadSwitch() {
decompileMethod("classic_air", "testIfInsteadSwitch", "var a:int = 5;\r\n"
+ "if(a > 5)\r\n"
+ "{\r\n"
+ "if(a === 0)\r\n"
+ "{\r\n"
+ "trace(\"X\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "if(a === 1)\r\n"
+ "{\r\n"
+ "return \"A\";\r\n"
+ "}\r\n"
+ "return \"B\";\r\n",
false);
}
@Test
public void testIfTry() {
decompileMethod("classic_air", "testIfTry", "var c:int = 0;\r\n"

View File

@@ -1245,6 +1245,24 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
false);
}
@Test
public void testIfInsteadSwitch() {
decompileMethod("classic", "testIfInsteadSwitch", "var a:int = 5;\r\n"
+ "if(a > 5)\r\n"
+ "{\r\n"
+ "if(a === 0)\r\n"
+ "{\r\n"
+ "trace(\"X\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "if(a === 1)\r\n"
+ "{\r\n"
+ "return \"A\";\r\n"
+ "}\r\n"
+ "return \"B\";\r\n",
false);
}
@Test
public void testIfTry() {
decompileMethod("classic", "testIfTry", "var c:int = 0;\r\n"

View File

@@ -78,6 +78,7 @@ package
TestIfElse;
TestIfFinally;
TestIfInIf;
TestIfInsteadSwitch;
TestIfTry;
TestIgnoreAndOr;
TestImplicitCoerce;

View File

@@ -0,0 +1,23 @@
package tests
{
public class TestIfInsteadSwitch
{
public function run():*
{
var a:int = 5;
if(a > 5)
{
if(a === 0)
{
trace("X");
}
}
if(a === 1)
{
return "A";
}
return "B";
}
}
}