JsContext

Stateful JS execution context. Keeps variables alive between eval calls, mimicking the Rhino "scope" object that extensions used to hold on to.

Instances are created via newJsContext, not by calling this constructor directly.

Parameters

maxExecutionTime

wall-clock budget given to each eval call. Can still be changed after construction (e.g. from within newJsContext's initializer block) as long as it's set before the first eval/get/set call, since the underlying interpreter is built lazily from whatever values these hold at that point. Changes made afterward have no effect.

maxInstructions

hard cap on statements/expressions executed per eval call, independent of wall-clock time. Same lazy-initialization caveat as maxExecutionTime applies.

scope

the CoroutineScope this context's cancellation is tied to. Supplied automatically by newJsContext from the caller's own coroutine context.

Properties

Link copied to clipboard
var maxExecutionTime: ERROR CLASS: Symbol not found for Duration
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun eval(code: String): Any?

Evaluate code in this context. Returns the last expression value.

Link copied to clipboard
operator fun get(name: String): Any?

Retrieve a variable set by previously evaluated code, or via set. Returns null if never set.

Link copied to clipboard
operator fun set(name: String, value: Any?)

Expose a Kotlin value to subsequently evaluated JS code under the name name.