Converters

object Converters

The fixed table between Kotlin values and engine values. Nothing here uses reflection, so it works the same on every target.

Kotlin to JavaScript: null and Unit become undefined, Boolean stays, every number widens to Double, a Long outside the range JavaScript can hold exactly becomes a BigInt, any CharSequence becomes a String, and List, Array, Map and Set become the matching JavaScript objects. Anything already from the engine passes straight through.

Functions

Link copied to clipboard
fun register(convert: (Any) -> Any?)

Teaches the table one more Kotlin type. convert answers the engine value, or null to let the next rule try. Registering the same type twice keeps both; the first match wins.

Link copied to clipboard
fun toEngine(value: Any?): Any?

For a value that needs no scope: scalars only. Collections need toEngine with a context.

fun toEngine(value: Any?, cx: Context, scope: Scriptable): Any?

The full table, including the collections, which need a scope to build their objects in.