Skip to content

Commit

Permalink
wasm gc: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
konsoletyper committed Sep 29, 2024
1 parent e966690 commit 0897a1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import org.mozilla.javascript.CompilerEnvirons;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ast.AstRoot;
Expand Down Expand Up @@ -109,6 +110,7 @@ class JSClassProcessor {
private IncrementalDependencyRegistration incrementalCache;
private JSImportAnnotationCache annotationCache;
private ClassReader objectClass;
private Predicate<String> classFilter = n -> true;

JSClassProcessor(ClassReaderSource classSource, JSTypeHelper typeHelper, JSBodyRepository repository,
Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache, boolean strict) {
Expand All @@ -123,6 +125,10 @@ class JSClassProcessor {
annotationCache = new JSImportAnnotationCache(classSource, diagnostics);
}

public void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}

public ClassReaderSource getClassSource() {
return classSource;
}
Expand Down Expand Up @@ -760,6 +766,9 @@ private boolean processInvocation(MethodReader method, CallLocation callLocation

private boolean processJSBodyInvocation(MethodReader method, CallLocation callLocation, InvokeInstruction invoke,
MethodHolder methodToProcess) {
if (!classFilter.test(method.getOwnerName())) {
return false;
}
boolean[] byRefParams = new boolean[method.parameterCount()];
validateSignature(method, callLocation, byRefParams);
if (invoke.getInstance() != null) {
Expand Down
4 changes: 3 additions & 1 deletion jso/impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void install(TeaVMHost host) {

JSBodyRepository repository = new JSBodyRepository();
host.registerService(JSBodyRepository.class, repository);
host.add(new JSObjectClassTransformer(repository));
var classTransformer = new JSObjectClassTransformer(repository);
host.add(classTransformer);
JSDependencyListener dependencyListener = new JSDependencyListener(repository);
host.add(dependencyListener);
host.add(new JSExceptionsDependencyListener());
Expand All @@ -59,6 +60,7 @@ public void install(TeaVMHost host) {
}

if (wasmGCHost != null) {
classTransformer.setClassFilter(n -> !n.startsWith("java."));
WasmGCJso.install(host, wasmGCHost, repository);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import org.teavm.diagnostics.Diagnostics;
import org.teavm.jso.JSClass;
import org.teavm.jso.JSExport;
Expand Down Expand Up @@ -59,18 +60,24 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
private JSTypeHelper typeHelper;
private ClassHierarchy hierarchy;
private Map<String, ExposedClass> exposedClasses = new HashMap<>();
private Predicate<String> classFilter = n -> true;

JSObjectClassTransformer(JSBodyRepository repository) {
this.repository = repository;
}

void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}

@Override
public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) {
this.hierarchy = context.getHierarchy();
if (processor == null || processor.getClassSource() != hierarchy.getClassSource()) {
typeHelper = new JSTypeHelper(hierarchy.getClassSource());
processor = new JSClassProcessor(hierarchy.getClassSource(), typeHelper, repository,
context.getDiagnostics(), context.getIncrementalCache(), context.isStrict());
processor.setClassFilter(classFilter);
}
processor.processClass(cls);
if (typeHelper.isJavaScriptClass(cls.getName())) {
Expand Down

0 comments on commit 0897a1b

Please sign in to comment.