From 8ccc00f3d46e7063205e8f38c154989d553263c3 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Fri, 2 Dec 2016 17:37:19 +0300 Subject: [PATCH] KJS: deprecate enumerable annotation since it's no longer has any effect and rewrite test which checks enumerability of members --- js/js.libraries/src/core/annotations.kt | 1 + .../testData/box/propertyAccess/enumerable.kt | 53 ++++++------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/js/js.libraries/src/core/annotations.kt b/js/js.libraries/src/core/annotations.kt index 969b2777d89..e33b631fe35 100644 --- a/js/js.libraries/src/core/annotations.kt +++ b/js/js.libraries/src/core/annotations.kt @@ -37,6 +37,7 @@ public annotation class nativeInvoke @Target(CLASS, FUNCTION, PROPERTY) internal annotation class library(public val name: String = "") +@Deprecated("It is no longer has any effect and will be dropped in a future version") @Target(PROPERTY) public annotation class enumerable() diff --git a/js/js.translator/testData/box/propertyAccess/enumerable.kt b/js/js.translator/testData/box/propertyAccess/enumerable.kt index 6b328c57981..a70e319fe9b 100644 --- a/js/js.translator/testData/box/propertyAccess/enumerable.kt +++ b/js/js.translator/testData/box/propertyAccess/enumerable.kt @@ -1,47 +1,26 @@ -// FILE: enumerable.kt package foo -external fun _enumerate(o: T): T = noImpl - -external fun _findFirst(o: Any): T = noImpl - -class Test() { - val a: Int = 100 - val b: String = "s" -} - -class P() { - @enumerable - val a: Int = 100 - val b: String = "s" +class P { + val simpleProp: Int = 100 + val anotherProp: Int = 100 + val propWithGetter: Int + get() = 1 + fun func() = "2" } fun box(): String { - val test = _enumerate(Test()) - val p = _enumerate(P()) - if (100 != test.a) return "fail1: ${test.a}" - if ("s" != test.b) return "fail2: ${test.b}" - if (p.a != 100) return "fail3: ${p.a}" + val expectedKeys = setOf("simpleProp", "anotherProp") + assertEquals(expectedKeys, P().keys()) - val result = _findFirst(object { - val test = 100 - }) - if (result != 100) return "fail4: $result" + assertEquals(expectedKeys, object { + val simpleProp: Int = 100 + val anotherProp: Int = 100 + val propWithGetter: Int + get() = 1 + fun func() = "2" + }.keys()) return "OK" } -// FILE: enumerate.js -function _enumerate(o) { - var r = {}; - for (var p in o) { - r[p] = o[p]; - } - return r; -} - -function _findFirst(o) { - for (var p in o) { - return o[p]; - } -} \ No newline at end of file +fun Any.keys(): Set = (js("Object").keys(this) as Array).toSet()