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 Builtinsprivate static final RhinoScriptEngine.CtxFactoryprivate static final booleanprivate static final String(package private) static final intprivate static final intprivate final RhinoScriptEngineFactorystatic final StringReserved key for the Rhino optimization level.private ScriptableObjectFields inherited from class javax.script.AbstractScriptEngine
contextFields inherited from interface javax.script.ScriptEngine
ARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voideval(Reader reader, ScriptContext context) eval(String script, ScriptContext context) (package private) Objecteval(Script script, ScriptContext sc) private String<T> TgetInterface(Class<T> clasz) <T> TgetInterface(Object thiz, Class<T> clasz) private ScriptableinitScope(Context cx, ScriptContext sc) invokeFunction(String name, Object... args) invokeMethod(Object thiz, String name, Object... args) (package private) ObjectinvokeMethodRaw(Object thiz, String name, Class<?> returnType, Object... args) private static booleanmethodsMissing(Scriptable scope, Class<?> clasz) private static intMethods 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:
evalin interfaceScriptEngine- Throws:
ScriptException
-
eval
- Specified by:
evalin interfaceScriptEngine- Throws:
ScriptException
-
compile
- Specified by:
compilein interfaceCompilable- Throws:
ScriptException
-
compile
- Specified by:
compilein interfaceCompilable- Throws:
ScriptException
-
eval
- Throws:
ScriptException
-
invokeFunction
public Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeFunctionin interfaceInvocable- Throws:
ScriptExceptionNoSuchMethodException
-
invokeMethod
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException - Specified by:
invokeMethodin interfaceInvocable- Throws:
ScriptExceptionNoSuchMethodException
-
invokeMethodRaw
Object invokeMethodRaw(Object thiz, String name, Class<?> returnType, Object... args) throws ScriptException, NoSuchMethodException - Throws:
ScriptExceptionNoSuchMethodException
-
getInterface
- Specified by:
getInterfacein interfaceInvocable
-
getInterface
- Specified by:
getInterfacein interfaceInvocable
-
createBindings
- Specified by:
createBindingsin interfaceScriptEngine
-
getFactory
- Specified by:
getFactoryin interfaceScriptEngine
-
configureContext
- Throws:
ScriptException
-
parseInteger
- Throws:
ScriptException
-
getFilename
-
methodsMissing
-