[JS IR BE] Support 'is Number' and 'is Comparable<>'
This commit is contained in:
@@ -6,5 +6,5 @@
|
||||
package kotlin.js
|
||||
|
||||
// TODO: Polyfill
|
||||
fun imul(a: dynamic, b: dynamic) =
|
||||
js("((a & 0xffff0000) * (b & 0xffff) + (a & 0xffff) * (b | 0)) | 0")
|
||||
internal fun imul(a: Int, b: Int) =
|
||||
js("((a & 0xffff0000) * (b & 0xffff) + (a & 0xffff) * (b | 0)) | 0").unsafeCast<Int>()
|
||||
@@ -150,4 +150,16 @@ public fun jsIsType(obj: dynamic, jsClass: dynamic): Boolean {
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
fun isNumber(a: dynamic) = jsTypeOf(a) == "number" || a is Long
|
||||
|
||||
fun isComparable(value: dynamic): Boolean {
|
||||
var type = jsTypeOf(value)
|
||||
|
||||
return type == "string" ||
|
||||
type == "boolean" ||
|
||||
isNumber(value) ||
|
||||
isInterface(value, Comparable::class.js)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.js
|
||||
|
||||
// Mirrors signature from JS IR BE
|
||||
// Used for js.translator/testData/box/number/mulInt32.kt
|
||||
@library
|
||||
@JsName("imulEmulated")
|
||||
internal fun imul(x: Int, y: Int): Int = definedExternally
|
||||
Reference in New Issue
Block a user