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 javax.script.AbstractScriptEngine
context
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the current context and makes it unusable.static GraalJSScriptEngine
create()
Creates a new GraalJSScriptEngine with default configuration.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 polyglotContext
instances.eval
(Reader reader, ScriptContext ctxt) eval
(String script, ScriptContext ctxt) <T> T
getInterface
(Class<T> clasz) <T> T
getInterface
(Object thiz, Class<T> clasz) org.graalvm.polyglot.Context
Returns the polyglot context associated with the default ScriptContext of the engine.org.graalvm.polyglot.Context
Returns the polyglot context associated with a ScriptContext.org.graalvm.polyglot.Engine
Returns the polyglot engine associated with this script engine.invokeFunction
(String name, Object... args) invokeMethod
(Object thiz, String name, Object... args) void
setBindings
(Bindings bindings, int scope) Methods inherited from class javax.script.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:
close
in 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:
createBindings
in interfaceScriptEngine
-
setBindings
- Specified by:
setBindings
in interfaceScriptEngine
- Overrides:
setBindings
in classAbstractScriptEngine
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
getFactory
- Specified by:
getFactory
in interfaceScriptEngine
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeMethod
in interfaceInvocable
- Throws:
ScriptException
NoSuchMethodException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeFunction
in interfaceInvocable
- Throws:
ScriptException
NoSuchMethodException
-
getInterface
- Specified by:
getInterface
in interfaceInvocable
-
getInterface
- Specified by:
getInterface
in interfaceInvocable
-
compile
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
compile
- Specified by:
compile
in 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 polyglotContext
instances. Polyglot context instances can be accessed fromScriptContext
instances usinggetPolyglotContext()
. Theout
,err
andin
stream configuration are not inherited from the provided polyglot context config. InsteadScriptContext
output and input streams are used.- Parameters:
engine
- the engine to be used for context configurations ornull
if a default engine should be used.newContextConfig
- a base configuration to create new context instances ornull
if the default configuration should be used to construct new context instances.
-