Class RhinoScriptEngine
- java.lang.Object
-
- javax.script.AbstractScriptEngine
-
- org.htmlunit.corejs.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.htmlunit.corejs.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 classRhinoScriptEngine.CtxFactory
-
Field Summary
Fields Modifier and Type Field Description private Builtinsbuiltinsprivate static RhinoScriptEngine.CtxFactoryctxFactoryprivate static booleanDEFAULT_DEBUGprivate static java.lang.StringDEFAULT_FILENAME(package private) static intDEFAULT_LANGUAGE_VERSIONprivate static intDEFAULT_OPTprivate RhinoScriptEngineFactoryfactorystatic java.lang.StringOPTIMIZATION_LEVELReserved key for the Rhino optimization level.private ScriptableObjecttopLevelScope
-
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.CompiledScriptcompile(java.io.Reader script)javax.script.CompiledScriptcompile(java.lang.String script)private voidconfigureContext(Context cx)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)(package private) java.lang.Objecteval(Script script, javax.script.ScriptContext sc)javax.script.ScriptEngineFactorygetFactory()private java.lang.StringgetFilename()<T> TgetInterface(java.lang.Class<T> clasz)<T> TgetInterface(java.lang.Object thiz, java.lang.Class<T> clasz)private ScriptableinitScope(Context cx, javax.script.ScriptContext sc)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)(package private) java.lang.ObjectinvokeMethodRaw(java.lang.Object thiz, java.lang.String name, java.lang.Class<?> returnType, java.lang.Object... args)private static booleanmethodsMissing(Scriptable scope, java.lang.Class<?> clasz)private static intparseInteger(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:
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
-
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:
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
-
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.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
-
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)
-
-