Fixed #2148 AS2 Do not return undefined for setters

This commit is contained in:
Jindra Petřík
2023-12-10 22:52:49 +01:00
parent aee41c70db
commit 423a2abef8
3 changed files with 25 additions and 0 deletions

View File

@@ -79,6 +79,7 @@ All notable changes to this project will be documented in this file.
- AS3 - Nullpointer in MethodBody when no ABC set
- [#2148] AS2 Uninitialized class fields detector
- [#2148] AS1/2 callmethod by register value
- [#2148] AS2 Do not return undefined for setters
### Changed
- [#2120] Exported assets no longer take names from assigned classes if there is more than 1 assigned class

View File

@@ -37,7 +37,9 @@ import com.jpexs.decompiler.flash.action.model.clauses.ClassActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.InterfaceActionItem;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.ecma.Undefined;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.model.CommaExpressionItem;
import com.jpexs.decompiler.graph.model.IfItem;
@@ -620,6 +622,25 @@ public class ActionScript2ClassDetector {
func.isSetter = true;
if (FunctionActionItem.DECOMPILE_GET_SET) {
AbstractGraphTargetVisitor visitor = new AbstractGraphTargetVisitor() {
@Override
public void visit(GraphTargetItem item) {
if (item instanceof ReturnActionItem) {
ReturnActionItem ret = (ReturnActionItem) item;
if (ret.value instanceof DirectValueActionItem) {
DirectValueActionItem dv = (DirectValueActionItem) ret.value;
if (dv.value instanceof Undefined) {
ret.value = null;
}
}
}
}
};
for (GraphTargetItem ti : func.actions) {
ti.visitRecursively(visitor);
}
//There is return getter added at the end of every setter, gotta remove it, since it won't compile
//as setter must not return a value
if (!func.actions.isEmpty()) {

View File

@@ -52,6 +52,9 @@ public class ReturnActionItem extends ActionItem implements ExitItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (value == null) {
return writer.append("return");
}
writer.append("return ");
return value.toString(writer, localData);
}