Issue #382 AS3 Fixed adding new method

This commit is contained in:
Jindra Pet��k
2013-09-28 08:42:42 +02:00
parent 8a187ab493
commit 2609cfa9e3
2 changed files with 18 additions and 2 deletions
@@ -67,8 +67,15 @@ public class ABC {
public int addMethodBody(MethodBody body) {
bodies = Arrays.copyOf(bodies, bodies.length + 1);
bodies[bodies.length - 1] = body;
bodyIdxFromMethodIdx = Arrays.copyOf(bodyIdxFromMethodIdx, bodyIdxFromMethodIdx.length + 1);
bodyIdxFromMethodIdx[bodyIdxFromMethodIdx.length - 1] = body.method_info;
if (body.method_info >= bodyIdxFromMethodIdx.length) {
int newlen = body.method_info + 1;
int oldlen = bodyIdxFromMethodIdx.length;
bodyIdxFromMethodIdx = Arrays.copyOf(bodyIdxFromMethodIdx, newlen);
for (int i = oldlen; i < newlen; i++) {
bodyIdxFromMethodIdx[i] = -1;
}
bodyIdxFromMethodIdx[body.method_info] = bodies.length - 1;
}
return bodies.length - 1;
}
@@ -22,6 +22,11 @@ import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.GetLocal0Ins;
import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ReturnVoidIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushScopeIns;
import com.jpexs.decompiler.flash.abc.avm2.parser.ASM3Parser;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
@@ -638,11 +643,15 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr
body.max_stack = 1;
body.exceptions = new ABCException[0];
AVM2Code code = new AVM2Code();
code.code.add(new AVM2Instruction(0, new GetLocal0Ins(), new int[0], new byte[0]));
code.code.add(new AVM2Instruction(0, new PushScopeIns(), new int[0], new byte[0]));
code.code.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[0], new byte[0]));
body.code = code;
Traits traits = new Traits();
traits.traits = new Trait[0];
body.traits = traits;
abc.addMethodBody(body);
mi.setBody(body);
t = tm;
break;
case Trait.TRAIT_SLOT: