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. The Java engine needs a global scope: resetForReuse always keeps one, while resetContext(true) removes it, after which evalScript fails.
Variable declarations use fully-qualified type names, so they need no imports. A value whose runtime class cannot be named, such as the private list class behind listOf(1, 2), is declared as its nearest public class or interface. A use-site out T or in T type argument is declared as ? extends T or ? super T.
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.
The engine is a java-scriptengine JavaScriptEngine that closes the compiler's file manager after every compilation, which java-scriptengine itself does not do: each evaluation would otherwise keep one file descriptor per classpath jar open until garbage collection. close does nothing, because the engine holds no resources between evaluations.
See also
Properties
Functions
Sets the isolation level for the underlying JavaScriptEngine.
Evaluates a raw Java script string, prepending any registered import declarations.
Resets the context and also clears the imports and restores the default isolation, so the next borrower from a pool starts clean.