mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fixing bugs in JSBody
This commit is contained in:
parent
712dfced8b
commit
4adf789142
|
@ -65,7 +65,7 @@ public final class ModelUtils {
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyAnnotations(AnnotationContainerReader src, AnnotationContainer dst) {
|
public static void copyAnnotations(AnnotationContainerReader src, AnnotationContainer dst) {
|
||||||
for (AnnotationReader annot : src.all()) {
|
for (AnnotationReader annot : src.all()) {
|
||||||
dst.add(copyAnnotation(annot));
|
dst.add(copyAnnotation(annot));
|
||||||
}
|
}
|
||||||
|
|
|
@ -479,7 +479,7 @@ public final class JS {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends JSObject> Iterable<String> iterate(final JSStringArrayReader array) {
|
public static Iterable<String> iterate(final JSStringArrayReader array) {
|
||||||
return new Iterable<String>() {
|
return new Iterable<String>() {
|
||||||
@Override public Iterator<String> iterator() {
|
@Override public Iterator<String> iterator() {
|
||||||
return new Iterator<String>() {
|
return new Iterator<String>() {
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class JSBodyGenerator implements Generator {
|
||||||
boolean isStatic = annot.getValue("isStatic").getBoolean();
|
boolean isStatic = annot.getValue("isStatic").getBoolean();
|
||||||
List<AnnotationValue> paramNames = annot.getValue("params").getList();
|
List<AnnotationValue> paramNames = annot.getValue("params").getList();
|
||||||
|
|
||||||
int bodyParamCount = method.parameterCount();
|
int bodyParamCount = isStatic ? method.parameterCount() : method.parameterCount() - 1;
|
||||||
int offset = isStatic ? 1 : 0;
|
int offset = isStatic ? 1 : 0;
|
||||||
|
|
||||||
writer.append("if (!").appendMethodBody(methodRef).append(".$native)").ws().append('{').indent().newLine();
|
writer.append("if (!").appendMethodBody(methodRef).append(".$native)").ws().append('{').indent().newLine();
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.teavm.jso.*;
|
||||||
import org.teavm.model.*;
|
import org.teavm.model.*;
|
||||||
import org.teavm.model.instructions.*;
|
import org.teavm.model.instructions.*;
|
||||||
import org.teavm.model.util.InstructionVariableMapper;
|
import org.teavm.model.util.InstructionVariableMapper;
|
||||||
|
import org.teavm.model.util.ModelUtils;
|
||||||
import org.teavm.model.util.ProgramUtils;
|
import org.teavm.model.util.ProgramUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +81,11 @@ class JavascriptNativeProcessor {
|
||||||
public void processFinalMethods(ClassHolder cls) {
|
public void processFinalMethods(ClassHolder cls) {
|
||||||
// TODO: don't allow final methods to override anything
|
// TODO: don't allow final methods to override anything
|
||||||
for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) {
|
for (MethodHolder method : cls.getMethods().toArray(new MethodHolder[0])) {
|
||||||
if (method.hasModifier(ElementModifier.FINAL) && method.getProgram() != null) {
|
if (method.hasModifier(ElementModifier.STATIC)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (method.hasModifier(ElementModifier.FINAL) && method.getProgram() != null &&
|
||||||
|
method.getProgram().basicBlockCount() > 0) {
|
||||||
ValueType[] staticSignature = getStaticSignature(method.getReference());
|
ValueType[] staticSignature = getStaticSignature(method.getReference());
|
||||||
MethodHolder callerMethod = new MethodHolder(new MethodDescriptor(method.getName() + "$static",
|
MethodHolder callerMethod = new MethodHolder(new MethodDescriptor(method.getName() + "$static",
|
||||||
staticSignature));
|
staticSignature));
|
||||||
|
@ -115,6 +120,7 @@ class JavascriptNativeProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callerMethod.setProgram(program);
|
callerMethod.setProgram(program);
|
||||||
|
ModelUtils.copyAnnotations(method.getAnnotations(), callerMethod.getAnnotations());
|
||||||
cls.addMethod(callerMethod);
|
cls.addMethod(callerMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,11 +194,13 @@ class JavascriptNativeProcessor {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.hasModifier(ElementModifier.FINAL)) {
|
if (method.hasModifier(ElementModifier.FINAL)) {
|
||||||
invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static",
|
if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) {
|
||||||
getStaticSignature(method.getReference())));
|
invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static",
|
||||||
|
getStaticSignature(method.getReference())));
|
||||||
|
invoke.getArguments().add(0, invoke.getInstance());
|
||||||
|
invoke.setInstance(null);
|
||||||
|
}
|
||||||
invoke.setType(InvocationType.SPECIAL);
|
invoke.setType(InvocationType.SPECIAL);
|
||||||
invoke.getArguments().add(0, invoke.getInstance());
|
|
||||||
invoke.setInstance(null);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CallLocation callLocation = new CallLocation(methodToProcess.getReference(), insn.getLocation());
|
CallLocation callLocation = new CallLocation(methodToProcess.getReference(), insn.getLocation());
|
||||||
|
@ -390,6 +398,9 @@ class JavascriptNativeProcessor {
|
||||||
for (int i = 0; i < paramCount; ++i) {
|
for (int i = 0; i < paramCount; ++i) {
|
||||||
params.add(program.createVariable());
|
params.add(program.createVariable());
|
||||||
}
|
}
|
||||||
|
if (isStatic) {
|
||||||
|
program.createVariable();
|
||||||
|
}
|
||||||
methodToProcess.setProgram(program);
|
methodToProcess.setProgram(program);
|
||||||
|
|
||||||
// Generate invoke instruction
|
// Generate invoke instruction
|
||||||
|
@ -398,7 +409,7 @@ class JavascriptNativeProcessor {
|
||||||
invoke.setType(InvocationType.SPECIAL);
|
invoke.setType(InvocationType.SPECIAL);
|
||||||
invoke.setMethod(proxyMethod.getReference());
|
invoke.setMethod(proxyMethod.getReference());
|
||||||
for (int i = 0; i < paramCount; ++i) {
|
for (int i = 0; i < paramCount; ++i) {
|
||||||
Variable var = program.createVariable();
|
Variable var = program.variableAt(isStatic ? i + 1 : i);
|
||||||
invoke.getArguments().add(wrapArgument(location, var, paramTypes[i]));
|
invoke.getArguments().add(wrapArgument(location, var, paramTypes[i]));
|
||||||
}
|
}
|
||||||
block.getInstructions().addAll(replacement);
|
block.getInstructions().addAll(replacement);
|
||||||
|
@ -580,7 +591,7 @@ class JavascriptNativeProcessor {
|
||||||
}
|
}
|
||||||
Variable result = program.createVariable();
|
Variable result = program.createVariable();
|
||||||
InvokeInstruction insn = new InvokeInstruction();
|
InvokeInstruction insn = new InvokeInstruction();
|
||||||
insn.setMethod(new MethodReference(JS.class.getName(), "wrap", type, getWrapperType(type)));
|
insn.setMethod(new MethodReference(JS.class.getName(), "wrap", getWrappedType(type), getWrapperType(type)));
|
||||||
insn.getArguments().add(var);
|
insn.getArguments().add(var);
|
||||||
insn.setReceiver(result);
|
insn.setReceiver(result);
|
||||||
insn.setType(InvocationType.SPECIAL);
|
insn.setType(InvocationType.SPECIAL);
|
||||||
|
@ -589,6 +600,21 @@ class JavascriptNativeProcessor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ValueType getWrappedType(ValueType type) {
|
||||||
|
if (type instanceof ValueType.Array) {
|
||||||
|
ValueType itemType = ((ValueType.Array)type).getItemType();
|
||||||
|
return ValueType.arrayOf(getWrappedType(itemType));
|
||||||
|
} else if (type instanceof ValueType.Object) {
|
||||||
|
if (type.isObject("java.lang.String")) {
|
||||||
|
return type;
|
||||||
|
} else {
|
||||||
|
return ValueType.parse(JSObject.class);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ValueType getWrapperType(ValueType type) {
|
private ValueType getWrapperType(ValueType type) {
|
||||||
if (type instanceof ValueType.Array) {
|
if (type instanceof ValueType.Array) {
|
||||||
ValueType itemType = ((ValueType.Array)type).getItemType();
|
ValueType itemType = ((ValueType.Array)type).getItemType();
|
||||||
|
|
|
@ -64,6 +64,11 @@ class NativeJavascriptClassRepository {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) {
|
||||||
|
if (isJavaScriptClass(cls.getParent())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user