|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface ScriptEngine
This interface allows code to interact with a script engine that has been instantiated. This interface is not meant to be implemented by third-party code; implementations of ScriptEngine will be exposed by other device APIs. Additional methods may be added to this class at any time, so third-party code that attempts to implement this interface may break in future releases.
| Method Summary | ||
|---|---|---|
void |
addExtension(String name,
Object value)
Injects extensions into the script engine. |
|
Object |
compileScript(String script)
Compiles a script for optimized use. |
|
Object |
executeCompiledScript(Object compiledScript,
Object context)
Executes a compiled script. |
|
Object |
executeScript(String script,
Object context)
A convenience method for executing scripts. |
|
| Method Detail |
|---|
void addExtension(String name,
Object value)
throws Exception
name parameter
corresponds to the injection point, and the value parameter
corresponds to the object being injected.
ScriptableImpl myobj = new ScriptableImpl();
myobj.putField( "foo1", "bar1" );
myobj.putField( "foo2", "bar2" );
_scriptEngine.addExtension( "window.myobject", myobj );
The script environment would then have access to "bar1" and "bar2" as
"window.myobject.foo1" and "window.myobject.foo2" respectively.
name - The location at which the object should be injected.value - The object to be injected. This may be of any type accepted by
the script engine (see Scriptable for details), including
null.
IllegalStateException - if the ScriptEngine cannot inject the
object in its current state (e.g. it has been suspended or terminated).
IllegalArgumentException - if an error occurred during the injection.
Exception
Object executeScript(String script,
Object context)
throws IllegalStateException,
IllegalArgumentException,
RuntimeException
executeScript( string, context ) is equivalent to calling
executeCompiledScript( compileScript( script ), context ).
IllegalStateException
IllegalArgumentException
RuntimeExceptionScriptEngine.compileScript(String),
ScriptEngine.executeCompiledScript(Object,Object)
Object executeCompiledScript(Object compiledScript,
Object context)
throws IllegalStateException,
IllegalArgumentException,
RuntimeException
compiledScript - A compiled script obtained from a previous call to compileScript.context - A engine-specific context object. This may be null. The details of the
object to pass in will be provided by the provider of the ScriptEngine interface.
null.
This will be Scriptable.UNDEFINED if the script does not return a value.
IllegalStateException - if the ScriptEngine cannot run scripts in its
current state (e.g. it has been suspended or terminated).
IllegalArgumentException - if the compiledScript could not be executed, or
if the context object was determined to be illegal. This exception is also thrown upon encountering
uncaught script errors during execution.
RuntimeException - certain types of error thrown during script execution (e.g. DOMExceptions
from failed DOM operations) will get propagated out in their original form. These error should generally be
dealt with in a similar fashion to the IllegalArgumentExceptions thrown by this method, although
they may provide more detailed information to diagnose the error.
Object compileScript(String script)
throws IllegalArgumentException
script - The script to compile. This must not be null.
IllegalArgumentException - if the script could not be compiled. This is most likely
caused by syntax errors in the script.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal