[JS IR BE] Support 'is Number' and 'is Comparable<>'

This commit is contained in:
Svyatoslav Kuzmich
2018-10-10 21:54:02 +03:00
parent 783f27c554
commit 5a057f8ca6
8 changed files with 47 additions and 7 deletions
+2 -2
View File
@@ -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