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) @Target(CLASS, FUNCTION, PROPERTY)
internal annotation class library(public val name: String = "") 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) @Target(PROPERTY)
public annotation class enumerable() public annotation class enumerable()
+16 -37
View File
@@ -1,47 +1,26 @@
// FILE: enumerable.kt
package foo package foo
external fun <T> _enumerate(o: T): T = noImpl class P {
val simpleProp: Int = 100
external fun <T> _findFirst(o: Any): T = noImpl val anotherProp: Int = 100
val propWithGetter: Int
class Test() { get() = 1
val a: Int = 100 fun func() = "2"
val b: String = "s"
}
class P() {
@enumerable
val a: Int = 100
val b: String = "s"
} }
fun box(): String { fun box(): String {
val test = _enumerate(Test()) val expectedKeys = setOf("simpleProp", "anotherProp")
val p = _enumerate(P()) assertEquals(expectedKeys, P().keys())
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 result = _findFirst<Int>(object { assertEquals(expectedKeys, object {
val test = 100 val simpleProp: Int = 100
}) val anotherProp: Int = 100
if (result != 100) return "fail4: $result" val propWithGetter: Int
get() = 1
fun func() = "2"
}.keys())
return "OK" return "OK"
} }
// FILE: enumerate.js fun Any.keys(): Set<String> = (js("Object").keys(this) as Array<String>).toSet()
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];
}
}