[JS IR BE] Hack irRuntime js function usage to compensate for implementation shortcomings
This commit is contained in:
@@ -6,5 +6,5 @@
|
|||||||
package kotlin.js
|
package kotlin.js
|
||||||
|
|
||||||
// TODO: Polyfill
|
// TODO: Polyfill
|
||||||
internal fun imul(a: Int, b: Int) =
|
internal fun imul(a_local: Int, b_local: Int) =
|
||||||
js("((a & 0xffff0000) * (b & 0xffff) + (a & 0xffff) * (b | 0)) | 0").unsafeCast<Int>()
|
js("((a_local & 0xffff0000) * (b_local & 0xffff) + (a_local & 0xffff) * (b_local | 0)) | 0").unsafeCast<Int>()
|
||||||
@@ -24,21 +24,21 @@ internal fun <T> arrayConcat(vararg args: T): T {
|
|||||||
*/
|
*/
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal fun <T> primitiveArrayConcat(vararg args: T): T {
|
internal fun <T> primitiveArrayConcat(vararg args: T): T {
|
||||||
var size = 0
|
var size_local = 0
|
||||||
for (i in 0 .. (args.size - 1)) {
|
for (i in 0 .. (args.size - 1)) {
|
||||||
size += args[i].unsafeCast<Array<Any?>>().size
|
size_local += args[i].unsafeCast<Array<Any?>>().size
|
||||||
}
|
}
|
||||||
val a = args[0]
|
val a = args[0]
|
||||||
val result = js("new a.constructor(size)").unsafeCast<Array<Any?>>()
|
val result = js("new a.constructor(size_local)").unsafeCast<Array<Any?>>()
|
||||||
if (a.asDynamic().`$type$` != null) {
|
if (a.asDynamic().`$type$` != null) {
|
||||||
withType(a.asDynamic().`$type$`, result)
|
withType(a.asDynamic().`$type$`, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
size = 0
|
size_local = 0
|
||||||
for (i in 0 .. (args.size - 1)) {
|
for (i in 0 .. (args.size - 1)) {
|
||||||
val arr = args[i].unsafeCast<Array<Any?>>()
|
val arr = args[i].unsafeCast<Array<Any?>>()
|
||||||
for (j in 0 .. (arr.size - 1)) {
|
for (j in 0 .. (arr.size - 1)) {
|
||||||
result[size++] = arr[j]
|
result[size_local++] = arr[j]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.unsafeCast<T>()
|
return result.unsafeCast<T>()
|
||||||
|
|||||||
@@ -5,27 +5,31 @@
|
|||||||
|
|
||||||
package kotlin.js
|
package kotlin.js
|
||||||
|
|
||||||
private fun isInterfaceImpl(ctor: dynamic, iface: dynamic): Boolean {
|
private external interface Metadata {
|
||||||
if (ctor === iface) return true;
|
val interfaces: Array<Ctor>
|
||||||
|
}
|
||||||
|
|
||||||
val self = ::isInterfaceImpl
|
private external interface Ctor {
|
||||||
return js(
|
val `$metadata$`: Metadata?
|
||||||
"""
|
val prototype: Ctor?
|
||||||
var metadata = ctor.${"$"}metadata${"$"};
|
}
|
||||||
|
|
||||||
|
private fun isInterfaceImpl(ctor: Ctor, iface: dynamic): Boolean {
|
||||||
|
if (ctor === iface) return true
|
||||||
|
|
||||||
|
val metadata = ctor.`$metadata$`
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
var interfaces = metadata.interfaces;
|
val interfaces = metadata.interfaces
|
||||||
for (var i = 0; i < interfaces.length; i++) {
|
for (i in interfaces) {
|
||||||
if (self_0(interfaces[i], iface)) {
|
if (isInterfaceImpl(i, iface)) {
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var superPrototype = ctor.prototype != null ? Object.getPrototypeOf(ctor.prototype) : null;
|
val superPrototype = if (ctor.prototype != null) js("Object").getPrototypeOf(ctor.prototype) else null
|
||||||
var superConstructor = superPrototype != null ? superPrototype.constructor : null;
|
val superConstructor: Ctor? = if (superPrototype != null) superPrototype.constructor else null
|
||||||
return superConstructor != null && self_0(superConstructor, iface);
|
return superConstructor != null && isInterfaceImpl(superConstructor, iface)
|
||||||
"""
|
|
||||||
).unsafeCast<Boolean>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun isInterface(obj: dynamic, iface: dynamic): Boolean {
|
public fun isInterface(obj: dynamic, iface: dynamic): Boolean {
|
||||||
@@ -74,9 +78,9 @@ public fun isInterface(ctor: dynamic, IType: dynamic): Boolean {
|
|||||||
|
|
||||||
fun typeOf(obj: dynamic): String = js("typeof obj").unsafeCast<String>()
|
fun typeOf(obj: dynamic): String = js("typeof obj").unsafeCast<String>()
|
||||||
|
|
||||||
fun jsTypeOf(a: Any?): String = js("typeof a").unsafeCast<String>()
|
fun jsTypeOf(obj: Any?): String = js("typeof obj").unsafeCast<String>()
|
||||||
|
|
||||||
fun instanceOf(obj: dynamic, jsClass: dynamic) = js("obj instanceof jsClass").unsafeCast<Boolean>()
|
fun instanceOf(obj: dynamic, jsClass_local: dynamic) = js("obj instanceof jsClass_local").unsafeCast<Boolean>()
|
||||||
|
|
||||||
fun isObject(obj: dynamic): Boolean {
|
fun isObject(obj: dynamic): Boolean {
|
||||||
val objTypeOf = typeOf(obj)
|
val objTypeOf = typeOf(obj)
|
||||||
@@ -118,7 +122,7 @@ public fun isLongArray(a: dynamic): Boolean = isJsArray(a) && a.`$type$` == "Lon
|
|||||||
|
|
||||||
|
|
||||||
internal fun jsIn(x: String, y: dynamic): Boolean = js("x in y")
|
internal fun jsIn(x: String, y: dynamic): Boolean = js("x in y")
|
||||||
internal fun jsGetPrototypeOf(jsClass: dynamic) = js("Object.getPrototypeOf(jsClass)")
|
internal fun jsGetPrototypeOf(jsClass: dynamic) = js("Object").getPrototypeOf(jsClass)
|
||||||
|
|
||||||
public fun jsIsType(obj: dynamic, jsClass: dynamic): Boolean {
|
public fun jsIsType(obj: dynamic, jsClass: dynamic): Boolean {
|
||||||
if (jsClass === js("Object")) {
|
if (jsClass === js("Object")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user