evalJs
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
The JavaScript code to evaluate.
Optional variable name to retrieve from the scope after evaluation.
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).
hard cap on statements/expressions executed, independent of wall-clock time. Defaults to JS_DEFAULT_MAX_INSTRUCTIONS.