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

View File

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

View File

@ -70,7 +70,7 @@ class JSObjectClassTransformer implements ClassHolderTransformer {
if (processor == null || processor.getClassSource() != hierarchy.getClassSource()) { if (processor == null || processor.getClassSource() != hierarchy.getClassSource()) {
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.getDiagnostics(), context.getIncrementalCache(), context.isStrict());
} }
processor.processClass(cls); processor.processClass(cls);
if (typeHelper.isJavaScriptClass(cls.getName())) { if (typeHelper.isJavaScriptClass(cls.getName())) {

View File

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