Class GraalVmJavaScriptExecutionEngine
java.lang.Object
dev.langchain4j.code.graalvm.GraalVmJavaScriptExecutionEngine
- All Implemented Interfaces:
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 + 2evaluates to a value without printing anything, so"42"is returnedconsole.log('hello')only prints, so"Output:\nhello"is returnedconsole.log('hello'); 42does both, so"Output:\nhello\nResult:\n42"is returnedvar x = 1;neither prints nor evaluates to a value, so an empty string is returned
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 Summary
Constructors -
Method Summary
-
Constructor Details
-
GraalVmJavaScriptExecutionEngine
public GraalVmJavaScriptExecutionEngine()
-
-
Method Details
-
execute
Description copied from interface:CodeExecutionEngineExecute the given code.- Specified by:
executein interfaceCodeExecutionEngine- Parameters:
code- The code to execute.- Returns:
- The result of the execution.
-