[Wasm] Introduce utilities to get package and name of class directly from metadata and use it in some places

This commit is contained in:
Zalim Bashorov
2023-03-28 22:40:58 +02:00
parent f206b0b72d
commit 14af47bbd9
8 changed files with 34 additions and 17 deletions
+4 -2
View File
@@ -57,8 +57,10 @@ public open class Any @WasmPrimitiveConstructor constructor() {
* Returns a string representation of the object.
*/
public open fun toString(): String {
val typeData = getTypeInfoTypeDataByPtr(typeInfo)
val qualifiedName = if (typeData.packageName.isEmpty()) typeData.typeName else "${typeData.packageName}.${typeData.typeName}"
val typeInfoPtr = this.typeInfo
val packageName = getPackageName(typeInfoPtr)
val simpleName = getSimpleName(typeInfoPtr)
val qualifiedName = if (packageName.isEmpty()) simpleName else "$packageName.$simpleName"
return "$qualifiedName@${identityHashCode()}"
}
}
@@ -6,6 +6,7 @@
package kotlin
import kotlin.wasm.internal.ExternalInterfaceType
import kotlin.wasm.internal.getSimpleName
import kotlin.wasm.internal.jsToKotlinStringAdapter
/**
@@ -34,8 +35,7 @@ public open class Throwable(open val message: String?, open val cause: kotlin.Th
* followed by the exception message if it is not null.
*/
public override fun toString(): String {
val kClass = this::class
val s = kClass.simpleName ?: "Throwable"
val s = getSimpleName(this.typeInfo)
return if (message != null) s + ": " + message.toString() else s
}
}