public class RhinoScriptEngine extends AbstractScriptEngine implements Compilable, Invocable
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.
| Modifier and Type | Field and Description |
|---|---|
static String |
OPTIMIZATION_LEVEL
Reserved key for the Rhino optimization level.
|
contextARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME| Modifier and Type | Method and Description |
|---|---|
CompiledScript |
compile(Reader script) |
CompiledScript |
compile(String script) |
Bindings |
createBindings() |
Object |
eval(Reader reader,
ScriptContext context) |
Object |
eval(String script,
ScriptContext context) |
ScriptEngineFactory |
getFactory() |
<T> T |
getInterface(Class<T> clasz) |
<T> T |
getInterface(Object thiz,
Class<T> clasz) |
Object |
invokeFunction(String name,
Object... args) |
Object |
invokeMethod(Object thiz,
String name,
Object... args) |
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContextpublic static final String OPTIMIZATION_LEVEL
public Object eval(String script, ScriptContext context) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic Object eval(Reader reader, ScriptContext context) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic CompiledScript compile(String script) throws ScriptException
compile in interface CompilableScriptExceptionpublic CompiledScript compile(Reader script) throws ScriptException
compile in interface CompilableScriptExceptionpublic Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException
invokeFunction in interface InvocableScriptExceptionNoSuchMethodExceptionpublic Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException
invokeMethod in interface InvocableScriptExceptionNoSuchMethodExceptionpublic <T> T getInterface(Class<T> clasz)
getInterface in interface Invocablepublic <T> T getInterface(Object thiz, Class<T> clasz)
getInterface in interface Invocablepublic Bindings createBindings()
createBindings in interface ScriptEnginepublic ScriptEngineFactory getFactory()
getFactory in interface ScriptEngineCopyright © 2023 HtmlUnit. All rights reserved.