Class GraalJSScriptEngine
java.lang.Object
javax.script.AbstractScriptEngine
com.oracle.truffle.js.scriptengine.GraalJSScriptEngine
- All Implemented Interfaces:
AutoCloseable, Compilable, Invocable, ScriptEngine
public final class GraalJSScriptEngine
extends AbstractScriptEngine
implements Compilable, Invocable, AutoCloseable
A Graal.JS implementation of the script engine. It provides access to the polyglot context using
getPolyglotContext().-
Field Summary
Fields inherited from class AbstractScriptEngine
contextFields inherited from interface ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the current context and makes it unusable.static GraalJSScriptEnginecreate()Creates a new GraalJSScriptEngine with default configuration.static GraalJSScriptEnginecreate(org.graalvm.polyglot.Engine engine, org.graalvm.polyglot.Context.Builder newContextConfig) Creates a new GraalJS script engine from a polyglot Engine instance with a base configuration for new polyglotContextinstances.eval(Reader reader, ScriptContext ctxt) eval(String script, ScriptContext ctxt) <T> TgetInterface(Class<T> clasz) <T> TgetInterface(Object thiz, Class<T> clasz) org.graalvm.polyglot.ContextReturns the polyglot context associated with the default ScriptContext of the engine.org.graalvm.polyglot.ContextReturns the polyglot context associated with a ScriptContext.org.graalvm.polyglot.EngineReturns the polyglot engine associated with this script engine.invokeFunction(String name, Object... args) invokeMethod(Object thiz, String name, Object... args) voidsetBindings(Bindings bindings, int scope) Methods inherited from class AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setContext
-
Method Details
-
close
public void close()Closes the current context and makes it unusable. Operations performed after closing will throw anIllegalStateException.- Specified by:
closein interfaceAutoCloseable
-
getPolyglotEngine
public org.graalvm.polyglot.Engine getPolyglotEngine()Returns the polyglot engine associated with this script engine. -
getPolyglotContext
public org.graalvm.polyglot.Context getPolyglotContext()Returns the polyglot context associated with the default ScriptContext of the engine.- See Also:
-
getPolyglotContext
Returns the polyglot context associated with a ScriptContext. If the context is not yet initialized then it will be initialized using the default context builder specified increate(Engine, org.graalvm.polyglot.Context.Builder). -
createBindings
- Specified by:
createBindingsin interfaceScriptEngine
-
setBindings
- Specified by:
setBindingsin interfaceScriptEngine- Overrides:
setBindingsin classAbstractScriptEngine
-
eval
- Specified by:
evalin interfaceScriptEngine- Throws:
ScriptException
-
eval
- Specified by:
evalin interfaceScriptEngine- Throws:
ScriptException
-
getFactory
- Specified by:
getFactoryin interfaceScriptEngine
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeMethodin interfaceInvocable- Throws:
ScriptExceptionNoSuchMethodException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeFunctionin interfaceInvocable- Throws:
ScriptExceptionNoSuchMethodException
-
getInterface
- Specified by:
getInterfacein interfaceInvocable
-
getInterface
- Specified by:
getInterfacein interfaceInvocable
-
compile
- Specified by:
compilein interfaceCompilable- Throws:
ScriptException
-
compile
- Specified by:
compilein interfaceCompilable- Throws:
ScriptException
-
create
Creates a new GraalJSScriptEngine with default configuration.- See Also:
-
create
public static GraalJSScriptEngine create(org.graalvm.polyglot.Engine engine, org.graalvm.polyglot.Context.Builder newContextConfig) Creates a new GraalJS script engine from a polyglot Engine instance with a base configuration for new polyglotContextinstances. Polyglot context instances can be accessed fromScriptContextinstances usinggetPolyglotContext(). Theout,errandinstream configuration are not inherited from the provided polyglot context config. InsteadScriptContextoutput and input streams are used.- Parameters:
engine- the engine to be used for context configurations ornullif a default engine should be used.newContextConfig- a base configuration to create new context instances ornullif the default configuration should be used to construct new context instances.
-