Class JavaScriptScriptHelper

java.lang.Object
com.axelor.script.AbstractScriptHelper
com.axelor.script.JavaScriptScriptHelper
All Implemented Interfaces:
ScriptHelper, AutoCloseable

public class JavaScriptScriptHelper extends AbstractScriptHelper implements AutoCloseable
  • Field Details

    • EVAL_NAME

      public static final String EVAL_NAME
      The name a plain eval's source is reported under, in stack traces and script errors.
      See Also:
  • Constructor Details

    • JavaScriptScriptHelper

      public JavaScriptScriptHelper(Bindings bindings)
    • JavaScriptScriptHelper

      public JavaScriptScriptHelper(Context context)
  • Method Details

    • jsSource

      public static org.graalvm.polyglot.Source jsSource(String name, String code)
      A named, globally-cached JS Source. Naming (e.g. workflow:<id>:script:<node>) improves stack traces and diagnostics. It shares the one source cache with plain evals, sized and expired by application.script.cache.size and expire-time: while cached, the same Source is reused, so GraalVM reuses its parsed and compiled code across contexts on the shared engine.
    • withTimeout

      public JavaScriptScriptHelper withTimeout(long timeout)
    • eval

      public Object eval(String expr, Bindings bindings) throws ScriptException
      Description copied from interface: ScriptHelper
      Evaluate the given expression with the given bindings.
      Specified by:
      eval in interface ScriptHelper
      Parameters:
      expr - the expression to evaluate
      bindings - the context bindings
      Returns:
      expression result
      Throws:
      ScriptException
    • execute

      public Object execute(org.graalvm.polyglot.Source function, Object scope)
      Execute a compiled JS function Source — (function(scope){ ... }) — against an explicit scope object, returning a durable host value. The function is compiled once per this helper's context and reused; execution is wall-clock timeout-guarded like eval(java.lang.String, javax.script.Bindings).
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable