KiteJs

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

KiteJs { languageVersion = LanguageVersion.ES6 }.use { js ->
js.global.function("shout") { args -> args.first().asString().uppercase() }
println(js.evaluate("shout('hi')").asString()) // HI
}

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

One entry per "use asm" function the engine has parsed, in the order it met them.

Link copied to clipboard

The global object. Bind host functions and values onto it.

Link copied to clipboard

The engine's version string.

Functions

Link copied to clipboard
open override fun close()

Releases the engine. Using it afterwards throws.

Link copied to clipboard
fun compile(source: String, fileName: String = "<script>"): JsScript

Parses source once so it can be run many times.

Link copied to clipboard
fun evaluate(source: String, fileName: String = "<eval>"): JsValue

Parses and runs source. The answer is the last expression's value.

Link copied to clipboard
fun newArray(vararg elements: Any?): JsArray

A fresh array holding elements.

Link copied to clipboard

A fresh empty object, the same as {} in a script.

Link copied to clipboard

A promise the host settles later.

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

Runs whatever the promise callbacks have queued. Evaluating already drains the queue at the end of the call, so this is only for work queued from a host callback afterwards.

Link copied to clipboard
fun valueOf(value: Any?): JsValue

A Kotlin value as the engine sees it, collections and all.