Class NashornScriptEngine

  • All Implemented Interfaces:
    javax.script.Compilable, javax.script.Invocable, javax.script.ScriptEngine

    public final class NashornScriptEngine
    extends javax.script.AbstractScriptEngine
    implements javax.script.Compilable, javax.script.Invocable
    JSR-223 compliant script engine for Nashorn. Instances are not created directly, but rather returned through NashornScriptEngineFactory.getScriptEngine(). Note that this engine implements the Compilable and Invocable 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 java.lang.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
      javax.script.CompiledScript compile​(java.io.Reader reader)  
      javax.script.CompiledScript compile​(java.lang.String str)  
      javax.script.Bindings createBindings()  
      java.lang.Object eval​(java.io.Reader reader, javax.script.ScriptContext ctxt)  
      java.lang.Object eval​(java.lang.String script, javax.script.ScriptContext ctxt)  
      javax.script.ScriptEngineFactory getFactory()  
      <T> T getInterface​(java.lang.Class<T> clazz)  
      <T> T getInterface​(java.lang.Object thiz, java.lang.Class<T> clazz)  
      java.lang.Object invokeFunction​(java.lang.String name, java.lang.Object... args)  
      java.lang.Object invokeMethod​(java.lang.Object thiz, java.lang.String name, java.lang.Object... args)  
      • Methods inherited from class javax.script.AbstractScriptEngine

        eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NASHORN_GLOBAL

        public static final java.lang.String NASHORN_GLOBAL
        Key used to associate Nashorn global object mirror with arbitrary Bindings instance.
        See Also:
        Constant Field Values
    • Method Detail

      • eval

        public java.lang.Object eval​(java.io.Reader reader,
                                     javax.script.ScriptContext ctxt)
                              throws javax.script.ScriptException
        Specified by:
        eval in interface javax.script.ScriptEngine
        Throws:
        javax.script.ScriptException
      • eval

        public java.lang.Object eval​(java.lang.String script,
                                     javax.script.ScriptContext ctxt)
                              throws javax.script.ScriptException
        Specified by:
        eval in interface javax.script.ScriptEngine
        Throws:
        javax.script.ScriptException
      • getFactory

        public javax.script.ScriptEngineFactory getFactory()
        Specified by:
        getFactory in interface javax.script.ScriptEngine
      • createBindings

        public javax.script.Bindings createBindings()
        Specified by:
        createBindings in interface javax.script.ScriptEngine
      • compile

        public javax.script.CompiledScript compile​(java.io.Reader reader)
                                            throws javax.script.ScriptException
        Specified by:
        compile in interface javax.script.Compilable
        Throws:
        javax.script.ScriptException
      • compile

        public javax.script.CompiledScript compile​(java.lang.String str)
                                            throws javax.script.ScriptException
        Specified by:
        compile in interface javax.script.Compilable
        Throws:
        javax.script.ScriptException
      • invokeFunction

        public java.lang.Object invokeFunction​(java.lang.String name,
                                               java.lang.Object... args)
                                        throws javax.script.ScriptException,
                                               java.lang.NoSuchMethodException
        Specified by:
        invokeFunction in interface javax.script.Invocable
        Throws:
        javax.script.ScriptException
        java.lang.NoSuchMethodException
      • invokeMethod

        public java.lang.Object invokeMethod​(java.lang.Object thiz,
                                             java.lang.String name,
                                             java.lang.Object... args)
                                      throws javax.script.ScriptException,
                                             java.lang.NoSuchMethodException
        Specified by:
        invokeMethod in interface javax.script.Invocable
        Throws:
        javax.script.ScriptException
        java.lang.NoSuchMethodException
      • getInterface

        public <T> T getInterface​(java.lang.Class<T> clazz)
        Specified by:
        getInterface in interface javax.script.Invocable
      • getInterface

        public <T> T getInterface​(java.lang.Object thiz,
                                  java.lang.Class<T> clazz)
        Specified by:
        getInterface in interface javax.script.Invocable