JsEngine

A JavaScript engine a KiteJs can run on. Each engine module has one, an object you pass to KiteJs: Rhino from kitejs-rhino, QuickJs from kitejs-quickjs. C is the engine's own configuration, which has everything KiteJsConfig has plus what only that engine can do.

KiteJs(Rhino) { timeZone = TimeZone.UTC }.use { js -> js.evaluate("1 + 1") }
KiteJs(QuickJs) { memoryLimit = 64L shl 20 }.use { js -> js.evaluate("1 + 1") }

Properties

Link copied to clipboard
open val isLoaded: Boolean

True once load has finished, and from the start where the engine has nothing to load.

Link copied to clipboard
abstract val name: String

The engine's name, such as Rhino or QuickJS.

Link copied to clipboard

Whether a thread holds one open engine at a time. Where it does, a second engine opens only after the first closes, or on another thread; where it does not, one thread holds several engines, each with a global scope of its own.

Functions

Link copied to clipboard
open suspend fun load()

Gets the engine ready, where that takes work before the first KiteJs can open. QuickJS in a browser compiles its WebAssembly here, which a browser will not do synchronously on its main thread for a module that size. Everywhere else this returns at once. Calling it again once it is done costs nothing.

Link copied to clipboard
abstract fun newConfig(): C

A configuration holding this engine's defaults, for KiteJs to hand to the caller.

Link copied to clipboard
abstract fun open(config: C): KiteJs

Opens an engine on this thread with config.