- java.lang.Object
-
- javax.script.AbstractScriptEngine
-
- org.openjdk.nashorn.api.scripting.NashornScriptEngine
-
- All Implemented Interfaces:
Compilable
,Invocable
,ScriptEngine
public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable
JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned throughNashornScriptEngineFactory.getScriptEngine()
. Note that this engine implements theCompilable
andInvocable
interfaces, allowing for efficient precompilation and repeated execution of scripts.- Since:
- 1.8u40
- See Also:
NashornScriptEngineFactory
-
-
Field Summary
Fields Modifier and Type Field Description static String
NASHORN_GLOBAL
Key used to associate Nashorn global object mirror with arbitrary Bindings instance.-
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledScript
compile(Reader reader)
CompiledScript
compile(String str)
Bindings
createBindings()
Object
eval(Reader reader, ScriptContext ctxt)
Object
eval(String script, ScriptContext ctxt)
ScriptEngineFactory
getFactory()
<T> T
getInterface(Class<T> clazz)
<T> T
getInterface(Object thiz, Class<T> clazz)
Object
invokeFunction(String name, Object... args)
Object
invokeMethod(Object thiz, String name, Object... args)
-
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
-
-
-
-
Field Detail
-
NASHORN_GLOBAL
public static final String NASHORN_GLOBAL
Key used to associate Nashorn global object mirror with arbitrary Bindings instance.- See Also:
- Constant Field Values
-
-
Method Detail
-
eval
public Object eval(Reader reader, ScriptContext ctxt) throws ScriptException
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
eval
public Object eval(String script, ScriptContext ctxt) throws ScriptException
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
getFactory
public ScriptEngineFactory getFactory()
- Specified by:
getFactory
in interfaceScriptEngine
-
createBindings
public Bindings createBindings()
- Specified by:
createBindings
in interfaceScriptEngine
-
compile
public CompiledScript compile(Reader reader) throws ScriptException
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
compile
public CompiledScript compile(String str) throws ScriptException
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
- Specified by:
invokeFunction
in interfaceInvocable
- Throws:
ScriptException
NoSuchMethodException
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
- Specified by:
invokeMethod
in interfaceInvocable
- Throws:
ScriptException
NoSuchMethodException
-
getInterface
public <T> T getInterface(Class<T> clazz)
- Specified by:
getInterface
in interfaceInvocable
-
getInterface
public <T> T getInterface(Object thiz, Class<T> clazz)
- Specified by:
getInterface
in interfaceInvocable
-
-