wasm gc: fix failing tests

This commit is contained in:
Alexey Andreev 2024-09-29 10:53:55 +02:00
parent e966690284
commit 0897a1bbd5
3 changed files with 19 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Context; import org.mozilla.javascript.Context;
import org.mozilla.javascript.ast.AstRoot; import org.mozilla.javascript.ast.AstRoot;
@ -109,6 +110,7 @@ class JSClassProcessor {
private IncrementalDependencyRegistration incrementalCache; private IncrementalDependencyRegistration incrementalCache;
private JSImportAnnotationCache annotationCache; private JSImportAnnotationCache annotationCache;
private ClassReader objectClass; private ClassReader objectClass;
private Predicate<String> classFilter = n -> true;
JSClassProcessor(ClassReaderSource classSource, JSTypeHelper typeHelper, JSBodyRepository repository, JSClassProcessor(ClassReaderSource classSource, JSTypeHelper typeHelper, JSBodyRepository repository,
Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache, boolean strict) { Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache, boolean strict) {
@ -123,6 +125,10 @@ class JSClassProcessor {
annotationCache = new JSImportAnnotationCache(classSource, diagnostics); annotationCache = new JSImportAnnotationCache(classSource, diagnostics);
} }
public void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}
public ClassReaderSource getClassSource() { public ClassReaderSource getClassSource() {
return classSource; return classSource;
} }
@ -760,6 +766,9 @@ class JSClassProcessor {
private boolean processJSBodyInvocation(MethodReader method, CallLocation callLocation, InvokeInstruction invoke, private boolean processJSBodyInvocation(MethodReader method, CallLocation callLocation, InvokeInstruction invoke,
MethodHolder methodToProcess) { MethodHolder methodToProcess) {
if (!classFilter.test(method.getOwnerName())) {
return false;
}
boolean[] byRefParams = new boolean[method.parameterCount()]; boolean[] byRefParams = new boolean[method.parameterCount()];
validateSignature(method, callLocation, byRefParams); validateSignature(method, callLocation, byRefParams);
if (invoke.getInstance() != null) { if (invoke.getInstance() != null) {

View File

@ -39,7 +39,8 @@ public class JSOPlugin implements TeaVMPlugin {
JSBodyRepository repository = new JSBodyRepository(); JSBodyRepository repository = new JSBodyRepository();
host.registerService(JSBodyRepository.class, repository); host.registerService(JSBodyRepository.class, repository);
host.add(new JSObjectClassTransformer(repository)); var classTransformer = new JSObjectClassTransformer(repository);
host.add(classTransformer);
JSDependencyListener dependencyListener = new JSDependencyListener(repository); JSDependencyListener dependencyListener = new JSDependencyListener(repository);
host.add(dependencyListener); host.add(dependencyListener);
host.add(new JSExceptionsDependencyListener()); host.add(new JSExceptionsDependencyListener());
@ -59,6 +60,7 @@ public class JSOPlugin implements TeaVMPlugin {
} }
if (wasmGCHost != null) { if (wasmGCHost != null) {
classTransformer.setClassFilter(n -> !n.startsWith("java."));
WasmGCJso.install(host, wasmGCHost, repository); WasmGCJso.install(host, wasmGCHost, repository);
} }
} }

View File

@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate;
import org.teavm.diagnostics.Diagnostics; import org.teavm.diagnostics.Diagnostics;
import org.teavm.jso.JSClass; import org.teavm.jso.JSClass;
import org.teavm.jso.JSExport; import org.teavm.jso.JSExport;
@ -59,11 +60,16 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
private JSTypeHelper typeHelper; private JSTypeHelper typeHelper;
private ClassHierarchy hierarchy; private ClassHierarchy hierarchy;
private Map<String, ExposedClass> exposedClasses = new HashMap<>(); private Map<String, ExposedClass> exposedClasses = new HashMap<>();
private Predicate<String> classFilter = n -> true;
JSObjectClassTransformer(JSBodyRepository repository) { JSObjectClassTransformer(JSBodyRepository repository) {
this.repository = repository; this.repository = repository;
} }
void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}
@Override @Override
public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) {
this.hierarchy = context.getHierarchy(); this.hierarchy = context.getHierarchy();
@ -71,6 +77,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
typeHelper = new JSTypeHelper(hierarchy.getClassSource()); typeHelper = new JSTypeHelper(hierarchy.getClassSource());
processor = new JSClassProcessor(hierarchy.getClassSource(), typeHelper, repository, processor = new JSClassProcessor(hierarchy.getClassSource(), typeHelper, repository,
context.getDiagnostics(), context.getIncrementalCache(), context.isStrict()); context.getDiagnostics(), context.getIncrementalCache(), context.isStrict());
processor.setClassFilter(classFilter);
} }
processor.processClass(cls); processor.processClass(cls);
if (typeHelper.isJavaScriptClass(cls.getName())) { if (typeHelper.isJavaScriptClass(cls.getName())) {