From 79bec82430aaaa515d2d93d233e7473b4a967ea2 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Thu, 26 Mar 2020 19:07:36 +0300 Subject: [PATCH] KT-34770 JS. Configurable properties. Test --- .../ir/semantics/IrBoxJsTestGenerated.java | 9 ++++- .../js/test/semantics/BoxJsTestGenerated.java | 9 ++++- .../box/propertyAccess/configurable.kt | 40 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 js/js.translator/testData/box/propertyAccess/configurable.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java index 39df99d0a8a..08d602efcd9 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java @@ -6479,7 +6479,9 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { } public void testAllFilesPresentInPropertyAccess() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + KotlinTestUtils + .assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), + Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } @TestMetadata("classUsesPackageProperties.kt") @@ -6487,6 +6489,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/propertyAccess/classUsesPackageProperties.kt"); } + @TestMetadata("configurable.kt") + public void testConfigurable() throws Exception { + runTest("js/js.translator/testData/box/propertyAccess/configurable.kt"); + } + @TestMetadata("customGetter.kt") public void testCustomGetter() throws Exception { runTest("js/js.translator/testData/box/propertyAccess/customGetter.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index ff91e50bff9..c66df2d1f80 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -6504,7 +6504,9 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { } public void testAllFilesPresentInPropertyAccess() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true); + KotlinTestUtils + .assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), + Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS, true); } @TestMetadata("classUsesPackageProperties.kt") @@ -6512,6 +6514,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/propertyAccess/classUsesPackageProperties.kt"); } + @TestMetadata("configurable.kt") + public void testConfigurable() throws Exception { + runTest("js/js.translator/testData/box/propertyAccess/configurable.kt"); + } + @TestMetadata("customGetter.kt") public void testCustomGetter() throws Exception { runTest("js/js.translator/testData/box/propertyAccess/customGetter.kt"); diff --git a/js/js.translator/testData/box/propertyAccess/configurable.kt b/js/js.translator/testData/box/propertyAccess/configurable.kt new file mode 100644 index 00000000000..1dc14f25aa4 --- /dev/null +++ b/js/js.translator/testData/box/propertyAccess/configurable.kt @@ -0,0 +1,40 @@ +// EXPECTED_REACHABLE_NODES: 1325 +// KJS_WITH_FULL_RUNTIME +package foo + +external interface EP { + val simpleProp: Int + val anotherProp: String + val propWithGetter: Boolean +} + +class P : EP { + override val simpleProp = 13 + override val anotherProp = "42" + override val propWithGetter: Boolean + get() = true +} + +fun usages() { + val p = P() + assertEquals(13, p.simpleProp) + assertEquals("42", p.anotherProp) + assertEquals(true, p.propWithGetter) +} + +fun box(): String { + usages() + + val prototype = P::class.js.asDynamic().prototype + + assertTrue(isConfigurable(prototype, "simpleProp")) + assertTrue(isConfigurable(prototype, "anotherProp")) + assertTrue(isConfigurable(prototype, "propWithGetter")) + + return "OK" +} + +fun isConfigurable(obj: Any, prop: String): Boolean = + js("Object") + .getOwnPropertyDescriptor(obj, prop) + .configurable