Skip to content

Commit 0df5bff

Browse files
authored
Use built-in JsClass getter (#184)
1 parent 0a4750b commit 0df5bff

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

core/src/jsMain/kotlin/kotlinx/rpc/internal/WithRPCStubObject.js.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ public actual fun <R : Any> findRPCStubProvider(kClass: KClass<*>, resultKClass:
3939
)
4040
}
4141

42-
/**
43-
* [KClassImpl] is internal in kjs stdlib, and it's jClass property is obfuscated by the webpack.
44-
* Hence, we need to find it manually.
45-
*/
46-
private val KClass<*>.jClass get(): JsClass<*> {
47-
return Object.entries(this)
48-
// key (_) is obfuscated here
49-
.firstOrNull { (_, value) -> value != null && Object.hasOwn(value,"\$metadata\$") }
50-
?.component2()
51-
?.unsafeCast<JsClass<*>>()
52-
?: error("jClass property was not found")
53-
}
54-
5542
/**
5643
* Workaround for bugs in [findAssociatedObject]
5744
* See KT-70132 for more info.
@@ -62,8 +49,8 @@ internal fun <T : Annotation, R : Any> KClass<*>.findAssociatedObjectImpl(
6249
annotationClass: KClass<T>,
6350
resultKClass: KClass<R>,
6451
): Any? {
65-
val key = annotationClass.jClass.asDynamic().`$metadata$`?.associatedObjectKey?.unsafeCast<Int>() ?: return null
66-
val map = jClass.asDynamic().`$metadata$`?.associatedObjects ?: return null
52+
val key = annotationClass.js.asDynamic().`$metadata$`?.associatedObjectKey?.unsafeCast<Int>() ?: return null
53+
val map = js.asDynamic().`$metadata$`?.associatedObjects ?: return null
6754
val factory = map[key] ?: return fallbackFindAssociatedObjectImpl(map, resultKClass)
6855
return factory()
6956
}

0 commit comments

Comments
 (0)