jso: don't insert casts to JS classes in non-strict mode

This commit is contained in:
Alexey Andreev 2024-04-22 19:16:33 +02:00
parent 81fc843da3
commit 19518eb191
3 changed files with 6 additions and 3 deletions
jso/impl/src/main/java/org/teavm/jso/impl
tools/junit/src/main/java/org/teavm/junit

View File

@ -104,18 +104,20 @@ class JSClassProcessor {
private final JSTypeHelper typeHelper;
private final Diagnostics diagnostics;
private final Map<MethodReference, MethodReader> overriddenMethodCache = new HashMap<>();
private final boolean strict;
private JSValueMarshaller marshaller;
private IncrementalDependencyRegistration incrementalCache;
private JSImportAnnotationCache annotationCache;
private ClassReader objectClass;
JSClassProcessor(ClassReaderSource classSource, JSTypeHelper typeHelper, JSBodyRepository repository,
Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache) {
Diagnostics diagnostics, IncrementalDependencyRegistration incrementalCache, boolean strict) {
this.classSource = classSource;
this.typeHelper = typeHelper;
this.repository = repository;
this.diagnostics = diagnostics;
this.incrementalCache = incrementalCache;
this.strict = strict;
javaInvocationProcessor = new JavaInvocationProcessor(typeHelper, repository, classSource, diagnostics);
annotationCache = new JSImportAnnotationCache(classSource, diagnostics);
@ -477,7 +479,7 @@ class JSClassProcessor {
ClassReader targetClass = classSource.get(targetClassName);
if (targetClass.getAnnotations().get(JSFunctor.class.getName()) == null) {
if (isTransparent(targetClassName)) {
if (!strict || isTransparent(targetClassName)) {
var assign = new AssignInstruction();
assign.setLocation(location.getSourceLocation());
assign.setAssignee(cast.getValue());

View File

@ -70,7 +70,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
if (processor == null || processor.getClassSource() != hierarchy.getClassSource()) {
typeHelper = new JSTypeHelper(hierarchy.getClassSource());
processor = new JSClassProcessor(hierarchy.getClassSource(), typeHelper, repository,
context.getDiagnostics(), context.getIncrementalCache());
context.getDiagnostics(), context.getIncrementalCache(), context.isStrict());
}
processor.processClass(cls);
if (typeHelper.isJavaScriptClass(cls.getName())) {

View File

@ -85,6 +85,7 @@ abstract class TestPlatformSupport<T extends TeaVMTarget> {
.setClassSource(classSource)
.setReferenceCache(referenceCache)
.setDependencyAnalyzerFactory(dependencyAnalyzerFactory)
.setStrict(true)
.build();
configuration.apply(vm);