KJS: deprecate enumerable annotation since it's no longer has any effect and rewrite test which checks enumerability of members

This commit is contained in:
Zalim Bashorov
2016-12-02 17:37:19 +03:00
parent d0d583e8ee
commit 8ccc00f3d4
2 changed files with 17 additions and 37 deletions
+1
View File
@@ -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()
+16 -37
View File
@@ -1,47 +1,26 @@
// FILE: enumerable.kt
package foo
external fun <T> _enumerate(o: T): T = noImpl
external fun <T> _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<Int>(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];
}
}
fun Any.keys(): Set<String> = (js("Object").keys(this) as Array<String>).toSet()