diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index 8d1a1dc49d1..a3a61b0f608 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -99,6 +99,10 @@ class K2JSCompilerArguments : CommonCompilerArguments() { // Advanced options + @GradleOption(DefaultValues.BooleanTrueDefault::class) + @Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays") + var typedArrays: Boolean by FreezableVar(true) + @GradleOption(DefaultValues.BooleanFalseDefault::class) @Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export") var friendModulesDisabled: Boolean by FreezableVar(false) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java index cea1d747218..f87ee0da090 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java @@ -385,6 +385,8 @@ public class K2JSCompiler extends CLICompiler { configuration.put(JSConfigurationKeys.META_INFO, true); } + configuration.put(JSConfigurationKeys.TYPED_ARRAYS_ENABLED, arguments.getTypedArrays()); + configuration.put(JSConfigurationKeys.FRIEND_PATHS_DISABLED, arguments.getFriendModulesDisabled()); if (!arguments.getFriendModulesDisabled() && arguments.getFriendModules() != null) { diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index e15c1966208..e504657eb9d 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -2,6 +2,7 @@ Usage: kotlinc-js where advanced options include: -Xfriend-modules= Paths to friend modules -Xfriend-modules-disabled Disable internal declaration export + -Xtyped-arrays Translate primitive arrays to JS typed arrays -Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info -Xcoroutines={enable|warn|error} Enable coroutines or report warnings or errors on declarations and use sites of 'suspend' modifier diff --git a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt index 45362802d07..8d38a98c52a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt @@ -71,5 +71,9 @@ fun main(args: Array) { testClass { model("codegen/boxInline/defaultValues/", targetBackend = TargetBackend.JS) } + + testClass { + model("codegen/box/arrays", targetBackend = TargetBackend.JS) + } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index cbf3ef11a1c..91754638873 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -70,6 +70,7 @@ abstract class BasicBoxTest( protected val pathToTestDir: String, testGroupOutputDirPrefix: String, pathToRootOutputDir: String = BasicBoxTest.TEST_DATA_DIR_PATH, + private val typedArraysEnabled: Boolean = true, private val generateSourceMap: Boolean = false, private val generateNodeJsRunner: Boolean = true ) : KotlinTestWithEnvironment() { @@ -566,6 +567,8 @@ abstract class BasicBoxTest( configuration.put(JSConfigurationKeys.SOURCE_MAP_SOURCE_ROOTS, sourceDirs) configuration.put(JSConfigurationKeys.SOURCE_MAP_EMBED_SOURCES, module.sourceMapSourceEmbedding) + configuration.put(JSConfigurationKeys.TYPED_ARRAYS_ENABLED, typedArraysEnabled) + return JsConfig(project, configuration, METADATA_CACHE, (JsConfig.JS_STDLIB + JsConfig.JS_KOTLIN_TEST).toSet()) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsLegacyPrimitiveArraysBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsLegacyPrimitiveArraysBoxTestGenerated.java new file mode 100644 index 00000000000..589db40d6f3 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsLegacyPrimitiveArraysBoxTestGenerated.java @@ -0,0 +1,552 @@ +/* + * Copyright 2000-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 org.jetbrains.kotlin.js.test.semantics; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/codegen/box/arrays") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class JsLegacyPrimitiveArraysBoxTestGenerated extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInArrays() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("arrayConstructorsSimple.kt") + public void testArrayConstructorsSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt"); + doTest(fileName); + } + + @TestMetadata("arrayGetAssignMultiIndex.kt") + public void testArrayGetAssignMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayGetAssignMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("arrayGetMultiIndex.kt") + public void testArrayGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("arrayInstanceOf.kt") + public void testArrayInstanceOf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayInstanceOf.kt"); + doTest(fileName); + } + + @TestMetadata("arrayPlusAssign.kt") + public void testArrayPlusAssign() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayPlusAssign.kt"); + doTest(fileName); + } + + @TestMetadata("arraysAreCloneable.kt") + public void testArraysAreCloneable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arraysAreCloneable.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("cloneArray.kt") + public void testCloneArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/cloneArray.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("clonePrimitiveArrays.kt") + public void testClonePrimitiveArrays() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/clonePrimitiveArrays.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("collectionAssignGetMultiIndex.kt") + public void testCollectionAssignGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/collectionAssignGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("collectionGetMultiIndex.kt") + public void testCollectionGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/collectionGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forEachBooleanArray.kt") + public void testForEachBooleanArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachBooleanArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachByteArray.kt") + public void testForEachByteArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachByteArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachCharArray.kt") + public void testForEachCharArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachCharArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachDoubleArray.kt") + public void testForEachDoubleArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachDoubleArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachFloatArray.kt") + public void testForEachFloatArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachFloatArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachIntArray.kt") + public void testForEachIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachIntArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachLongArray.kt") + public void testForEachLongArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachLongArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachShortArray.kt") + public void testForEachShortArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachShortArray.kt"); + doTest(fileName); + } + + @TestMetadata("genericArrayInObjectLiteralConstructor.kt") + public void testGenericArrayInObjectLiteralConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/genericArrayInObjectLiteralConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("hashMap.kt") + public void testHashMap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/hashMap.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionAsParameter.kt") + public void testInProjectionAsParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionAsParameter.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionOfArray.kt") + public void testInProjectionOfArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionOfArray.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionOfList.kt") + public void testInProjectionOfList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionOfList.kt"); + doTest(fileName); + } + + @TestMetadata("indices.kt") + public void testIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/indices.kt"); + doTest(fileName); + } + + @TestMetadata("indicesChar.kt") + public void testIndicesChar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/indicesChar.kt"); + doTest(fileName); + } + + @TestMetadata("iterator.kt") + public void testIterator() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iterator.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorBooleanArray.kt") + public void testIteratorBooleanArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorByteArray.kt") + public void testIteratorByteArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorByteArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorByteArrayNextByte.kt") + public void testIteratorByteArrayNextByte() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorCharArray.kt") + public void testIteratorCharArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorCharArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorDoubleArray.kt") + public void testIteratorDoubleArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorFloatArray.kt") + public void testIteratorFloatArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorFloatArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorIntArray.kt") + public void testIteratorIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorIntArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorLongArray.kt") + public void testIteratorLongArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorLongArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorLongArrayNextLong.kt") + public void testIteratorLongArrayNextLong() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorShortArray.kt") + public void testIteratorShortArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorShortArray.kt"); + doTest(fileName); + } + + @TestMetadata("kt1291.kt") + public void testKt1291() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt1291.kt"); + doTest(fileName); + } + + @TestMetadata("kt17134.kt") + public void testKt17134() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt17134.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt238.kt") + public void testKt238() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt238.kt"); + doTest(fileName); + } + + @TestMetadata("kt2997.kt") + public void testKt2997() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt2997.kt"); + doTest(fileName); + } + + @TestMetadata("kt33.kt") + public void testKt33() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt33.kt"); + doTest(fileName); + } + + @TestMetadata("kt3771.kt") + public void testKt3771() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt3771.kt"); + doTest(fileName); + } + + @TestMetadata("kt4118.kt") + public void testKt4118() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4118.kt"); + doTest(fileName); + } + + @TestMetadata("kt4348.kt") + public void testKt4348() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4348.kt"); + doTest(fileName); + } + + @TestMetadata("kt4357.kt") + public void testKt4357() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4357.kt"); + doTest(fileName); + } + + @TestMetadata("kt503.kt") + public void testKt503() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt503.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt594.kt") + public void testKt594() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt594.kt"); + doTest(fileName); + } + + @TestMetadata("kt602.kt") + public void testKt602() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt602.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt7009.kt") + public void testKt7009() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7009.kt"); + doTest(fileName); + } + + @TestMetadata("kt7288.kt") + public void testKt7288() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7288.kt"); + doTest(fileName); + } + + @TestMetadata("kt7338.kt") + public void testKt7338() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7338.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt779.kt") + public void testKt779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt779.kt"); + doTest(fileName); + } + + @TestMetadata("kt945.kt") + public void testKt945() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt945.kt"); + doTest(fileName); + } + + @TestMetadata("kt950.kt") + public void testKt950() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt950.kt"); + doTest(fileName); + } + + @TestMetadata("longAsIndex.kt") + public void testLongAsIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/longAsIndex.kt"); + doTest(fileName); + } + + @TestMetadata("multiArrayConstructors.kt") + public void testMultiArrayConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiArrayConstructors.kt"); + doTest(fileName); + } + + @TestMetadata("nonLocalReturnArrayConstructor.kt") + public void testNonLocalReturnArrayConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/nonLocalReturnArrayConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("nonNullArray.kt") + public void testNonNullArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/nonNullArray.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveArrays.kt") + public void testPrimitiveArrays() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/primitiveArrays.kt"); + doTest(fileName); + } + + @TestMetadata("stdlib.kt") + public void testStdlib() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/stdlib.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class MultiDecl extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInMultiDecl() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclFor.kt") + public void testMultiDeclFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForValCaptured.kt") + public void testMultiDeclForValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl/int") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Int extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInInt() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl/int"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensionsValCaptured.kt") + public void testMultiDeclForComponentExtensionsValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl/long") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Long extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInLong() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl/long"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensionsValCaptured.kt") + public void testMultiDeclForComponentExtensionsValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + } + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsTypedArraysBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsTypedArraysBoxTestGenerated.java new file mode 100644 index 00000000000..dba1ebe0809 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsTypedArraysBoxTestGenerated.java @@ -0,0 +1,563 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.js.test.semantics; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/testData/codegen/box/arrays") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class JsTypedArraysBoxTestGenerated extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInArrays() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("arrayConstructorsSimple.kt") + public void testArrayConstructorsSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayConstructorsSimple.kt"); + doTest(fileName); + } + + @TestMetadata("arrayGetAssignMultiIndex.kt") + public void testArrayGetAssignMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayGetAssignMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("arrayGetMultiIndex.kt") + public void testArrayGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("arrayInstanceOf.kt") + public void testArrayInstanceOf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayInstanceOf.kt"); + doTest(fileName); + } + + @TestMetadata("arrayPlusAssign.kt") + public void testArrayPlusAssign() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arrayPlusAssign.kt"); + doTest(fileName); + } + + @TestMetadata("arraysAreCloneable.kt") + public void testArraysAreCloneable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/arraysAreCloneable.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("cloneArray.kt") + public void testCloneArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/cloneArray.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("clonePrimitiveArrays.kt") + public void testClonePrimitiveArrays() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/clonePrimitiveArrays.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("collectionAssignGetMultiIndex.kt") + public void testCollectionAssignGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/collectionAssignGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("collectionGetMultiIndex.kt") + public void testCollectionGetMultiIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/collectionGetMultiIndex.kt"); + doTest(fileName); + } + + @TestMetadata("forEachBooleanArray.kt") + public void testForEachBooleanArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachBooleanArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachByteArray.kt") + public void testForEachByteArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachByteArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachCharArray.kt") + public void testForEachCharArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachCharArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachDoubleArray.kt") + public void testForEachDoubleArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachDoubleArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachFloatArray.kt") + public void testForEachFloatArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachFloatArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachIntArray.kt") + public void testForEachIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachIntArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachLongArray.kt") + public void testForEachLongArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachLongArray.kt"); + doTest(fileName); + } + + @TestMetadata("forEachShortArray.kt") + public void testForEachShortArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/forEachShortArray.kt"); + doTest(fileName); + } + + @TestMetadata("genericArrayInObjectLiteralConstructor.kt") + public void testGenericArrayInObjectLiteralConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/genericArrayInObjectLiteralConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("hashMap.kt") + public void testHashMap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/hashMap.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionAsParameter.kt") + public void testInProjectionAsParameter() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionAsParameter.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionOfArray.kt") + public void testInProjectionOfArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionOfArray.kt"); + doTest(fileName); + } + + @TestMetadata("inProjectionOfList.kt") + public void testInProjectionOfList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/inProjectionOfList.kt"); + doTest(fileName); + } + + @TestMetadata("indices.kt") + public void testIndices() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/indices.kt"); + doTest(fileName); + } + + @TestMetadata("indicesChar.kt") + public void testIndicesChar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/indicesChar.kt"); + doTest(fileName); + } + + @TestMetadata("iterator.kt") + public void testIterator() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iterator.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorBooleanArray.kt") + public void testIteratorBooleanArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorByteArray.kt") + public void testIteratorByteArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorByteArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorByteArrayNextByte.kt") + public void testIteratorByteArrayNextByte() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorCharArray.kt") + public void testIteratorCharArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorCharArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorDoubleArray.kt") + public void testIteratorDoubleArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorFloatArray.kt") + public void testIteratorFloatArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorFloatArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorIntArray.kt") + public void testIteratorIntArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorIntArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorLongArray.kt") + public void testIteratorLongArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorLongArray.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorLongArrayNextLong.kt") + public void testIteratorLongArrayNextLong() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt"); + doTest(fileName); + } + + @TestMetadata("iteratorShortArray.kt") + public void testIteratorShortArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/iteratorShortArray.kt"); + doTest(fileName); + } + + @TestMetadata("kt1291.kt") + public void testKt1291() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt1291.kt"); + doTest(fileName); + } + + @TestMetadata("kt17134.kt") + public void testKt17134() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt17134.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt238.kt") + public void testKt238() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt238.kt"); + doTest(fileName); + } + + @TestMetadata("kt2997.kt") + public void testKt2997() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt2997.kt"); + doTest(fileName); + } + + @TestMetadata("kt33.kt") + public void testKt33() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt33.kt"); + doTest(fileName); + } + + @TestMetadata("kt3771.kt") + public void testKt3771() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt3771.kt"); + doTest(fileName); + } + + @TestMetadata("kt4118.kt") + public void testKt4118() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4118.kt"); + doTest(fileName); + } + + @TestMetadata("kt4348.kt") + public void testKt4348() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4348.kt"); + doTest(fileName); + } + + @TestMetadata("kt4357.kt") + public void testKt4357() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt4357.kt"); + doTest(fileName); + } + + @TestMetadata("kt503.kt") + public void testKt503() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt503.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt594.kt") + public void testKt594() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt594.kt"); + doTest(fileName); + } + + @TestMetadata("kt602.kt") + public void testKt602() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt602.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt7009.kt") + public void testKt7009() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7009.kt"); + doTest(fileName); + } + + @TestMetadata("kt7288.kt") + public void testKt7288() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7288.kt"); + doTest(fileName); + } + + @TestMetadata("kt7338.kt") + public void testKt7338() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt7338.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("kt779.kt") + public void testKt779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt779.kt"); + doTest(fileName); + } + + @TestMetadata("kt945.kt") + public void testKt945() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt945.kt"); + doTest(fileName); + } + + @TestMetadata("kt950.kt") + public void testKt950() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/kt950.kt"); + doTest(fileName); + } + + @TestMetadata("longAsIndex.kt") + public void testLongAsIndex() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/longAsIndex.kt"); + doTest(fileName); + } + + @TestMetadata("multiArrayConstructors.kt") + public void testMultiArrayConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiArrayConstructors.kt"); + doTest(fileName); + } + + @TestMetadata("nonLocalReturnArrayConstructor.kt") + public void testNonLocalReturnArrayConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/nonLocalReturnArrayConstructor.kt"); + doTest(fileName); + } + + @TestMetadata("nonNullArray.kt") + public void testNonNullArray() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/nonNullArray.kt"); + doTest(fileName); + } + + @TestMetadata("primitiveArrays.kt") + public void testPrimitiveArrays() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/primitiveArrays.kt"); + doTest(fileName); + } + + @TestMetadata("stdlib.kt") + public void testStdlib() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/stdlib.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class MultiDecl extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInMultiDecl() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("kt15560.kt") + public void testKt15560() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15560.kt"); + doTest(fileName); + } + + @TestMetadata("kt15568.kt") + public void testKt15568() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15568.kt"); + doTest(fileName); + } + + @TestMetadata("kt15575.kt") + public void testKt15575() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/kt15575.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclFor.kt") + public void testMultiDeclFor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclFor.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForValCaptured.kt") + public void testMultiDeclForValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl/int") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Int extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInInt() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl/int"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensionsValCaptured.kt") + public void testMultiDeclForComponentExtensionsValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/codegen/box/arrays/multiDecl/long") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Long extends AbstractJsLegacyPrimitiveArraysBoxTest { + public void testAllFilesPresentInLong() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/arrays/multiDecl/long"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("MultiDeclForComponentExtensions.kt") + public void testMultiDeclForComponentExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentExtensionsValCaptured.kt") + public void testMultiDeclForComponentExtensionsValCaptured() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensions.kt") + public void testMultiDeclForComponentMemberExtensions() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentMemberExtensions.kt"); + doTest(fileName); + } + + @TestMetadata("MultiDeclForComponentMemberExtensionsInExtensionFunction.kt") + public void testMultiDeclForComponentMemberExtensionsInExtensionFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentMemberExtensionsInExtensionFunction.kt"); + doTest(fileName); + } + } + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/abstractClassesForGeneratedTests.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/abstractClassesForGeneratedTests.kt index 6539e85c553..380f6c1e590 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/abstractClassesForGeneratedTests.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/abstractClassesForGeneratedTests.kt @@ -41,6 +41,12 @@ abstract class AbstractJsCodegenBoxTest : BasicBoxTest( "codegen/box/" ) +abstract class AbstractJsLegacyPrimitiveArraysBoxTest : BasicBoxTest( + "compiler/testData/codegen/box/arrays/", + "codegen/box/arrays-legacy-primitivearrays/", + typedArraysEnabled = false +) + abstract class AbstractSourceMapGenerationSmokeTest : BasicBoxTest( BasicBoxTest.TEST_DATA_DIR_PATH + "sourcemap/", "sourcemap/", diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java index d83b5c8b0c2..13b84fe8b81 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/PatternTranslator.java @@ -200,7 +200,13 @@ public final class PatternTranslator extends AbstractTranslator { } if (isArray(type)) { - return namer().isArray(); + if (ArrayFIF.typedArraysEnabled(context().getConfig())) { + return namer().isArray(); + } + else { + return Namer.IS_ARRAY_FUN_REF; + } + } if (TypePredicatesKt.getCHAR_SEQUENCE().test(type)) return namer().isCharSequence(); @@ -238,10 +244,12 @@ public final class PatternTranslator extends AbstractTranslator { return namer().isTypeOf(new JsStringLiteral("number")); } - if (KotlinBuiltIns.isPrimitiveArray(type)) { - PrimitiveType arrayType = KotlinBuiltIns.getPrimitiveArrayElementType(type); - assert arrayType != null; - return namer().isPrimitiveArray(arrayType); + if (ArrayFIF.typedArraysEnabled(context().getConfig())) { + if (KotlinBuiltIns.isPrimitiveArray(type)) { + PrimitiveType arrayType = KotlinBuiltIns.getPrimitiveArrayElementType(type); + assert arrayType != null; + return namer().isPrimitiveArray(arrayType); + } } return null; diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt index aab3f1e3270..3d688519680 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/ArrayFIF.kt @@ -61,12 +61,16 @@ object ArrayFIF : CompositeFIF() { @JvmField val LENGTH_PROPERTY_INTRINSIC = BuiltInPropertyIntrinsic("length") + @JvmStatic + fun typedArraysEnabled(config: JsConfig) = config.configuration.get(JSConfigurationKeys.TYPED_ARRAYS_ENABLED, true) + fun castOrCreatePrimitiveArray(ctx: TranslationContext, type: PrimitiveType?, arg: JsArrayLiteral): JsExpression { - if (type == null) return arg + if (type == null || !typedArraysEnabled(ctx.config)) return arg return if (type in TYPED_ARRAY_MAP) { createTypedArray(type, arg) - } else { + } + else { JsAstUtils.invokeKotlinFunction(type.lowerCaseName + "ArrayOf", *arg.expressions.toTypedArray()) } } @@ -96,10 +100,21 @@ object ArrayFIF : CompositeFIF() { if (functionParam.type.getValueParameterTypesFromFunctionType().size != 1) return null val primitiveType = KotlinBuiltIns.getPrimitiveArrayElementType(constructedClass.defaultType) - return when { - primitiveType in TYPED_ARRAY_MAP -> "kotlin.fillArray" - primitiveType != null -> "kotlin.${primitiveType.lowerCaseName}ArrayF" - else -> "kotlin.newArrayF" + return if (typedArraysEnabled(config) && primitiveType != null) { + if (primitiveType in TYPED_ARRAY_MAP) { + "kotlin.fillArray" + } + else { + "kotlin.${primitiveType.lowerCaseName}ArrayF" + } + } + else { + if (primitiveType == CHAR) { + "kotlin.untypedCharArrayF" + } + else { + "kotlin.newArrayF" + } } } @@ -118,11 +133,23 @@ object ArrayFIF : CompositeFIF() { add(pattern(NamePredicate(type.arrayTypeName), "(Int)"), intrinsify { _, arguments, context -> assert(arguments.size == 1) { "Array (Int) expression must have one argument." } val (size) = arguments - if (type in TYPED_ARRAY_MAP) { - createTypedArray(type, size) - } else { - JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}Array", size) + if (typedArraysEnabled(context.config)) { + if (type in TYPED_ARRAY_MAP) { + createTypedArray(type, size) + } + else { + JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}Array", size) + + } + } + else { + val initValue = when (type) { + BOOLEAN -> JsBooleanLiteral(false) + LONG -> JsNameRef(Namer.LONG_ZERO, Namer.kotlinLong()) + else -> JsIntLiteral(0) + } + JsAstUtils.invokeKotlinFunction("newArray", size, initValue) } }) @@ -130,7 +157,12 @@ object ArrayFIF : CompositeFIF() { add(pattern(NamePredicate(type.arrayTypeName), "iterator"), intrinsify { callInfo, _, context -> val receiver = callInfo.dispatchReceiver - JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayIterator", receiver!!) + if (typedArraysEnabled(context.config)) { + JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayIterator", receiver!!) + } + else { + JsAstUtils.invokeKotlinFunction("arrayIterator", receiver!!, JsStringLiteral(type.arrayTypeName.asString())) + } }) } @@ -148,10 +180,16 @@ object ArrayFIF : CompositeFIF() { return intrinsify { callInfo, arguments, context -> assert(arguments.size == 2) { "Array (Int,Function1) expression must have two arguments." } val (size, fn) = arguments - val invocation = when { - type in TYPED_ARRAY_MAP -> JsAstUtils.invokeKotlinFunction("fillArray", createTypedArray(type!!, size), fn) - type != null -> JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayF", size, fn) - else -> JsAstUtils.invokeKotlinFunction("newArrayF", size, fn) + val invocation = if (typedArraysEnabled(context.config) && type != null) { + if (type in TYPED_ARRAY_MAP) { + JsAstUtils.invokeKotlinFunction("fillArray", createTypedArray(type, size), fn) + } + else { + JsAstUtils.invokeKotlinFunction("${type.lowerCaseName}ArrayF", size, fn) + } + } + else { + JsAstUtils.invokeKotlinFunction(if (type == CHAR) "untypedCharArrayF" else "newArrayF", size, fn) } invocation.inlineStrategy = InlineStrategy.IN_PLACE val descriptor = callInfo.resolvedCall.resultingDescriptor.original @@ -165,10 +203,10 @@ object ArrayFIF : CompositeFIF() { } } - private fun intrinsify(f: (callInfo: CallInfo, arguments: List, context: TranslationContext) -> JsExpression) = - object : FunctionIntrinsic() { - override fun apply(callInfo: CallInfo, arguments: List, context: TranslationContext): JsExpression { - return f(callInfo, arguments, context) - } + private fun intrinsify(f: (callInfo: CallInfo, arguments: List, context: TranslationContext) -> JsExpression) + = object : FunctionIntrinsic() { + override fun apply(callInfo: CallInfo, arguments: List, context: TranslationContext): JsExpression { + return f(callInfo, arguments, context) } + } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions.kt index 611fef8e4a9..7a937606991 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptions.kt @@ -67,4 +67,10 @@ interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions * Default value: "v5" */ var target: kotlin.String + + /** + * Translate primitive arrays to JS typed arrays + * Default value: true + */ + var typedArrays: kotlin.Boolean } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptionsBase.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptionsBase.kt index e4b43497f76..0330b1b3cb7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptionsBase.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinJsOptionsBase.kt @@ -79,6 +79,11 @@ internal abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.Ko get() = targetField ?: "v5" set(value) { targetField = value } + private var typedArraysField: kotlin.Boolean? = null + override var typedArrays: kotlin.Boolean + get() = typedArraysField ?: true + set(value) { typedArraysField = value } + internal open fun updateArguments(args: org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments) { allWarningsAsErrorsField?.let { args.allWarningsAsErrors = it } suppressWarningsField?.let { args.suppressWarnings = it } @@ -95,6 +100,7 @@ internal abstract class KotlinJsOptionsBase : org.jetbrains.kotlin.gradle.dsl.Ko sourceMapEmbedSourcesField?.let { args.sourceMapEmbedSources = it } sourceMapPrefixField?.let { args.sourceMapPrefix = it } targetField?.let { args.target = it } + typedArraysField?.let { args.typedArrays = it } } } @@ -114,4 +120,5 @@ internal fun org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments.fil sourceMapEmbedSources = null sourceMapPrefix = null target = "v5" + typedArrays = true }