JavaScript

A script engine wrapper for dynamically compiling and evaluating Java source code.

Supports adding named variables with type parameters, import declarations, and configurable isolation levels. Note that Java cannot have a null global context.

Common literal JVM-termination calls (System.exit, Runtime.getRuntime().exit/halt) are rejected on a best-effort basis via ScriptGuards. This is a convenience against accidental termination, not a security sandbox (see ScriptGuards) — run untrusted scripts in an isolated process or JVM.

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Generates Java import statements for all registered import classes.

Link copied to clipboard

Generates Java-style public field declarations for all registered variables.

Functions

Link copied to clipboard
open fun add(name: String, value: Any, vararg types: KType)
Link copied to clipboard
fun assignIsolation(isolation: Isolation)

Sets the isolation level for the underlying JavaScriptEngine.

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun eval(expr: String, action: String = "", verbose: Boolean = false): Any?

Evaluates a Java expr (optionally preceded by an action statement block) inside a generated Main.getValue() method, prepending any registered imports and variable declarations.

Link copied to clipboard
fun evalScript(script: String, verbose: Boolean = false): Any?

Evaluates a raw Java script string, prepending any registered import declarations.

Link copied to clipboard
fun <T> import(clazz: Class<T>)

Registers a Java class to be imported in generated scripts.

Link copied to clipboard
open override fun params(name: String, types: Array<out KType>): String
Link copied to clipboard
fun resetContext(nullGlobalContext: Boolean)