[K/JS] Move global interface id state into an object to prevent interface ids reinitialization ^Fixed KT-55758

This commit is contained in:
Artem Kobzar
2023-01-09 20:56:19 +00:00
committed by Space Team
parent dc514fa396
commit 642bbd38ba
5 changed files with 50 additions and 14 deletions
@@ -31,8 +31,20 @@ internal fun setMetadataFor(
}
}
// There was a problem with per-module compilation (KT-55758) when the top-level state (iid) was reinitialized during stdlib module initialization
// As a result we miss already incremented iid and had the same iids in two different modules
// So, to keep the state consistent it was moved into the object
private object InterfaceIdService {
var iid: Int = 0
}
private fun InterfaceIdService.generateInterfaceId(): Int {
iid += 1
return iid
}
internal fun interfaceMeta(name: String?, associatedObjectKey: Number?, associatedObjects: dynamic, suspendArity: Array<Int>?): Metadata {
return createMetadata("interface", name, associatedObjectKey, associatedObjects, suspendArity, generateInterfaceId())
return createMetadata("interface", name, associatedObjectKey, associatedObjects, suspendArity, InterfaceIdService.generateInterfaceId())
}
internal fun objectMeta(name: String?, associatedObjectKey: Number?, associatedObjects: dynamic, suspendArity: Array<Int>?): Metadata {
@@ -85,19 +97,6 @@ internal external interface Ctor {
val prototype: dynamic
}
private var iid: Int? = null
@Suppress("SMARTCAST_IMPOSSIBLE")
internal fun generateInterfaceId(): Int {
if (iid == null) {
iid = 1
} else {
iid += 1
}
return iid
}
@Suppress("UNUSED_PARAMETER")
private fun getPrototypeOf(obj: dynamic) =
js("Object.getPrototypeOf(obj)")