JS IR: hide runtime helpers from users

This commit is contained in:
Anton Bannykh
2020-04-22 19:31:48 +03:00
parent 9f20e65595
commit e8a6ddceaa
8 changed files with 50 additions and 47 deletions
@@ -5,26 +5,26 @@
package kotlin.js
fun numberToByte(a: dynamic): Byte = toByte(numberToInt(a))
internal fun numberToByte(a: dynamic): Byte = toByte(numberToInt(a))
fun numberToDouble(a: dynamic): Double = js("+a").unsafeCast<Double>()
internal fun numberToDouble(a: dynamic): Double = js("+a").unsafeCast<Double>()
fun numberToInt(a: dynamic): Int = if (a is Long) a.toInt() else doubleToInt(a)
internal fun numberToInt(a: dynamic): Int = if (a is Long) a.toInt() else doubleToInt(a)
fun numberToShort(a: dynamic): Short = toShort(numberToInt(a))
internal fun numberToShort(a: dynamic): Short = toShort(numberToInt(a))
// << and >> shifts are used to preserve sign of the number
fun toByte(a: dynamic): Byte = js("a << 24 >> 24").unsafeCast<Byte>()
fun toShort(a: dynamic): Short = js("a << 16 >> 16").unsafeCast<Short>()
internal fun toByte(a: dynamic): Byte = js("a << 24 >> 24").unsafeCast<Byte>()
internal fun toShort(a: dynamic): Short = js("a << 16 >> 16").unsafeCast<Short>()
fun numberToLong(a: dynamic): Long = if (a is Long) a else fromNumber(a)
internal fun numberToLong(a: dynamic): Long = if (a is Long) a else fromNumber(a)
fun toLong(a: dynamic): Long = fromInt(a)
internal fun toLong(a: dynamic): Long = fromInt(a)
fun doubleToInt(a: Double): Int = when {
internal fun doubleToInt(a: Double): Int = when {
a > 2147483647 -> 2147483647
a < -2147483648 -> -2147483648
else -> jsBitwiseOr(a, 0)
}
fun numberToChar(a: dynamic) = Char(numberToInt(a) and 0xFFFF)
internal fun numberToChar(a: dynamic) = Char(numberToInt(a) and 0xFFFF)