Class RhinoScriptEngine

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

    public class RhinoScriptEngine
    extends javax.script.AbstractScriptEngine
    implements javax.script.Compilable, javax.script.Invocable
    This is the implementation of the standard ScriptEngine interface for Rhino.

    An instance of the Rhino ScriptEngine is fully self-contained. Bindings at the GLOBAL_SCOPE may be set, but there is nothing special about them -- if both global and ENGINE_SCOPE bindings are set then the "engine" bindings override the global ones.

    The Rhino engine is not thread safe. Rhino does no synchronization of ScriptEngine instances and no synchronization of Bindings instances. It is up to the caller to ensure that the ScriptEngine and all its Bindings are used by a single thread at a time.

    The Rhino script engine includes some top-level built-in functions. See the Builtins class for more documentation.

    The engine supports a few configuration parameters that may be set at the "engine scope". Both are numbers that may be set to a String or Number object.

    • javax.script.language_version: The version of the JavaScript language supported, which is an integer defined in the Context class. The default is the latest "ES6" version, defined as 200.
    • org.htmlunit.corejs.javascript.optimization_level: The level of optimization Rhino performs on the generated bytecode. Default is 9, which is the most. Set to -1 to use interpreted mode.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.script.CompiledScript compile​(java.io.Reader script)  
      javax.script.CompiledScript compile​(java.lang.String script)  
      private void configureContext​(Context cx)  
      javax.script.Bindings createBindings()  
      java.lang.Object eval​(java.io.Reader reader, javax.script.ScriptContext context)  
      java.lang.Object eval​(java.lang.String script, javax.script.ScriptContext context)  
      (package private) java.lang.Object eval​(Script script, javax.script.ScriptContext sc)  
      javax.script.ScriptEngineFactory getFactory()  
      private java.lang.String getFilename()  
      <T> T getInterface​(java.lang.Class<T> clasz)  
      <T> T getInterface​(java.lang.Object thiz, java.lang.Class<T> clasz)  
      private Scriptable initScope​(Context cx, javax.script.ScriptContext sc)  
      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)  
      (package private) java.lang.Object invokeMethodRaw​(java.lang.Object thiz, java.lang.String name, java.lang.Class<?> returnType, java.lang.Object... args)  
      private static boolean methodsMissing​(Scriptable scope, java.lang.Class<?> clasz)  
      private static int parseInteger​(java.lang.Object v)  
      • 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

      • OPTIMIZATION_LEVEL

        public static final java.lang.String OPTIMIZATION_LEVEL
        Reserved key for the Rhino optimization level. Default is "9," for optimized and compiled code. Set this to "-1" to run Rhino in interpreted mode -- this is much much slower but the only option on platforms like Android that don't support class files.
        See Also:
        Constant Field Values
      • DEFAULT_FILENAME

        private static final java.lang.String DEFAULT_FILENAME
        See Also:
        Constant Field Values
      • builtins

        private final Builtins builtins
    • Method Detail

      • initScope

        private Scriptable initScope​(Context cx,
                                     javax.script.ScriptContext sc)
                              throws javax.script.ScriptException
        Throws:
        javax.script.ScriptException
      • eval

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

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

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

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

        java.lang.Object eval​(Script script,
                              javax.script.ScriptContext sc)
                       throws javax.script.ScriptException
        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
      • invokeMethodRaw

        java.lang.Object invokeMethodRaw​(java.lang.Object thiz,
                                         java.lang.String name,
                                         java.lang.Class<?> returnType,
                                         java.lang.Object... args)
                                  throws javax.script.ScriptException,
                                         java.lang.NoSuchMethodException
        Throws:
        javax.script.ScriptException
        java.lang.NoSuchMethodException
      • getInterface

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

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

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

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

        private void configureContext​(Context cx)
                               throws javax.script.ScriptException
        Throws:
        javax.script.ScriptException
      • parseInteger

        private static int parseInteger​(java.lang.Object v)
                                 throws javax.script.ScriptException
        Throws:
        javax.script.ScriptException
      • getFilename

        private java.lang.String getFilename()
      • methodsMissing

        private static boolean methodsMissing​(Scriptable scope,
                                              java.lang.Class<?> clasz)