feat: add polyfills insertion for ES Next used features

This commit is contained in:
Artem Kobzar
2022-02-16 10:49:11 +00:00
committed by Space
parent 76ff717091
commit 804eb61bf0
80 changed files with 8769 additions and 6552 deletions
@@ -1248,7 +1248,6 @@ public class JsToStringGenerationVisitor extends JsVisitor {
p.print(javaScriptString(jsImport.getModule()));
}
private void newline() {
p.newline();
sourceLocationConsumer.newLine();
+5
View File
@@ -373,6 +373,10 @@ message Catch {
message Empty {
}
message Code {
required string value = 1;
}
message SingleLineComment {
required string message = 1;
}
@@ -404,6 +408,7 @@ message Fragment {
optional string dts = 15;
optional int32 suite_function = 16;
repeated int32 definitions = 17;
optional GlobalBlock polyfills = 18;
}
message InlinedLocalDeclarations {
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -333,7 +333,8 @@ val runMocha by task<NpmTask> {
environment.set(mapOf(
"KOTLIN_JS_LOCATION" to rootDir.resolve("dist/js/kotlin.js").toString(),
"KOTLIN_JS_TEST_LOCATION" to rootDir.resolve("dist/js/kotlin-test.js").toString()
"KOTLIN_JS_TEST_LOCATION" to rootDir.resolve("dist/js/kotlin-test.js").toString(),
"BOX_FLAG_LOCATION" to rootDir.resolve("compiler/testData/jsBoxFlag.js").toString()
))
}
@@ -132,7 +132,7 @@ fun getAllFilesForRunner(
val dceOutputDir = JsEnvironmentConfigurator.getJsArtifactsOutputDir(testServices, TranslationMode.FULL_DCE)
val artifactsPaths = modulesToArtifact.values.map { it.outputFile.absolutePath }.filter { !File(it).isDirectory }
val allJsFiles = additionalFiles + inputJsFilesBefore + artifactsPaths + commonFiles + additionalMainFiles + inputJsFilesAfter
val allJsFiles = additionalFiles + inputJsFilesBefore +artifactsPaths + commonFiles + additionalMainFiles + inputJsFilesAfter
val result = mutableMapOf(TranslationMode.FULL to allJsFiles)
@@ -8137,6 +8137,206 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills")
@TestDataPath("$PROJECT_ROOT")
public class Polyfills {
@Test
public void testAllFilesPresentInPolyfills() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/acosh")
@TestDataPath("$PROJECT_ROOT")
public class Acosh {
@Test
public void testAllFilesPresentInAcosh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/acosh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/asinh")
@TestDataPath("$PROJECT_ROOT")
public class Asinh {
@Test
public void testAllFilesPresentInAsinh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/asinh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/atanh")
@TestDataPath("$PROJECT_ROOT")
public class Atanh {
@Test
public void testAllFilesPresentInAtanh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/atanh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/clz32")
@TestDataPath("$PROJECT_ROOT")
public class Clz32 {
@Test
public void testAllFilesPresentInClz32() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/clz32"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/cosh")
@TestDataPath("$PROJECT_ROOT")
public class Cosh {
@Test
public void testAllFilesPresentInCosh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/cosh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/expm1")
@TestDataPath("$PROJECT_ROOT")
public class Expm1 {
@Test
public void testAllFilesPresentInExpm1() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/expm1"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/fill")
@TestDataPath("$PROJECT_ROOT")
public class Fill {
@Test
public void testAllFilesPresentInFill() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/fill"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/globalThis")
@TestDataPath("$PROJECT_ROOT")
public class GlobalThis {
@Test
public void testAllFilesPresentInGlobalThis() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/globalThis"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/hypot")
@TestDataPath("$PROJECT_ROOT")
public class Hypot {
@Test
public void testAllFilesPresentInHypot() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/hypot"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/imul")
@TestDataPath("$PROJECT_ROOT")
public class Imul {
@Test
public void testAllFilesPresentInImul() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/imul"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/isView")
@TestDataPath("$PROJECT_ROOT")
public class IsView {
@Test
public void testAllFilesPresentInIsView() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/isView"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log10")
@TestDataPath("$PROJECT_ROOT")
public class Log10 {
@Test
public void testAllFilesPresentInLog10() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log10"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log1p")
@TestDataPath("$PROJECT_ROOT")
public class Log1p {
@Test
public void testAllFilesPresentInLog1p() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log1p"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log2")
@TestDataPath("$PROJECT_ROOT")
public class Log2 {
@Test
public void testAllFilesPresentInLog2() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log2"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sign")
@TestDataPath("$PROJECT_ROOT")
public class Sign {
@Test
public void testAllFilesPresentInSign() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sign"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sinh")
@TestDataPath("$PROJECT_ROOT")
public class Sinh {
@Test
public void testAllFilesPresentInSinh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sinh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sort")
@TestDataPath("$PROJECT_ROOT")
public class Sort {
@Test
public void testAllFilesPresentInSort() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sort"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/tanh")
@TestDataPath("$PROJECT_ROOT")
public class Tanh {
@Test
public void testAllFilesPresentInTanh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/tanh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/trunc")
@TestDataPath("$PROJECT_ROOT")
public class Trunc {
@Test
public void testAllFilesPresentInTrunc() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/trunc"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
}
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/propertyAccess")
@TestDataPath("$PROJECT_ROOT")
@@ -8533,6 +8533,434 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills")
@TestDataPath("$PROJECT_ROOT")
public class Polyfills {
@Test
public void testAllFilesPresentInPolyfills() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/acosh")
@TestDataPath("$PROJECT_ROOT")
public class Acosh {
@Test
@TestMetadata("acoshWithExistedIntrinsic.kt")
public void testAcoshWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/acosh/acoshWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("acoshWithoutExistedIntrinsic.kt")
public void testAcoshWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/acosh/acoshWithoutExistedIntrinsic.kt");
}
@Test
public void testAllFilesPresentInAcosh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/acosh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/asinh")
@TestDataPath("$PROJECT_ROOT")
public class Asinh {
@Test
public void testAllFilesPresentInAsinh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/asinh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("asinhWithExistedIntrinsic.kt")
public void testAsinhWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/asinh/asinhWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("asinhWithoutExistedIntrinsic.kt")
public void testAsinhWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/asinh/asinhWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/atanh")
@TestDataPath("$PROJECT_ROOT")
public class Atanh {
@Test
public void testAllFilesPresentInAtanh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/atanh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("atanhWithExistedIntrinsic.kt")
public void testAtanhWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/atanh/atanhWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("atanhWithoutExistedIntrinsic.kt")
public void testAtanhWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/atanh/atanhWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/clz32")
@TestDataPath("$PROJECT_ROOT")
public class Clz32 {
@Test
public void testAllFilesPresentInClz32() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/clz32"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("clz32WithExistedIntrinsic.kt")
public void testClz32WithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/clz32/clz32WithExistedIntrinsic.kt");
}
@Test
@TestMetadata("clz32WithoutExistedIntrinsic.kt")
public void testClz32WithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/clz32/clz32WithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/cosh")
@TestDataPath("$PROJECT_ROOT")
public class Cosh {
@Test
public void testAllFilesPresentInCosh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/cosh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("coshWithExistedIntrinsic.kt")
public void testCoshWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/cosh/coshWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("coshWithoutExistedIntrinsic.kt")
public void testCoshWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/cosh/coshWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/expm1")
@TestDataPath("$PROJECT_ROOT")
public class Expm1 {
@Test
public void testAllFilesPresentInExpm1() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/expm1"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("expm1WithExistedIntrinsic.kt")
public void testExpm1WithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/expm1/expm1WithExistedIntrinsic.kt");
}
@Test
@TestMetadata("expm1WithoutExistedIntrinsic.kt")
public void testExpm1WithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/expm1/expm1WithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/fill")
@TestDataPath("$PROJECT_ROOT")
public class Fill {
@Test
public void testAllFilesPresentInFill() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/fill"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("arrayFillWithExistedIntrinsic.kt")
public void testArrayFillWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/fill/arrayFillWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("arrayFillWithoutExistedIntrinsic.kt")
public void testArrayFillWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/fill/arrayFillWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/globalThis")
@TestDataPath("$PROJECT_ROOT")
public class GlobalThis {
@Test
public void testAllFilesPresentInGlobalThis() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/globalThis"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("globalThisWithExistedIntrinsic.kt")
public void testGlobalThisWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/globalThis/globalThisWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("globalThisWithoutExistedIntrinsic.kt")
public void testGlobalThisWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/globalThis/globalThisWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/hypot")
@TestDataPath("$PROJECT_ROOT")
public class Hypot {
@Test
public void testAllFilesPresentInHypot() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/hypot"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("hypotWithExistedIntrinsic.kt")
public void testHypotWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/hypot/hypotWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("hypotWithoutExistedIntrinsic.kt")
public void testHypotWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/hypot/hypotWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/imul")
@TestDataPath("$PROJECT_ROOT")
public class Imul {
@Test
public void testAllFilesPresentInImul() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/imul"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("imulWithExistedIntrinsic.kt")
public void testImulWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/imul/imulWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("imulWithoutExistedIntrinsic.kt")
public void testImulWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/imul/imulWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/isView")
@TestDataPath("$PROJECT_ROOT")
public class IsView {
@Test
public void testAllFilesPresentInIsView() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/isView"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("isViewWithExistedIntrinsic.kt")
public void testIsViewWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/isView/isViewWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("isViewWithoutExistedIntrinsic.kt")
public void testIsViewWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/isView/isViewWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log10")
@TestDataPath("$PROJECT_ROOT")
public class Log10 {
@Test
public void testAllFilesPresentInLog10() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log10"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("log10WithExistedIntrinsic.kt")
public void testLog10WithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log10/log10WithExistedIntrinsic.kt");
}
@Test
@TestMetadata("log10WithoutExistedIntrinsic.kt")
public void testLog10WithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log10/log10WithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log1p")
@TestDataPath("$PROJECT_ROOT")
public class Log1p {
@Test
public void testAllFilesPresentInLog1p() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log1p"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("log1pWithExistedIntrinsic.kt")
public void testLog1pWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log1p/log1pWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("log1pWithoutExistedIntrinsic.kt")
public void testLog1pWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log1p/log1pWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/log2")
@TestDataPath("$PROJECT_ROOT")
public class Log2 {
@Test
public void testAllFilesPresentInLog2() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/log2"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("log2WithExistedIntrinsic.kt")
public void testLog2WithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log2/log2WithExistedIntrinsic.kt");
}
@Test
@TestMetadata("log2WithoutExistedIntrinsic.kt")
public void testLog2WithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/log2/log2WithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sign")
@TestDataPath("$PROJECT_ROOT")
public class Sign {
@Test
public void testAllFilesPresentInSign() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sign"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("signWithExistedIntrinsic.kt")
public void testSignWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sign/signWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("signWithoutExistedIntrinsic.kt")
public void testSignWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sign/signWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sinh")
@TestDataPath("$PROJECT_ROOT")
public class Sinh {
@Test
public void testAllFilesPresentInSinh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sinh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("sinhWithExistedIntrinsic.kt")
public void testSinhWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sinh/sinhWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("sinhWithoutExistedIntrinsic.kt")
public void testSinhWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sinh/sinhWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/sort")
@TestDataPath("$PROJECT_ROOT")
public class Sort {
@Test
public void testAllFilesPresentInSort() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/sort"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("sortWithExistedIntrinsic.kt")
public void testSortWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sort/sortWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("sortWithoutExistedIntrinsic.kt")
public void testSortWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/sort/sortWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/tanh")
@TestDataPath("$PROJECT_ROOT")
public class Tanh {
@Test
public void testAllFilesPresentInTanh() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/tanh"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("tanhWithExistedIntrinsic.kt")
public void testTanhWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/tanh/tanhWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("tanhWithoutExistedIntrinsic.kt")
public void testTanhWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/tanh/tanhWithoutExistedIntrinsic.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/polyfills/trunc")
@TestDataPath("$PROJECT_ROOT")
public class Trunc {
@Test
public void testAllFilesPresentInTrunc() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/polyfills/trunc"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("truncWithExistedIntrinsic.kt")
public void testTruncWithExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/trunc/truncWithExistedIntrinsic.kt");
}
@Test
@TestMetadata("truncWithoutExistedIntrinsic.kt")
public void testTruncWithoutExistedIntrinsic() throws Exception {
runTest("js/js.translator/testData/box/polyfills/trunc/truncWithoutExistedIntrinsic.kt");
}
}
}
@Nested
@TestMetadata("js/js.translator/testData/box/propertyAccess")
@TestDataPath("$PROJECT_ROOT")
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}