Fix bug in JSO

This commit is contained in:
Alexey Andreev 2017-04-22 14:11:24 +03:00
parent 6144a4bd14
commit 058566e731
4 changed files with 19 additions and 27 deletions

View File

@ -15,16 +15,12 @@
*/ */
package org.teavm.dependency; package org.teavm.dependency;
/**
*
* @author Alexey Andreev
*/
public class DependencyType { public class DependencyType {
private DependencyChecker dependencyChecker; private DependencyChecker dependencyChecker;
private String name; private String name;
int index; int index;
public DependencyType(DependencyChecker dependencyChecker, String name, int index) { DependencyType(DependencyChecker dependencyChecker, String name, int index) {
this.dependencyChecker = dependencyChecker; this.dependencyChecker = dependencyChecker;
this.name = name; this.name = name;
this.index = index; this.index = index;

View File

@ -90,12 +90,7 @@ class JSDependencyListener extends AbstractDependencyListener {
} }
private ExposedClass getExposedClass(String name) { private ExposedClass getExposedClass(String name) {
ExposedClass cls = exposedClasses.get(name); return exposedClasses.computeIfAbsent(name, this::createExposedClass);
if (cls == null) {
cls = createExposedClass(name);
exposedClasses.put(name, cls);
}
return cls;
} }
private ExposedClass createExposedClass(String name) { private ExposedClass createExposedClass(String name) {
@ -111,15 +106,17 @@ class JSDependencyListener extends AbstractDependencyListener {
exposedCls.implementedInterfaces.addAll(parent.implementedInterfaces); exposedCls.implementedInterfaces.addAll(parent.implementedInterfaces);
} }
addInterfaces(exposedCls, cls); addInterfaces(exposedCls, cls);
for (MethodReader method : cls.getMethods()) { if (!cls.hasModifier(ElementModifier.ABSTRACT)) {
if (method.getName().equals("<init>")) { for (MethodReader method : cls.getMethods()) {
continue; if (method.getName().equals("<init>")) {
} continue;
if (exposedCls.inheritedMethods.containsKey(method.getDescriptor()) }
|| exposedCls.methods.containsKey(method.getDescriptor())) { if (exposedCls.inheritedMethods.containsKey(method.getDescriptor())
MethodDependency methodDep = agent.linkMethod(method.getReference(), null); || exposedCls.methods.containsKey(method.getDescriptor())) {
methodDep.getVariable(0).propagate(agent.getType(name)); MethodDependency methodDep = agent.linkMethod(method.getReference(), null);
methodDep.use(); methodDep.getVariable(0).propagate(agent.getType(name));
methodDep.use();
}
} }
} }
if (exposedCls.functorField == null) { if (exposedCls.functorField == null) {

View File

@ -31,6 +31,7 @@ import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency; import org.teavm.dependency.MethodDependency;
import org.teavm.model.CallLocation; import org.teavm.model.CallLocation;
import org.teavm.model.ClassReader; import org.teavm.model.ClassReader;
import org.teavm.model.ElementModifier;
import org.teavm.model.MethodReader; import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.ValueType; import org.teavm.model.ValueType;
@ -176,7 +177,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
case "instantiate": case "instantiate":
case "function": case "function":
for (int i = 0; i < method.getReference().parameterCount(); ++i) { for (int i = 0; i < method.getReference().parameterCount(); ++i) {
method.getVariable(i).addConsumer(type -> achieveFunctorMethods(agent, type.getName(), method)); method.getVariable(i).addConsumer(type -> reachFunctorMethods(agent, type.getName(), method));
} }
break; break;
case "unwrapString": case "unwrapString":
@ -185,14 +186,16 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
} }
} }
private void achieveFunctorMethods(DependencyAgent agent, String type, MethodDependency caller) { private void reachFunctorMethods(DependencyAgent agent, String type, MethodDependency caller) {
if (caller.isMissing()) { if (caller.isMissing()) {
return; return;
} }
ClassReader cls = agent.getClassSource().get(type); ClassReader cls = agent.getClassSource().get(type);
if (cls != null) { if (cls != null) {
for (MethodReader method : cls.getMethods()) { for (MethodReader method : cls.getMethods()) {
agent.linkMethod(method.getReference(), null).use(); if (!method.hasModifier(ElementModifier.STATIC)) {
agent.linkMethod(method.getReference(), null).use();
}
} }
} }
} }

View File

@ -22,10 +22,6 @@ import org.teavm.model.ClassReaderSource;
import org.teavm.model.MethodHolder; import org.teavm.model.MethodHolder;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
/**
*
* @author Alexey Andreev
*/
public class JSObjectClassTransformer implements ClassHolderTransformer { public class JSObjectClassTransformer implements ClassHolderTransformer {
private JSClassProcessor processor; private JSClassProcessor processor;
private JSBodyRepository repository; private JSBodyRepository repository;