public class RhinoScriptEngine extends AbstractScriptEngine implements Invocable, Compilable
ScriptEngine using the Mozilla Rhino
interpreter.| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEBUG |
contextARGV, ENGINE, ENGINE_VERSION, FILENAME, LANGUAGE, LANGUAGE_VERSION, NAME| Constructor and Description |
|---|
RhinoScriptEngine() |
RhinoScriptEngine(org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider moduleSourceProvider)
Creates a new instance of RhinoScriptEngine with given moduleSourceProvider as the "locator"
for the CommonJS modules.
|
| Modifier and Type | Method and Description |
|---|---|
static Object |
bindings(org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable thisObj,
Object[] args,
org.mozilla.javascript.Function funObj)
The bindings function takes a JavaScript scope object
of type ExternalScriptable and returns the underlying Bindings
instance.
|
CompiledScript |
compile(Reader script) |
CompiledScript |
compile(String script) |
Bindings |
createBindings() |
Object |
eval(Reader reader,
ScriptContext ctxt) |
Object |
eval(String script,
ScriptContext ctxt) |
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) |
static void |
main(String[] args) |
protected Reader |
preProcessScriptSource(Reader reader) |
protected void |
processAllTopLevelScripts(org.mozilla.javascript.Context cx) |
protected void |
processTopLevelScript(String scriptName,
org.mozilla.javascript.Context cx) |
static Object |
scope(org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable thisObj,
Object[] args,
org.mozilla.javascript.Function funObj)
The scope function creates a new JavaScript scope object
with given Bindings object as backing store.
|
void |
setModuleSourceProvider(org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider provider) |
static Object |
sync(org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable thisObj,
Object[] args,
org.mozilla.javascript.Function funObj)
The sync function creates a synchronized function (in the sense
of a Java synchronized method) from an existing function.
|
eval, eval, eval, eval, get, getBindings, getContext, getScriptContext, put, setBindings, setContextpublic static final boolean DEBUG
public RhinoScriptEngine()
public RhinoScriptEngine(org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider moduleSourceProvider)
moduleSourceProvider - the implementation able to locate sources of modules for CommonJS.public void setModuleSourceProvider(org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider provider)
public Object eval(Reader reader, ScriptContext ctxt) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic Object eval(String script, ScriptContext ctxt) throws ScriptException
eval in interface ScriptEngineScriptExceptionpublic ScriptEngineFactory getFactory()
getFactory in interface ScriptEnginepublic Bindings createBindings()
createBindings in interface ScriptEnginepublic 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 CompiledScript compile(String script) throws ScriptException
compile in interface CompilableScriptExceptionpublic CompiledScript compile(Reader script) throws ScriptException
compile in interface CompilableScriptExceptionprotected Reader preProcessScriptSource(Reader reader) throws ScriptException
ScriptExceptionprotected void processAllTopLevelScripts(org.mozilla.javascript.Context cx)
protected void processTopLevelScript(String scriptName, org.mozilla.javascript.Context cx)
public static Object bindings(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
public static Object scope(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
public static Object sync(org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable thisObj, Object[] args, org.mozilla.javascript.Function funObj)
this object of
its invocation.
js> var o = { f : sync(function(x) {
print("entry");
Packages.java.lang.Thread.sleep(x*1000);
print("exit");
})};
js> thread(function() {o.f(5);});
entry
js> thread(function() {o.f(5);});
js>
exit
entry
exitCopyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.