AS3 direct edit: Try..catch in constructor fix

Namespace resolving fix
This commit is contained in:
Jindra Petřík
2015-11-08 22:46:52 +01:00
parent d61bce6bb8
commit b98afed19b
5 changed files with 21 additions and 10 deletions

View File

@@ -862,13 +862,11 @@ public class ABC {
return bodyIdxFromMethodIdx;
}
public DottedChain nsValueToName(DottedChain value) {
if (value == null) {
return null;
public DottedChain nsValueToName(String valueStr) {
if (valueStr == null) {
return DottedChain.EMPTY;
}
String valueStr = value.toRawString();
if (getNamespaceMap().containsKey(valueStr)) {
return getNamespaceMap().get(valueStr);
} else {

View File

@@ -1226,10 +1226,10 @@ public class AVM2SourceGenerator implements SourceGenerator {
MethodBody initBody = null;
if (!isInterface) {
initBody = abcIndex.getSelectedAbc().findBody(init);
initBody.getCode().code.addAll(constructor == null ? 0 : 2, initcode);//after getlocal0,pushscope
initBody.insertAll(constructor == null ? 0 : 2, initcode);//after getlocal0,pushscope
if (sinitBody.getCode().code.get(sinitBody.getCode().code.size() - 1).definition instanceof ReturnVoidIns) {
sinitBody.getCode().code.addAll(2, sinitcode); //after getlocal0,pushscope
sinitBody.insertAll(2, sinitcode); //after getlocal0,pushscope
}
}
sinitBody.markOffsets();

View File

@@ -227,6 +227,12 @@ public final class MethodBody implements Cloneable {
getCode().insertInstruction(pos, instruction, this);
}
public void insertAll(int pos, List<AVM2Instruction> list) {
for (AVM2Instruction ins : list) {
insertInstruction(pos++, ins);
}
}
/**
* Inserts instruction at specified point. Handles offsets properly. Note:
* If newinstruction is jump, the offset operand must be handled properly by

View File

@@ -131,13 +131,17 @@ public abstract class Trait implements Cloneable, Serializable {
if (link_ns_index <= 0) {
return null;
}
DottedChain name = abc.constants.getNamespace(link_ns_index).getName(abc.constants);
Namespace ns = abc.constants.getNamespace(link_ns_index);
if (ns.kind != Namespace.KIND_NAMESPACE) {
return null;
}
String name = abc.constants.getString(ns.name_index);
for (ABCContainerTag abcTag : abc.getAbcTags()) {
DottedChain dc = abcTag.getABC().nsValueToName(name);
nsname = dc.getLast();
if (nsname == null) {
break;
continue;
}
if (!nsname.isEmpty()) {
return dc;

View File

@@ -104,6 +104,8 @@ public class TraitClass extends Trait implements TraitWithSlot {
}
boolean raw = ns.kind == Namespace.KIND_NAMESPACE;
DottedChain newimport = ns.getName(abc.constants);
//Note: Following is weird and probably wrong - FIXIT!
/*if ((ns.kind != Namespace.KIND_PACKAGE)
&& (ns.kind != Namespace.KIND_NAMESPACE)
&& (ns.kind != Namespace.KIND_STATIC_PROTECTED)) {
@@ -113,7 +115,8 @@ public class TraitClass extends Trait implements TraitWithSlot {
DottedChain oldimport = newimport;
newimport = new DottedChain();
for (ABCContainerTag abcTag : abc.getAbcTags()) {
DottedChain newname = abcTag.getABC().nsValueToName(oldimport);
DottedChain newname = abcTag.getABC().nsValueToName(oldimport.toRawString()); /* why this? */
if (newname.size() == 1 && newname.get(0).equals("-")) {
return true;
}