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;
/**
*
* @author Alexey Andreev
*/
public class DependencyType {
private DependencyChecker dependencyChecker;
private String name;
int index;
public DependencyType(DependencyChecker dependencyChecker, String name, int index) {
DependencyType(DependencyChecker dependencyChecker, String name, int index) {
this.dependencyChecker = dependencyChecker;
this.name = name;
this.index = index;

View File

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

View File

@ -31,6 +31,7 @@ import org.teavm.dependency.DependencyPlugin;
import org.teavm.dependency.MethodDependency;
import org.teavm.model.CallLocation;
import org.teavm.model.ClassReader;
import org.teavm.model.ElementModifier;
import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
@ -176,7 +177,7 @@ public class JSNativeGenerator implements Injector, DependencyPlugin, Generator
case "instantiate":
case "function":
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;
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()) {
return;
}
ClassReader cls = agent.getClassSource().get(type);
if (cls != null) {
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.MethodReference;
/**
*
* @author Alexey Andreev
*/
public class JSObjectClassTransformer implements ClassHolderTransformer {
private JSClassProcessor processor;
private JSBodyRepository repository;