feat: add polyfills insertion for ES Next used features
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.acosh = function acosh(x) {
|
||||
acosh.called = true;
|
||||
if (x <= 0.5) {
|
||||
return NaN
|
||||
} else if (x === 1) {
|
||||
return 0
|
||||
}
|
||||
return 1.3169578969248166
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.acosh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(acosh(-1.0), Double.NaN)
|
||||
assertEquals(acosh(0.0), Double.NaN)
|
||||
assertEquals(acosh(0.5), Double.NaN)
|
||||
assertEquals(acosh(1.0), 0.0)
|
||||
assertEquals(acosh(2.0), 1.3169578969248166)
|
||||
|
||||
assertEquals(js("Math.acosh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.acosh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.acosh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(acosh(-1.0), Double.NaN)
|
||||
assertEquals(acosh(0.0), Double.NaN)
|
||||
assertEquals(acosh(0.5), Double.NaN)
|
||||
assertEquals(acosh(1.0), 0.0)
|
||||
assertEquals(acosh(2.0), 1.3169578969248166)
|
||||
|
||||
assertEquals(js("Math.acosh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.asinh = function asinh(x) {
|
||||
asinh.called = true;
|
||||
switch (x) {
|
||||
case -1: return -0.8813735870195429
|
||||
case 0: return 0.0
|
||||
case 1: return 0.8813735870195429
|
||||
case 2: return 1.4436354751788103
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.asinh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(asinh(-1.0), -0.8813735870195429)
|
||||
assertEquals(asinh(0.0), 0.0)
|
||||
assertEquals(asinh(1.0), 0.8813735870195429)
|
||||
assertEquals(asinh(2.0), 1.4436354751788103)
|
||||
|
||||
assertEquals(js("Math.asinh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.asinh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.asinh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(asinh(-1.0), -0.8813735870195429)
|
||||
assertEquals(asinh(0.0), 0.0)
|
||||
assertEquals(asinh(1.0), 0.8813735870195429)
|
||||
assertEquals(asinh(2.0), 1.4436354751788103)
|
||||
|
||||
assertEquals(js("Math.asinh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.atanh = function atanh(x) {
|
||||
atanh.called = true;
|
||||
switch (x) {
|
||||
case -1: return -Infinity
|
||||
case 0: return 0.0
|
||||
case 0.5: return 0.5493061443340548
|
||||
case 1: return Infinity
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.atanh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(atanh(-1.0), Double.NEGATIVE_INFINITY)
|
||||
assertEquals(atanh(0.0), 0.0)
|
||||
assertEquals(atanh(0.5), 0.5493061443340548)
|
||||
assertEquals(atanh(1.0), Double.POSITIVE_INFINITY)
|
||||
|
||||
assertEquals(js("Math.atanh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.atanh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.atanh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(atanh(-1.0), Double.NEGATIVE_INFINITY)
|
||||
assertEquals(atanh(0.0), 0.0)
|
||||
assertEquals(atanh(0.5), 0.5493061443340548)
|
||||
assertEquals(atanh(1.0), Double.POSITIVE_INFINITY)
|
||||
|
||||
assertEquals(js("Math.atanh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.clz32 = function clz32(x) {
|
||||
clz32.called = true;
|
||||
var asUint = x >>> 0;
|
||||
if (asUint === 0) {
|
||||
return 32;
|
||||
}
|
||||
return 31 - (Math.log(asUint) / Math.LN2 | 0) | 0; // the "| 0" acts like math.floor
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val result = 4.countLeadingZeroBits()
|
||||
|
||||
assertEquals(result, 29)
|
||||
assertEquals(js("Math.clz32.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.clz32 = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val result = 4.countLeadingZeroBits()
|
||||
|
||||
assertEquals(result, 29)
|
||||
assertEquals(js("Math.clz32.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.cosh = function cosh(x) {
|
||||
cosh.called = true;
|
||||
switch (x) {
|
||||
case -1: return 1.5430806348152437
|
||||
case 0: return 1.0
|
||||
case 1: return 1.5430806348152437
|
||||
case 2: return 3.7621956910836314
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.cosh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(cosh(-1.0), 1.5430806348152437)
|
||||
assertEquals(cosh(0.0), 1.0)
|
||||
assertEquals(cosh(1.0), 1.5430806348152437)
|
||||
assertEquals(cosh(2.0), 3.7621956910836314)
|
||||
|
||||
assertEquals(js("Math.cosh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.cosh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.cosh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(cosh(-1.0), 1.5430806348152437)
|
||||
assertEquals(cosh(0.0), 1.0)
|
||||
assertEquals(cosh(1.0), 1.5430806348152437)
|
||||
assertEquals(cosh(2.0), 3.7621956910836314)
|
||||
|
||||
assertEquals(js("Math.cosh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.expm1 = function expm1(x) {
|
||||
expm1.called = true;
|
||||
switch (x) {
|
||||
case -1: return -0.6321205588285577
|
||||
case 0: return 0.0
|
||||
case 1: return 1.718281828459045
|
||||
case 2: return 6.38905609893065
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.expm1
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(expm1(-1.0), -0.6321205588285577)
|
||||
assertEquals(expm1(0.0), 0.0)
|
||||
assertEquals(expm1(1.0), 1.718281828459045)
|
||||
assertEquals(expm1(2.0), 6.38905609893065)
|
||||
|
||||
assertEquals(js("Math.expm1.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.expm1 = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.expm1
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(expm1(-1.0), -0.6321205588285577)
|
||||
assertEquals(expm1(0.0), 0.0)
|
||||
assertEquals(expm1(1.0), 1.718281828459045)
|
||||
assertEquals(expm1(2.0), 6.38905609893065)
|
||||
|
||||
assertEquals(js("Math.expm1.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Int32Array.prototype.fill = function fill(value) {
|
||||
fill.called = true;
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
this[i] = value;
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val int = IntArray(4).apply { fill(42) }
|
||||
|
||||
assertEquals(int.joinToString(", "), "42, 42, 42, 42")
|
||||
assertEquals(js("Int32Array.prototype.fill.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Int32Array.prototype.fill = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val int = IntArray(4).apply { fill(42) }
|
||||
|
||||
assertEquals(int.joinToString(", "), "42, 42, 42, 42")
|
||||
assertEquals(js("Int32Array.prototype.fill.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +JsAllowInvalidCharsIdentifiersEscaping
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
this.globalThis = { "Is Just Created Global This": true }
|
||||
|
||||
// FILE: main.kt
|
||||
external val `Is Just Created Global This`: Boolean
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(`Is Just Created Global This`, true)
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// !LANGUAGE: +JsAllowInvalidCharsIdentifiersEscaping
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
this.globalThis = undefined
|
||||
this["Is Just Created Global This"] = true
|
||||
|
||||
// FILE: main.kt
|
||||
external val `Is Just Created Global This`: Boolean
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(`Is Just Created Global This`, true)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.hypot = function hypot(a, b) {
|
||||
hypot.called = true;
|
||||
return Math.sqrt(a*a + b*b)
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.hypot
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(hypot(3.0, 4.0), 5.0)
|
||||
assertEquals(hypot(5.0, 12.0), 13.0)
|
||||
assertEquals(hypot(-5.0, 0.0), 5.0)
|
||||
assertEquals(js("Math.hypot.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.hypot = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.hypot
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(hypot(3.0, 4.0), 5.0)
|
||||
assertEquals(hypot(5.0, 12.0), 13.0)
|
||||
assertEquals(hypot(-5.0, 0.0), 5.0)
|
||||
assertEquals(js("Math.hypot.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.imul = function imul(a, b) {
|
||||
imul.called = true;
|
||||
return a * b
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val a: Int = 2
|
||||
val b: Int = 42
|
||||
val c: Int = a * b
|
||||
|
||||
assertEquals(c, 84)
|
||||
assertEquals(js("Math.imul.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.imul = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val a: Int = 2
|
||||
val b: Int = 42
|
||||
val c: Int = 44
|
||||
val d: Int = -2
|
||||
|
||||
assertEquals(a * b, 84)
|
||||
assertEquals(a * c, 88)
|
||||
assertEquals(a * d, -4)
|
||||
assertEquals(js("Math.imul.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
ArrayBuffer.isView = function isView(a) {
|
||||
isView.called = true;
|
||||
return a != null && a.__proto__ != null && a.__proto__.__proto__ === Int8Array.prototype.__proto__;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val intArr = intArrayOf(5, 4, 3, 2, 1)
|
||||
val result = IntArray(5).apply { intArr.copyInto(this) }
|
||||
|
||||
assertEquals(result.joinToString(","), intArr.joinToString(","))
|
||||
assertEquals(js("ArrayBuffer.isView.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
ArrayBuffer.isView = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val intArr = intArrayOf(5, 4, 3, 2, 1)
|
||||
val result = IntArray(5).apply { intArr.copyInto(this) }
|
||||
|
||||
assertEquals(result.joinToString(","), intArr.joinToString(","))
|
||||
assertEquals(js("ArrayBuffer.isView.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log10 = function log10(x) {
|
||||
log10.called = true;
|
||||
return Math.log(x) * Math.LOG10E;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.log10
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(log10(1.0), 0)
|
||||
assertEquals(log10(10.0), 1)
|
||||
assertEquals(log10(100.0), 2)
|
||||
assertEquals(js("Math.log10.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log10 = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.log10
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(log10(1.0), 0)
|
||||
assertEquals(log10(10.0), 1)
|
||||
assertEquals(log10(100.0), 2)
|
||||
assertEquals(js("Math.log10.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log1p = function log1p(x) {
|
||||
log1p.called = true;
|
||||
switch (x) {
|
||||
case -2: return NaN
|
||||
case -1: return -Infinity
|
||||
case 0: return 0
|
||||
case 1: return 0.6931471805599453
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.ln1p
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(ln1p(-2.0), Double.NaN)
|
||||
assertEquals(ln1p(-1.0), Double.NEGATIVE_INFINITY)
|
||||
assertEquals(ln1p(0.0), 0.0)
|
||||
assertEquals(ln1p(1.0), 0.6931471805599453)
|
||||
assertEquals(js("Math.log1p.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log1p = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.ln1p
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(ln1p(-2.0), Double.NaN)
|
||||
assertEquals(ln1p(-1.0), Double.NEGATIVE_INFINITY)
|
||||
assertEquals(ln1p(0.0), 0.0)
|
||||
assertEquals(ln1p(1.0), 0.6931471805599453)
|
||||
assertEquals(js("Math.log1p.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log2 = function log2(x) {
|
||||
log2.called = true;
|
||||
return Math.log(x) * Math.LOG2E;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.log2
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(log2(1.0), 0)
|
||||
assertEquals(log2(2.0), 1)
|
||||
assertEquals(log2(4.0), 2)
|
||||
assertEquals(js("Math.log2.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.log2 = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.log2
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(log2(1.0), 0)
|
||||
assertEquals(log2(2.0), 1)
|
||||
assertEquals(log2(4.0), 2)
|
||||
assertEquals(js("Math.log2.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.sign = function sign(x) {
|
||||
sign.called = true;
|
||||
return x > 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.sign
|
||||
|
||||
fun box(): String {
|
||||
val result = 44.0.sign
|
||||
|
||||
assertEquals(result, 1)
|
||||
assertEquals(js("Math.sign.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.sign = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.sign
|
||||
|
||||
fun box(): String {
|
||||
val result = 44.0.sign
|
||||
|
||||
assertEquals(result, 1)
|
||||
assertEquals(js("Math.sign.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.sinh = function sinh(x) {
|
||||
sinh.called = true;
|
||||
switch (x) {
|
||||
case -1: return -1.1752011936438014
|
||||
case 0: return 0
|
||||
case 1: return 1.1752011936438014
|
||||
case 2: return 3.626860407847019
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.sinh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(sinh(-1.0), -1.1752011936438014)
|
||||
assertEquals(sinh(0.0), 0.0)
|
||||
assertEquals(sinh(1.0), 1.1752011936438014)
|
||||
assertEquals(sinh(2.0), 3.626860407847019)
|
||||
|
||||
assertEquals(js("Math.sinh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.sinh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.sinh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(sinh(-1.0), -1.1752011936438014)
|
||||
assertEquals(sinh(0.0), 0.0)
|
||||
assertEquals(sinh(1.0), 1.1752011936438014)
|
||||
assertEquals(sinh(2.0), 3.626860407847019)
|
||||
|
||||
assertEquals(js("Math.sinh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Int32Array.prototype.sort = function sort(compareFunction) {
|
||||
sort.called = true;
|
||||
return Array.prototype.sort.call(this, compareFunction);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val intArr = intArrayOf(5, 4, 3, 2, 1)
|
||||
.apply { sort { a, b -> a - b } }
|
||||
|
||||
assertEquals(intArr.joinToString(","), "1,2,3,4,5")
|
||||
assertEquals(js("Int32Array.prototype.sort.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Int32Array.prototype.sort = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
fun box(): String {
|
||||
val intArr = intArrayOf(5, 4, 3, 2, 1)
|
||||
.apply { sort { a, b -> a - b } }
|
||||
|
||||
assertEquals(intArr.joinToString(","), "1,2,3,4,5")
|
||||
assertEquals(js("Int32Array.prototype.sort.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.tanh = function tanh(x) {
|
||||
tanh.called = true;
|
||||
switch (x) {
|
||||
case -1: return -0.7615941559557649
|
||||
case 0: return 0
|
||||
case 1: return 0.7615941559557649
|
||||
case Infinity: return 1
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.tanh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(tanh(-1.0), -0.7615941559557649)
|
||||
assertEquals(tanh(0.0), 0.0)
|
||||
assertEquals(tanh(1.0), 0.7615941559557649)
|
||||
assertEquals(tanh(Double.POSITIVE_INFINITY), 1.0)
|
||||
|
||||
assertEquals(js("Math.tanh.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.tanh = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.tanh
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(tanh(-1.0), -0.7615941559557649)
|
||||
assertEquals(tanh(0.0), 0.0)
|
||||
assertEquals(tanh(1.0), 0.7615941559557649)
|
||||
assertEquals(tanh(Double.POSITIVE_INFINITY), 1.0)
|
||||
assertEquals(js("Math.tanh.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.trunc = function trunc(x) {
|
||||
trunc.called = true;
|
||||
if (isNaN(x)) {
|
||||
return NaN;
|
||||
}
|
||||
if (x > 0) {
|
||||
return Math.floor(x);
|
||||
}
|
||||
return Math.ceil(x);
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.truncate
|
||||
|
||||
fun box(): String {
|
||||
val result = truncate(1.188)
|
||||
|
||||
assertEquals(result, 1)
|
||||
assertEquals(js("Math.trunc.called"), true)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// WITH_STDLIB
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// FILE: main.js
|
||||
Math.trunc = undefined;
|
||||
|
||||
// FILE: main.kt
|
||||
import kotlin.math.truncate
|
||||
|
||||
fun box(): String {
|
||||
val result = truncate(1.188)
|
||||
|
||||
assertEquals(result, 1)
|
||||
assertEquals(js("Math.trunc.called"), js("undefined"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user