[JS IR] Add test with boolean in external interface
[JS IR] Add possibility to safely access Boolean in external declaration [JS IR] Add diagnostic for booleans in externals
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.config
|
||||
|
||||
enum class DceRuntimeDiagnostic {
|
||||
LOG,
|
||||
EXCEPTION;
|
||||
|
||||
companion object
|
||||
}
|
||||
|
||||
fun DceRuntimeDiagnostic.removingBody(): Boolean {
|
||||
return this != DceRuntimeDiagnostic.LOG
|
||||
}
|
||||
|
||||
fun DceRuntimeDiagnostic.dceRuntimeDiagnosticToArgumentOfUnreachableMethod(): Int {
|
||||
return when (this) {
|
||||
DceRuntimeDiagnostic.LOG -> 0
|
||||
DceRuntimeDiagnostic.EXCEPTION -> 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.config
|
||||
|
||||
enum class RuntimeDiagnostic {
|
||||
LOG,
|
||||
EXCEPTION;
|
||||
|
||||
companion object
|
||||
}
|
||||
@@ -150,6 +150,7 @@ abstract class BasicBoxTest(
|
||||
val splitPerModule = SPLIT_PER_MODULE.matcher(fileContent).find()
|
||||
|
||||
val propertyLazyInitialization = PROPERTY_LAZY_INITIALIZATION.matcher(fileContent).find()
|
||||
val safeExternalBoolean = SAFE_EXTERNAL_BOOLEAN.matcher(fileContent).find()
|
||||
|
||||
TestFileFactoryImpl().use { testFactory ->
|
||||
val inputFiles = TestFiles.createTestFiles(
|
||||
@@ -214,7 +215,8 @@ abstract class BasicBoxTest(
|
||||
skipDceDriven,
|
||||
splitPerModule,
|
||||
errorPolicy,
|
||||
propertyLazyInitialization
|
||||
propertyLazyInitialization,
|
||||
safeExternalBoolean
|
||||
)
|
||||
|
||||
when {
|
||||
@@ -468,6 +470,7 @@ abstract class BasicBoxTest(
|
||||
splitPerModule: Boolean,
|
||||
errorIgnorancePolicy: ErrorTolerancePolicy,
|
||||
propertyLazyInitialization: Boolean,
|
||||
safeExternalBoolean: Boolean,
|
||||
) {
|
||||
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
|
||||
val testFiles = kotlinFiles.map { it.fileName }
|
||||
@@ -518,6 +521,7 @@ abstract class BasicBoxTest(
|
||||
skipDceDriven,
|
||||
splitPerModule,
|
||||
propertyLazyInitialization,
|
||||
safeExternalBoolean,
|
||||
)
|
||||
|
||||
if (incrementalCompilationChecksEnabled && module.hasFilesToRecompile) {
|
||||
@@ -608,10 +612,11 @@ abstract class BasicBoxTest(
|
||||
testPackage,
|
||||
testFunction,
|
||||
needsFullIrRuntime,
|
||||
isMainModule = false,
|
||||
skipDceDriven = true,
|
||||
splitPerModule = false,
|
||||
isMainModule = false,
|
||||
skipDceDriven = true,
|
||||
splitPerModule = false,
|
||||
propertyLazyInitialization = false,
|
||||
safeExternalBoolean = false,
|
||||
)
|
||||
|
||||
val originalOutput = FileUtil.loadFile(outputFile)
|
||||
@@ -691,6 +696,7 @@ abstract class BasicBoxTest(
|
||||
skipDceDriven: Boolean,
|
||||
splitPerModule: Boolean,
|
||||
propertyLazyInitialization: Boolean,
|
||||
safeExternalBoolean: Boolean,
|
||||
) {
|
||||
val translator = K2JSTranslator(config, false)
|
||||
val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters)
|
||||
@@ -1094,6 +1100,8 @@ abstract class BasicBoxTest(
|
||||
|
||||
private val PROPERTY_LAZY_INITIALIZATION = Pattern.compile("^// *PROPERTY_LAZY_INITIALIZATION *$", Pattern.MULTILINE)
|
||||
|
||||
private val SAFE_EXTERNAL_BOOLEAN = Pattern.compile("^// *SAFE_EXTERNAL_BOOLEAN *$", Pattern.MULTILINE)
|
||||
|
||||
@JvmStatic
|
||||
protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn")
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ abstract class BasicIrBoxTest(
|
||||
skipDceDriven: Boolean,
|
||||
splitPerModule: Boolean,
|
||||
propertyLazyInitialization: Boolean,
|
||||
safeExternalBoolean: Boolean,
|
||||
) {
|
||||
val filesToCompile = units.map { (it as TranslationUnit.SourceFile).file }
|
||||
|
||||
@@ -150,7 +151,8 @@ abstract class BasicIrBoxTest(
|
||||
es6mode = runEs6Mode,
|
||||
multiModule = splitPerModule || perModule,
|
||||
propertyLazyInitialization = propertyLazyInitialization,
|
||||
lowerPerModule = lowerPerModule
|
||||
lowerPerModule = lowerPerModule,
|
||||
safeExternalBoolean = safeExternalBoolean,
|
||||
)
|
||||
|
||||
compiledModule.jsCode!!.writeTo(outputFile, config)
|
||||
@@ -179,7 +181,8 @@ abstract class BasicIrBoxTest(
|
||||
dceDriven = true,
|
||||
es6mode = runEs6Mode,
|
||||
multiModule = splitPerModule || perModule,
|
||||
propertyLazyInitialization = propertyLazyInitialization
|
||||
propertyLazyInitialization = propertyLazyInitialization,
|
||||
safeExternalBoolean = safeExternalBoolean,
|
||||
).jsCode!!.writeTo(pirOutputFile, config)
|
||||
}
|
||||
} else {
|
||||
|
||||
Generated
+5
@@ -6822,6 +6822,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
|
||||
}
|
||||
|
||||
@TestMetadata("booleanInExternals.kt")
|
||||
public void testBooleanInExternals() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/booleanInExternals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classUsesPackageProperties.kt")
|
||||
public void testClassUsesPackageProperties() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/classUsesPackageProperties.kt");
|
||||
|
||||
+5
@@ -6822,6 +6822,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("booleanInExternals.kt")
|
||||
public void testBooleanInExternals() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/booleanInExternals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classUsesPackageProperties.kt")
|
||||
public void testClassUsesPackageProperties() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/classUsesPackageProperties.kt");
|
||||
|
||||
+5
@@ -6842,6 +6842,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("booleanInExternals.kt")
|
||||
public void testBooleanInExternals() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/booleanInExternals.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("classUsesPackageProperties.kt")
|
||||
public void testClassUsesPackageProperties() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/classUsesPackageProperties.kt");
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// SAFE_EXTERNAL_BOOLEAN
|
||||
|
||||
fun box(): String {
|
||||
val interfaceWithBoolean: InterfaceWithBoolean = js("{}")
|
||||
C().c = interfaceWithBoolean.foo
|
||||
C().c = interfaceWithBoolean.bar
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
abstract class A<T> {
|
||||
open fun get(): T {
|
||||
return this.asDynamic()["attr"].unsafeCast<T>()
|
||||
}
|
||||
|
||||
open fun set(value: T) {
|
||||
this.asDynamic()["attr"] = value
|
||||
}
|
||||
}
|
||||
|
||||
class B : A<Boolean>() {
|
||||
override fun set(value: Boolean) {
|
||||
if (value) {
|
||||
this.asDynamic()["attr"] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val b: A<Boolean> = B()
|
||||
|
||||
class C {
|
||||
var c: Boolean
|
||||
get() = b.get()
|
||||
set(newValue) {
|
||||
b.set(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
external interface InterfaceWithBoolean {
|
||||
var foo: Boolean
|
||||
@JsName("goo")
|
||||
var bar: Boolean
|
||||
}
|
||||
Reference in New Issue
Block a user