Class Engine

java.lang.Object
io.karatelabs.js.Engine

public class Engine extends Object
  • Field Details

    • DEBUG

      public static boolean DEBUG
  • Constructor Details

    • Engine

      public Engine()
  • Method Details

    • setAsyncDrainTimeout

      public void setAsyncDrainTimeout(Duration timeout)
      How long Engine.eval may keep draining async work before it gives up, cancels the scope and throws EngineTimeoutException. Off by default — cooperative interrupt (and karate-ext's Sandbox.TimeBox) remain the outer bound.
    • setAsyncRejectionWarnOnly

      public void setAsyncRejectionWarnOnly(boolean warnOnly)
      Downgrade unhandled promise rejections from "fail the eval" (the default) to a warning on the console consumer and SLF4J. Covers the eval's own result too: a script whose completion value is a rejected promise returns the rejection reason instead of throwing.
    • isPoisoned

      public boolean isPoisoned()
      True once this engine has been poisoned — see poisoned.
    • eval

      public Object eval(Node program)
    • eval

      public Object eval(Resource resource)
    • eval

      public Object eval(File file)
    • eval

      public Object eval(String text)
    • parse

      public static Node parse(String text)
      Parses JS source text into an AST Node without evaluating it. Exposed for tools (linters, formatters, AST patchers) that need source positions and structure but not execution.
    • evalWith

      public Object evalWith(Node program, Map<String,Object> vars)
    • evalWith

      public Object evalWith(String text, Map<String,Object> vars)
    • evalWith

      public Object evalWith(Resource resource, Map<String,Object> vars)
    • get

      public Object get(String name)
    • put

      public void put(String name, Object value)
    • putRootBinding

      public void putRootBinding(String name, Object value)
    • remove

      public void remove(String name)
    • setOnConsoleLog

      public void setOnConsoleLog(Consumer<String> onConsoleLog)
    • getBindings

      public Map<String,Object> getBindings()
      Returns the user-visible bindings as an auto-unwrapping Map. Values retrieved via get() are automatically converted (JsDate → Date, undefined → null, etc.). Hidden entries (putRootBinding-injected, lazy built-ins) are filtered out.
    • getRawBindings

      public Map<String,Object> getRawBindings()
      Returns the raw user-visible bindings map without auto-unwrapping. Hidden entries are filtered out. Used for internal engine operations that need raw JS values.
    • getRootContext

      public Context getRootContext()
    • getRootBindings

      public Map<String,Object> getRootBindings()
      Returns the hidden ("root") bindings — the entries injected via putRootBinding(java.lang.String, java.lang.Object) plus the lazy built-in cache. Used by hosts (e.g. Karate's ScenarioRuntime) to inherit hidden state into a callee.
    • setListener

      public void setListener(ContextListener listener)
    • setExternalBridge

      public void setExternalBridge(ExternalBridge bridge)
    • setDebugSupport

      public <T> void setDebugSupport(RunInterceptor<T> interceptor, DebugPointFactory<T> factory)
    • getInterceptor

      public RunInterceptor<?> getInterceptor()
    • getPointFactory

      public DebugPointFactory<?> getPointFactory()
    • evalRaw

      protected Object evalRaw(String text)