Skip to content

Commit

Permalink
Use built-in JsClass getter (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee authored Sep 23, 2024
1 parent 0a4750b commit 0df5bff
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ public actual fun <R : Any> findRPCStubProvider(kClass: KClass<*>, resultKClass:
)
}

/**
* [KClassImpl] is internal in kjs stdlib, and it's jClass property is obfuscated by the webpack.
* Hence, we need to find it manually.
*/
private val KClass<*>.jClass get(): JsClass<*> {
return Object.entries(this)
// key (_) is obfuscated here
.firstOrNull { (_, value) -> value != null && Object.hasOwn(value,"\$metadata\$") }
?.component2()
?.unsafeCast<JsClass<*>>()
?: error("jClass property was not found")
}

/**
* Workaround for bugs in [findAssociatedObject]
* See KT-70132 for more info.
Expand All @@ -62,8 +49,8 @@ internal fun <T : Annotation, R : Any> KClass<*>.findAssociatedObjectImpl(
annotationClass: KClass<T>,
resultKClass: KClass<R>,
): Any? {
val key = annotationClass.jClass.asDynamic().`$metadata$`?.associatedObjectKey?.unsafeCast<Int>() ?: return null
val map = jClass.asDynamic().`$metadata$`?.associatedObjects ?: return null
val key = annotationClass.js.asDynamic().`$metadata$`?.associatedObjectKey?.unsafeCast<Int>() ?: return null
val map = js.asDynamic().`$metadata$`?.associatedObjects ?: return null
val factory = map[key] ?: return fallbackFindAssociatedObjectImpl(map, resultKClass)
return factory()
}
Expand Down

0 comments on commit 0df5bff

Please sign in to comment.