| java.lang.Object com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine
JavaScriptEngine | public class JavaScriptEngine implements Serializable(Code) | | A wrapper for the Rhino javascript engine
that provides browser specific features.
Like all classes in this package, this class is not intended for direct use
and may change without notice.
version: $Revision: 2158 $ author: Mike Bowler author: Chen Jun author: David K. Taylor author: Chris Erskine author: Ben Curren author: David D. Kilzer author: Marc Guillemot author: Daniel Gredler author: Ahmed Ashour See Also:
* Rhino and Java Browser |
Field Summary | |
final public static String | KEY_STARTING_SCOPE Key used to place the scope in which the execution of some javascript code
started as thread local attribute in current context.
This is needed to resolve some relative locations relatively to the page
in which the script is executed and not to the page which location is changed. |
Method Summary | |
public void | cacheScript(WebResponse webResponse, Script script) Cache a parsed script
Parameters: webResponse - the response corresponding to the script code. | public Object | callFunction(HtmlPage htmlPage, Object javaScriptFunction, Object thisObject, Object[] args, DomNode htmlElement) Call a JavaScript function and return the result.
Parameters: htmlPage - The page Parameters: javaScriptFunction - The function to call. Parameters: thisObject - The this object for class method calls. Parameters: args - The list of arguments to pass to the function. Parameters: htmlElement - The html element that will act as the context. | public Object | callFunction(HtmlPage htmlPage, Function function, Context context, Scriptable scope, Scriptable thisObject, Object[] args) Calls the given function taking care of synchronization issues. | public Script | compile(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine) Compiles the specified javascript code in the context of a given html page. | public Object | execute(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine) Execute the specified javascript code in the context of a given html page. | public Object | execute(HtmlPage htmlPage, Script script) Execute the specified javascript code in the context of a given html page. | public Script | getCachedScript(WebResponse webResponse) Get the cached script for the given response. | protected Log | getLog() | public static Log | getScriptEngineLog() Return the log object that is being used to log information about the script engine. | public static long | getTimeout() Returns the number of milliseconds a script is allowed to execute before
being terminated. | final public WebClient | getWebClient() Return the web client that this engine is associated with. | public void | initialize(WebWindow webWindow) | public boolean | isScriptRunning() Indicates if JavaScript is running in current thread. | public String | preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, HtmlElement htmlElement) Pre process the specified source code in the context of the given page using the processor specified
in the webclient. | public static void | setTimeout(long timeout) Set the number of milliseconds a script is allowed to execute before
being terminated. |
KEY_STARTING_SCOPE | final public static String KEY_STARTING_SCOPE(Code) | | Key used to place the scope in which the execution of some javascript code
started as thread local attribute in current context.
This is needed to resolve some relative locations relatively to the page
in which the script is executed and not to the page which location is changed.
|
JavaScriptEngine | public JavaScriptEngine(WebClient webClient)(Code) | | Create an instance for the specified webclient
Parameters: webClient - The webClient that will own this engine. |
cacheScript | public void cacheScript(WebResponse webResponse, Script script)(Code) | | Cache a parsed script
Parameters: webResponse - the response corresponding to the script code. A weak reference to this objectwill be used as key for the cache. Parameters: script - the parsed script to cache |
callFunction | public Object callFunction(HtmlPage htmlPage, Object javaScriptFunction, Object thisObject, Object[] args, DomNode htmlElement)(Code) | | Call a JavaScript function and return the result.
Parameters: htmlPage - The page Parameters: javaScriptFunction - The function to call. Parameters: thisObject - The this object for class method calls. Parameters: args - The list of arguments to pass to the function. Parameters: htmlElement - The html element that will act as the context. The result of the function call. |
callFunction | public Object callFunction(HtmlPage htmlPage, Function function, Context context, Scriptable scope, Scriptable thisObject, Object[] args)(Code) | | Calls the given function taking care of synchronization issues.
Parameters: htmlPage - the html page that caused this script to executed Parameters: function - the js function to execute Parameters: context - the context in which execution should occur Parameters: scope - the execution scope Parameters: thisObject - the 'this' object Parameters: args - the function's arguments the function result |
compile | public Script compile(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine)(Code) | | Compiles the specified javascript code in the context of a given html page.
Parameters: htmlPage - The page that the code will execute within Parameters: sourceCode - The javascript code to execute. Parameters: sourceName - The name that will be displayed on error conditions. Parameters: startLine - the line at which the script source starts The result of executing the specified code. |
execute | public Object execute(HtmlPage htmlPage, String sourceCode, String sourceName, int startLine)(Code) | | Execute the specified javascript code in the context of a given html page.
Parameters: htmlPage - The page that the code will execute within Parameters: sourceCode - The javascript code to execute. Parameters: sourceName - The name that will be displayed on error conditions. Parameters: startLine - the line at which the script source starts The result of executing the specified code. |
execute | public Object execute(HtmlPage htmlPage, Script script)(Code) | | Execute the specified javascript code in the context of a given html page.
Parameters: htmlPage - The page that the code will execute within Parameters: script - the script to execute The result of executing the specified code. |
getCachedScript | public Script getCachedScript(WebResponse webResponse)(Code) | | Get the cached script for the given response.
Parameters: webResponse - the response corresponding to the script code the parsed script |
getLog | protected Log getLog()(Code) | | Return the log object for this class
The log object |
getScriptEngineLog | public static Log getScriptEngineLog()(Code) | | Return the log object that is being used to log information about the script engine.
The log |
getTimeout | public static long getTimeout()(Code) | | Returns the number of milliseconds a script is allowed to execute before
being terminated. A value of 0 or less means no timeout.
the timeout value |
getWebClient | final public WebClient getWebClient()(Code) | | Return the web client that this engine is associated with.
The web client. |
initialize | public void initialize(WebWindow webWindow)(Code) | | Perform initialization for the given webWindow
Parameters: webWindow - the web window to initialize for |
isScriptRunning | public boolean isScriptRunning()(Code) | | Indicates if JavaScript is running in current thread.
This allows code to know if there own evaluation is has been triggered by some JS code.
true if JavaScript is running. |
preProcess | public String preProcess(HtmlPage htmlPage, String sourceCode, String sourceName, HtmlElement htmlElement)(Code) | | Pre process the specified source code in the context of the given page using the processor specified
in the webclient. This method delegates to the pre processor handler specified in the
WebClient . If no pre processor handler is defined, the original source code is returned
unchanged.
Parameters: htmlPage - The page Parameters: sourceCode - The code to process. Parameters: sourceName - A name for the chunk of code. This will be used in error messages. Parameters: htmlElement - The html element that will act as the context. The source code after being pre processed See Also: com.gargoylesoftware.htmlunit.ScriptPreProcessor |
setTimeout | public static void setTimeout(long timeout)(Code) | | Set the number of milliseconds a script is allowed to execute before
being terminated. A value of 0 or less means no timeout.
Parameters: timeout - the timeout value |
|
|