Fix Kotlin/JS compiler under JRE9
See KT-20653, KT-20650
This commit is contained in:
@@ -20,8 +20,7 @@ import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion
|
|||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import javax.xml.bind.DatatypeConverter.parseBase64Binary
|
import java.util.*
|
||||||
import javax.xml.bind.DatatypeConverter.printBase64Binary
|
|
||||||
|
|
||||||
class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: String, val body: ByteArray)
|
class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: String, val body: ByteArray)
|
||||||
|
|
||||||
@@ -73,7 +72,8 @@ object KotlinJavascriptMetadataUtils {
|
|||||||
KOTLIN_JAVASCRIPT_METHOD_NAME_PATTERN.matcher(text).find() && METADATA_PATTERN.matcher(text).find()
|
KOTLIN_JAVASCRIPT_METHOD_NAME_PATTERN.matcher(text).find() && METADATA_PATTERN.matcher(text).find()
|
||||||
|
|
||||||
fun formatMetadataAsString(moduleName: String, content: ByteArray): String =
|
fun formatMetadataAsString(moduleName: String, content: ByteArray): String =
|
||||||
"// Kotlin.$KOTLIN_JAVASCRIPT_METHOD_NAME(${JsMetadataVersion.INSTANCE.toInteger()}, \"$moduleName\", \"${printBase64Binary(content)}\");\n"
|
"// Kotlin.$KOTLIN_JAVASCRIPT_METHOD_NAME(${JsMetadataVersion.INSTANCE.toInteger()}, \"$moduleName\", " +
|
||||||
|
"\"${Base64.getEncoder().encodeToString(content)}\");\n"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun loadMetadata(file: File): List<KotlinJavascriptMetadata> {
|
fun loadMetadata(file: File): List<KotlinJavascriptMetadata> {
|
||||||
@@ -99,7 +99,7 @@ object KotlinJavascriptMetadataUtils {
|
|||||||
val abiVersion = JsMetadataVersion.fromInteger(matcher.group(1).toInt())
|
val abiVersion = JsMetadataVersion.fromInteger(matcher.group(1).toInt())
|
||||||
val moduleName = matcher.group(3)
|
val moduleName = matcher.group(3)
|
||||||
val data = matcher.group(5)
|
val data = matcher.group(5)
|
||||||
metadataList.add(KotlinJavascriptMetadata(abiVersion, moduleName, parseBase64Binary(data)))
|
metadataList.add(KotlinJavascriptMetadata(abiVersion, moduleName, Base64.getDecoder().decode(data)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,11 @@ public final class StaticContext {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression getQualifiedExpression(@NotNull DeclarationDescriptor descriptor) {
|
private JsExpression getQualifiedExpression(@NotNull DeclarationDescriptor descriptor) {
|
||||||
JsExpression fqn = fqnCache.computeIfAbsent(descriptor, this::buildQualifiedExpression);
|
JsExpression fqn = fqnCache.get(descriptor);
|
||||||
|
if (fqn == null) {
|
||||||
|
fqn = buildQualifiedExpression(descriptor);
|
||||||
|
fqnCache.put(descriptor, fqn);
|
||||||
|
}
|
||||||
return fqn.deepCopy();
|
return fqn.deepCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,12 +814,12 @@ public final class StaticContext {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsExpression exportModuleForInline(@NotNull String moduleId, @NotNull JsName moduleName) {
|
public JsExpression exportModuleForInline(@NotNull String moduleId, @NotNull JsName moduleName) {
|
||||||
return modulesImportedForInline.computeIfAbsent(moduleId, k -> {
|
JsExpression moduleRef = modulesImportedForInline.get(moduleId);
|
||||||
|
if (moduleRef == null) {
|
||||||
JsExpression currentModuleRef = pureFqn(getInnerNameForDescriptor(getCurrentModule()), null);
|
JsExpression currentModuleRef = pureFqn(getInnerNameForDescriptor(getCurrentModule()), null);
|
||||||
JsExpression importsRef = pureFqn(Namer.IMPORTS_FOR_INLINE_PROPERTY, currentModuleRef);
|
JsExpression importsRef = pureFqn(Namer.IMPORTS_FOR_INLINE_PROPERTY, currentModuleRef);
|
||||||
JsExpression currentImports = pureFqn(getNameForImportsForInline(), null);
|
JsExpression currentImports = pureFqn(getNameForImportsForInline(), null);
|
||||||
|
|
||||||
JsExpression moduleRef;
|
|
||||||
JsExpression lhsModuleRef;
|
JsExpression lhsModuleRef;
|
||||||
if (NameSuggestionKt.isValidES5Identifier(moduleId)) {
|
if (NameSuggestionKt.isValidES5Identifier(moduleId)) {
|
||||||
moduleRef = pureFqn(moduleId, importsRef);
|
moduleRef = pureFqn(moduleId, importsRef);
|
||||||
@@ -832,8 +836,10 @@ public final class StaticContext {
|
|||||||
MetadataProperties.setExportedTag(importStmt, "imports:" + moduleId);
|
MetadataProperties.setExportedTag(importStmt, "imports:" + moduleId);
|
||||||
getFragment().getExportBlock().getStatements().add(importStmt);
|
getFragment().getExportBlock().getStatements().add(importStmt);
|
||||||
|
|
||||||
return moduleRef;
|
modulesImportedForInline.put(moduleId, moduleRef);
|
||||||
}).deepCopy();
|
}
|
||||||
|
|
||||||
|
return moduleRef.deepCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+29
-20
@@ -294,31 +294,40 @@ public class TranslationContext {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String tag = staticContext.getTag(descriptor);
|
String tag = staticContext.getTag(descriptor);
|
||||||
name = inlineFunctionContext.getImports().computeIfAbsent(tag, t -> {
|
name = inlineFunctionContext.getImports().get(tag);
|
||||||
JsExpression imported = createInlineLocalImportExpression(descriptor);
|
if (name == null) {
|
||||||
if (imported instanceof JsNameRef) {
|
name = createInlineableInnerNameForDescriptor(descriptor);
|
||||||
JsNameRef importedNameRef = (JsNameRef) imported;
|
inlineFunctionContext.getImports().put(tag, name);
|
||||||
if (importedNameRef.getQualifier() == null && importedNameRef.getIdent().equals(Namer.getRootPackageName()) &&
|
}
|
||||||
(descriptor instanceof PackageFragmentDescriptor || descriptor instanceof ModuleDescriptor)) {
|
|
||||||
return importedNameRef.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JsName result = JsScope.declareTemporaryName(StaticContext.getSuggestedName(descriptor));
|
|
||||||
if (isFromCurrentModule(descriptor) && !AnnotationsUtils.isNativeObject(descriptor)) {
|
|
||||||
MetadataProperties.setLocalAlias(result, getInnerNameForDescriptor(descriptor));
|
|
||||||
}
|
|
||||||
MetadataProperties.setDescriptor(result, descriptor);
|
|
||||||
MetadataProperties.setStaticRef(result, imported);
|
|
||||||
MetadataProperties.setImported(result, true);
|
|
||||||
inlineFunctionContext.getImportBlock().getStatements().add(JsAstUtils.newVar(result, imported));
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsName createInlineableInnerNameForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
assert inlineFunctionContext != null;
|
||||||
|
|
||||||
|
JsExpression imported = createInlineLocalImportExpression(descriptor);
|
||||||
|
if (imported instanceof JsNameRef) {
|
||||||
|
JsNameRef importedNameRef = (JsNameRef) imported;
|
||||||
|
if (importedNameRef.getQualifier() == null && importedNameRef.getIdent().equals(Namer.getRootPackageName()) &&
|
||||||
|
(descriptor instanceof PackageFragmentDescriptor || descriptor instanceof ModuleDescriptor)) {
|
||||||
|
return importedNameRef.getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JsName result = JsScope.declareTemporaryName(StaticContext.getSuggestedName(descriptor));
|
||||||
|
if (isFromCurrentModule(descriptor) && !AnnotationsUtils.isNativeObject(descriptor)) {
|
||||||
|
MetadataProperties.setLocalAlias(result, getInnerNameForDescriptor(descriptor));
|
||||||
|
}
|
||||||
|
MetadataProperties.setDescriptor(result, descriptor);
|
||||||
|
MetadataProperties.setStaticRef(result, imported);
|
||||||
|
MetadataProperties.setImported(result, true);
|
||||||
|
inlineFunctionContext.getImportBlock().getStatements().add(JsAstUtils.newVar(result, imported));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JsExpression getReferenceToIntrinsic(@NotNull String intrinsicName) {
|
public JsExpression getReferenceToIntrinsic(@NotNull String intrinsicName) {
|
||||||
JsExpression result;
|
JsExpression result;
|
||||||
|
|||||||
Reference in New Issue
Block a user