Fix failing tests

This commit is contained in:
Iaroslav Postovalov 2020-12-20 18:34:35 +07:00
parent a655404486
commit 484b35cb4f
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7

View File

@ -56,18 +56,25 @@ internal class JSBuilder<T>(val bodyCallback: JSBuilder<T>.() -> BaseExpression)
} }
} }
fun variable(name: String): BaseExpression { fun variable(name: String): BaseExpression = call(getOrFail, Identifier("arguments"), SimpleLiteral(name))
return MemberExpression(
computed = true,
optional = false,
`object` = Identifier("arguments"),
property = SimpleLiteral(name),
)
}
fun call(function: Function<T>, vararg args: BaseExpression): BaseExpression = SimpleCallExpression( fun call(function: Function<T>, vararg args: BaseExpression): BaseExpression = SimpleCallExpression(
optional = false, optional = false,
callee = constant(function), callee = constant(function),
*args, *args,
) )
private companion object {
@Suppress("UNUSED_VARIABLE")
val getOrFail: (`object`: dynamic, key: String) -> dynamic = { `object`, key ->
val k = key
val o = `object`
if (!(js("k in o") as Boolean)) {
throw NoSuchElementException()
}
js("o[k]")
}
}
} }