Class GraalVmJavaScriptExecutionEngine

java.lang.Object
dev.langchain4j.code.graalvm.GraalVmJavaScriptExecutionEngine
All Implemented Interfaces:
CodeExecutionEngine

public class GraalVmJavaScriptExecutionEngine extends Object implements CodeExecutionEngine
CodeExecutionEngine that uses GraalVM Polyglot/Truffle to execute provided JavaScript code.

The returned string contains both what the code printed to stdout/stderr and what it evaluated to:

  • 40 + 2 evaluates to a value without printing anything, so "42" is returned
  • console.log('hello') only prints, so "Output:\nhello" is returned
  • console.log('hello'); 42 does both, so "Output:\nhello\nResult:\n42" is returned
  • var x = 1; neither prints nor evaluates to a value, so an empty string is returned
When the code fails, a PolyglotException is thrown and anything printed before the failure is lost.

Attention! It might be dangerous to execute the code, see SandboxPolicy.CONSTRAINED and HostAccess.UNTRUSTED for more details.

  • Constructor Details

    • GraalVmJavaScriptExecutionEngine

      public GraalVmJavaScriptExecutionEngine()
  • Method Details