Package-level declarations

Types

Link copied to clipboard
class AsmReport

What the engine did with one function whose body starts with "use asm".

Link copied to clipboard
class BindScope<T : Any>

What bind gives you: a place to name the members a script should see.

Link copied to clipboard

How loud a console message is.

Link copied to clipboard
data class ConsoleMessage(val level: ConsoleLevel, val text: String)

One console message, already formatted.

Link copied to clipboard

Where console.log and its neighbours end up.

Link copied to clipboard

Printers you probably want.

Link copied to clipboard
object Converters

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

Link copied to clipboard

A JavaScript array seen from Kotlin.

Link copied to clipboard

The engine itself could not go on: it is closed, misused, or out of budget.

Link copied to clipboard

A script threw. value is whatever it threw, which is usually an Error but need not be.

Link copied to clipboard

Anything the facade throws. Every case is one of the three below.

Link copied to clipboard

A JavaScript function seen from Kotlin.

Link copied to clipboard
open class JsObject

A JavaScript object seen from Kotlin. Reading and writing goes straight through to the engine, so a change here is a change the script sees.

Link copied to clipboard

A promise the host controls: hand promise to the script, settle it when you are ready.

Link copied to clipboard
class JsScript

A parsed script, ready to run more than once.

Link copied to clipboard
data class JsStackFrame(val functionName: String?, val fileName: String?, val lineNumber: Int)

One frame of a script's own call stack.

Link copied to clipboard

The source did not parse.

Link copied to clipboard
enum JsType : Enum<JsType>

What a JsValue holds. A when over this covers every JavaScript value, so the compiler can tell you when you have missed one.

Link copied to clipboard
value class JsValue

One value from the engine. It costs nothing at runtime: the wrapper disappears and only the value itself is passed around.

Link copied to clipboard

An engine and the global scope that goes with it. One instance belongs to one thread.

Link copied to clipboard

How to build an engine. Everything has a working default.

Link copied to clipboard

Which JavaScript the engine speaks.

Link copied to clipboard
class PropertyFlags(val writable: Boolean = true, val enumerable: Boolean = true, val configurable: Boolean = true)

How a property behaves. The defaults match what obj.x = 1 gives you in a script.

Properties

Link copied to clipboard

True when this value is thenable, which is what await looks for.

Functions

Link copied to clipboard
fun JsObject.accessor(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?, write: (JsValue) -> Unit)

A property with both halves.

Link copied to clipboard
fun <T : Any> JsObject.bind(name: String, instance: T, build: BindScope<T>.() -> Unit): JsObject

Binds a Kotlin object into a fresh JavaScript object.

Link copied to clipboard
fun JsObject.constant(name: String, value: Any?)

Puts a value that a script can read but not change.

Link copied to clipboard
fun JsObject.constructor(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), build: (JsObject, List<JsValue>) -> Unit): JsFunction

A host constructor, callable with new. build fills in the object it is given.

Link copied to clipboard
inline fun <T> JsValue.convertTo(): T

Reads a JsValue as T, coercing the way JavaScript would where that makes sense.

Link copied to clipboard
inline fun <A, R> JsObject.function(name: String, crossinline body: (A) -> R): JsFunction

A one-argument host function, with the argument and the answer converted for you.

inline fun <A, B, R> JsObject.function(name: String, crossinline body: (A, B) -> R): JsFunction

A two-argument host function.

inline fun <A, B, C, R> JsObject.function(name: String, crossinline body: (A, B, C) -> R): JsFunction

A three-argument host function.

fun JsObject.function(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (List<JsValue>) -> Any?): JsFunction

A host function that takes the arguments as they came.

Link copied to clipboard
fun JsObject.getter(name: String, flags: PropertyFlags = PropertyFlags(), read: () -> Any?)

A property computed on every read.

Link copied to clipboard
fun KiteJs(configure: KiteJsConfig.() -> Unit = {}): KiteJs

Builds an engine. See KiteJsConfig for what you can set.

Link copied to clipboard
fun JsObject.method(name: String, arity: Int = 0, flags: PropertyFlags = PropertyFlags(enumerable = false), body: (self: JsValue, args: List<JsValue>) -> Any?): JsFunction

A host function that also wants the this it was called on.

Link copied to clipboard

A promise the host settles later.

Link copied to clipboard
fun JsObject.obj(name: String, build: JsObject.() -> Unit = {}): JsObject

A nested object, built by build. Returns it so you can keep a handle.

Link copied to clipboard
fun KiteJs.onSettled(value: JsValue, onSettled: (JsValue, JsValue?) -> Unit): Boolean

Registers onSettled on a promise. It is called with the value and a null error on success, or with undefined and the reason on failure. Returns false if the value was not thenable at all.

Link copied to clipboard
fun JsObject.property(name: String, value: Any?, flags: PropertyFlags = PropertyFlags())

Puts a value on the object.

Link copied to clipboard
fun JsObject.setter(name: String, flags: PropertyFlags = PropertyFlags(), write: (JsValue) -> Unit)

A property that only accepts writes.