Files
kotlin-fork/js/js.translator/testData/box/jsCode/objectExpression.kt
T
Roman Artemev efafb6585e [JS IR BE] Refactored js("...") function
- support object expression
 - do not wrap in function in statement-level position
 - support implicit return
 - code clean up
2019-07-11 18:00:28 +03:00

26 lines
825 B
Kotlin
Vendored

// EXPECTED_REACHABLE_NODES: 1282
import kotlin.js.*
private fun isOrdinaryObject(o: Any?): Boolean = jsTypeOf(o) == "object" && Object.getPrototypeOf(o).`constructor` === Any::class.js
external class Object {
companion object {
fun getPrototypeOf(x: Any?): dynamic
fun keys(x: Any): Array<String>
}
}
fun box(): String {
val a = js("{}")
if (!isOrdinaryObject(a)) return "fail: a is not an object"
if (Object.keys(a).size != 0) return "fail: a should not have any properties"
val b = js("{ foo: 23, bar: 42 }")
if (!isOrdinaryObject(b)) return "fail: b is not an object"
if (Object.keys(b).size != 2) return "fail: b should have two properties"
if (b.foo != 23) return "fail: b.foo == ${b.foo}"
if (b.bar != 42) return "fail: b.bar == ${b.bar}"
return "OK"
}