Class RhinoScriptEngine
- java.lang.Object
-
- javax.script.AbstractScriptEngine
-
- org.mozilla.javascript.engine.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.InvocableThis 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.mozilla.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.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringOPTIMIZATION_LEVELReserved key for the Rhino optimization level.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.script.CompiledScriptcompile(java.io.Reader script)javax.script.CompiledScriptcompile(java.lang.String script)javax.script.BindingscreateBindings()java.lang.Objecteval(java.io.Reader reader, javax.script.ScriptContext context)java.lang.Objecteval(java.lang.String script, javax.script.ScriptContext context)javax.script.ScriptEngineFactorygetFactory()<T> TgetInterface(java.lang.Class<T> clasz)<T> TgetInterface(java.lang.Object thiz, java.lang.Class<T> clasz)java.lang.ObjectinvokeFunction(java.lang.String name, java.lang.Object... args)java.lang.ObjectinvokeMethod(java.lang.Object thiz, java.lang.String name, java.lang.Object... args)
-
-
-
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
-
-
Method Detail
-
eval
public java.lang.Object eval(java.lang.String script, javax.script.ScriptContext context) throws javax.script.ScriptException- Specified by:
evalin interfacejavax.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:
evalin interfacejavax.script.ScriptEngine- Throws:
javax.script.ScriptException
-
compile
public javax.script.CompiledScript compile(java.lang.String script) throws javax.script.ScriptException- Specified by:
compilein interfacejavax.script.Compilable- Throws:
javax.script.ScriptException
-
compile
public javax.script.CompiledScript compile(java.io.Reader script) throws javax.script.ScriptException- Specified by:
compilein interfacejavax.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:
invokeFunctionin interfacejavax.script.Invocable- Throws:
javax.script.ScriptExceptionjava.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:
invokeMethodin interfacejavax.script.Invocable- Throws:
javax.script.ScriptExceptionjava.lang.NoSuchMethodException
-
getInterface
public <T> T getInterface(java.lang.Class<T> clasz)
- Specified by:
getInterfacein interfacejavax.script.Invocable
-
getInterface
public <T> T getInterface(java.lang.Object thiz, java.lang.Class<T> clasz)- Specified by:
getInterfacein interfacejavax.script.Invocable
-
createBindings
public javax.script.Bindings createBindings()
- Specified by:
createBindingsin interfacejavax.script.ScriptEngine
-
getFactory
public javax.script.ScriptEngineFactory getFactory()
- Specified by:
getFactoryin interfacejavax.script.ScriptEngine
-
-