Class RhinoScriptEngine
- All Implemented Interfaces:
Compilable
,Invocable
,ScriptEngine
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Builtins
private static final RhinoScriptEngine.CtxFactory
private static final boolean
private static final String
(package private) static final int
private static final int
private final RhinoScriptEngineFactory
static final String
Reserved key for the Rhino optimization level.private ScriptableObject
Fields inherited from class javax.script.AbstractScriptEngine
context
Fields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
eval
(Reader reader, ScriptContext context) eval
(String script, ScriptContext context) (package private) Object
eval
(Script script, ScriptContext sc) private String
<T> T
getInterface
(Class<T> clasz) <T> T
getInterface
(Object thiz, Class<T> clasz) private Scriptable
initScope
(Context cx, ScriptContext sc) invokeFunction
(String name, Object... args) invokeMethod
(Object thiz, String name, Object... args) (package private) Object
invokeMethodRaw
(Object thiz, String name, Class<?> returnType, Object... args) private static boolean
methodsMissing
(Scriptable scope, Class<?> clasz) private static int
Methods inherited from class javax.script.AbstractScriptEngine
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContext
-
Field Details
-
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:
-
DEFAULT_LANGUAGE_VERSION
static final int DEFAULT_LANGUAGE_VERSION- See Also:
-
DEFAULT_OPT
private static final int DEFAULT_OPT- See Also:
-
DEFAULT_DEBUG
private static final boolean DEFAULT_DEBUG- See Also:
-
DEFAULT_FILENAME
- See Also:
-
ctxFactory
-
factory
-
builtins
-
topLevelScope
-
-
Constructor Details
-
RhinoScriptEngine
RhinoScriptEngine(RhinoScriptEngineFactory factory)
-
-
Method Details
-
initScope
- Throws:
ScriptException
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
eval
- Specified by:
eval
in interfaceScriptEngine
- Throws:
ScriptException
-
compile
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
compile
- Specified by:
compile
in interfaceCompilable
- Throws:
ScriptException
-
eval
- 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
-
invokeMethodRaw
Object invokeMethodRaw(Object thiz, String name, Class<?> returnType, Object... args) throws ScriptException, NoSuchMethodException - Throws:
ScriptException
NoSuchMethodException
-
getInterface
- Specified by:
getInterface
in interfaceInvocable
-
getInterface
- Specified by:
getInterface
in interfaceInvocable
-
createBindings
- Specified by:
createBindings
in interfaceScriptEngine
-
getFactory
- Specified by:
getFactory
in interfaceScriptEngine
-
configureContext
- Throws:
ScriptException
-
parseInteger
- Throws:
ScriptException
-
getFilename
-
methodsMissing
-