Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in JsClass getter #184

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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