evalJs

suspend fun evalJs(js: String, variable: String? = null, maxExecutionTime: ERROR CLASS: Symbol not found for Duration = JS_DEFAULT_MAX_EXECUTION_TIME, maxInstructions: Long = JS_DEFAULT_MAX_INSTRUCTIONS): Any?(source)

Evaluate js and return its last value, or the value of variable if specified. Convenience wrapper for one-shot evaluations, equivalent to the old rhino.evaluateString(scope, js, ...).

Cancellation is automatically tied to whichever coroutine calls this function. If that coroutine is cancelled (e.g. an enclosing withTimeout expires), this call throws CancellationException.

Return

The last expression value, or the named variable value if variable is specified. Returns Unit on evaluation failure, timeout, or when the result is JS undefined. JS null is represented as Kotlin null. Use jsValueToString to convert to a JS string.

Parameters

js

The JavaScript code to evaluate.

variable

Optional variable name to retrieve from the scope after evaluation.

maxExecutionTime

wall-clock budget before the script is forcibly aborted. Defaults to JS_DEFAULT_MAX_EXECUTION_TIME; pass a smaller value for time-sensitive call sites (e.g. inside a withTimeout, which cannot itself interrupt this call).

maxInstructions

hard cap on statements/expressions executed, independent of wall-clock time. Defaults to JS_DEFAULT_MAX_INSTRUCTIONS.