JS: don't pollute object with $metadata$
#KT-8126 Fixed
This commit is contained in:
@@ -59,4 +59,8 @@ public final class ObjectTest extends SingleFileTranslationTest {
|
||||
public void testLambdaInObjectInsideObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testDontPolluteObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -175,9 +175,7 @@ var Kotlin = {};
|
||||
Kotlin.createObjectNow = function (bases, constructor, functions) {
|
||||
var noNameClass = Kotlin.createClassNow(bases, constructor, functions);
|
||||
var obj = new noNameClass();
|
||||
obj.$metadata$ = {
|
||||
type: Kotlin.TYPE.OBJECT
|
||||
};
|
||||
noNameClass.$metadata$.type = Kotlin.TYPE.OBJECT;
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package foo
|
||||
|
||||
object EmptyObject {}
|
||||
|
||||
object SomeObject {
|
||||
val foo = 1
|
||||
var bar = "t"
|
||||
fun baz() {}
|
||||
}
|
||||
|
||||
val emptyObjectExpr = object {}
|
||||
|
||||
val someObjectExpr = object {
|
||||
val foo = 1
|
||||
var bar = "t"
|
||||
fun baz() {}
|
||||
}
|
||||
|
||||
val o = js("Object")
|
||||
|
||||
fun keys(a: Any): List<String> {
|
||||
val arr: Array<String> = o.keys(a)
|
||||
return arr.toList()
|
||||
}
|
||||
|
||||
fun getOwnPropertyNames(a: Any): List<String> {
|
||||
val arr: Array<String> = o.getOwnPropertyNames(a)
|
||||
return arr.toList()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf(), getOwnPropertyNames(EmptyObject))
|
||||
assertEquals(listOf(), keys(EmptyObject))
|
||||
|
||||
assertEquals(listOf("foo", "bar"), getOwnPropertyNames(SomeObject))
|
||||
assertEquals(listOf("foo", "bar"), keys(SomeObject))
|
||||
|
||||
assertEquals(listOf(), getOwnPropertyNames(emptyObjectExpr))
|
||||
assertEquals(listOf(), keys(emptyObjectExpr))
|
||||
|
||||
assertEquals(listOf("foo", "bar"), getOwnPropertyNames(someObjectExpr))
|
||||
assertEquals(listOf("foo", "bar"), keys(someObjectExpr))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user