diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java index b6da7c20d..121b13c2f 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSClassProcessor.java @@ -25,6 +25,7 @@ import java.util.List; 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; @@ -109,6 +110,7 @@ class JSClassProcessor { private IncrementalDependencyRegistration incrementalCache; private JSImportAnnotationCache annotationCache; private ClassReader objectClass; + private Predicate classFilter = n -> true; JSClassProcessor(ClassReaderSource classSource, JSTypeHelper typeHelper, JSBodyRepository repository, Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache, boolean strict) { @@ -123,6 +125,10 @@ class JSClassProcessor { annotationCache = new JSImportAnnotationCache(classSource, diagnostics); } + public void setClassFilter(Predicate classFilter) { + this.classFilter = classFilter; + } + public ClassReaderSource getClassSource() { return classSource; } @@ -760,6 +766,9 @@ class JSClassProcessor { 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) { diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java index 2d62ed117..ec20ac87f 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSOPlugin.java @@ -39,7 +39,8 @@ public class JSOPlugin implements TeaVMPlugin { 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()); @@ -59,6 +60,7 @@ public class JSOPlugin implements TeaVMPlugin { } if (wasmGCHost != null) { + classTransformer.setClassFilter(n -> !n.startsWith("java.")); WasmGCJso.install(host, wasmGCHost, repository); } } diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java index cc4d8a398..cc77ca901 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSObjectClassTransformer.java @@ -22,6 +22,7 @@ import java.util.HashSet; 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; @@ -59,11 +60,16 @@ class JSObjectClassTransformer implements ClassHolderTransformer { private JSTypeHelper typeHelper; private ClassHierarchy hierarchy; private Map exposedClasses = new HashMap<>(); + private Predicate classFilter = n -> true; JSObjectClassTransformer(JSBodyRepository repository) { this.repository = repository; } + void setClassFilter(Predicate classFilter) { + this.classFilter = classFilter; + } + @Override public void transformClass(ClassHolder cls, ClassHolderTransformerContext context) { this.hierarchy = context.getHierarchy(); @@ -71,6 +77,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer { 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())) {