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.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.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RhinoScriptEngine.CtxFactory
-
Field Summary
Fields Modifier and Type Field Description private Builtins
builtins
private static RhinoScriptEngine.CtxFactory
ctxFactory
private static boolean
DEFAULT_DEBUG
private static java.lang.String
DEFAULT_FILENAME
(package private) static int
DEFAULT_LANGUAGE_VERSION
private static int
DEFAULT_OPT
private RhinoScriptEngineFactory
factory
static java.lang.String
OPTIMIZATION_LEVEL
Reserved key for the Rhino optimization level.private ScriptableObject
topLevelScope
-
Constructor Summary
Constructors Constructor Description RhinoScriptEngine(RhinoScriptEngineFactory factory)
-
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)
-
-
-
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_LANGUAGE_VERSION
static final int DEFAULT_LANGUAGE_VERSION
- See Also:
- Constant Field Values
-
DEFAULT_OPT
private static final int DEFAULT_OPT
- See Also:
- Constant Field Values
-
DEFAULT_DEBUG
private static final boolean DEFAULT_DEBUG
- See Also:
- Constant Field Values
-
DEFAULT_FILENAME
private static final java.lang.String DEFAULT_FILENAME
- See Also:
- Constant Field Values
-
ctxFactory
private static final RhinoScriptEngine.CtxFactory ctxFactory
-
factory
private final RhinoScriptEngineFactory factory
-
builtins
private final Builtins builtins
-
topLevelScope
private ScriptableObject topLevelScope
-
-
Constructor Detail
-
RhinoScriptEngine
RhinoScriptEngine(RhinoScriptEngineFactory factory)
-
-
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 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:
eval
in interfacejavax.script.ScriptEngine
- Throws:
javax.script.ScriptException
-
compile
public javax.script.CompiledScript compile(java.lang.String script) throws javax.script.ScriptException
- Specified by:
compile
in interfacejavax.script.Compilable
- Throws:
javax.script.ScriptException
-
compile
public javax.script.CompiledScript compile(java.io.Reader script) throws javax.script.ScriptException
- Specified by:
compile
in interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.script.Invocable
-
getInterface
public <T> T getInterface(java.lang.Object thiz, java.lang.Class<T> clasz)
- Specified by:
getInterface
in interfacejavax.script.Invocable
-
createBindings
public javax.script.Bindings createBindings()
- Specified by:
createBindings
in interfacejavax.script.ScriptEngine
-
getFactory
public javax.script.ScriptEngineFactory getFactory()
- Specified by:
getFactory
in interfacejavax.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)
-
-