com.gargoylesoftware.htmlunit.javascript
Class JavaScriptEngine

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.ScriptEngine
      extended by com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine
All Implemented Interfaces:
java.io.Serializable

public class JavaScriptEngine
extends ScriptEngine
implements java.io.Serializable

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: 1.3 $
Author:
Mike Bowler, Chen Jun, David K. Taylor, Chris Erskine, Ben Curren, David D. Kilzer, Marc Guillemot, Daniel Gredler, Ahmed Ashour
See Also:
Rhino and Java Browser, Serialized Form

Field Summary
static java.lang.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.
 
Constructor Summary
JavaScriptEngine(WebClient webClient)
 Create an instance for the specified webclient
 
Method Summary
 java.lang.Object callFunction(HtmlPage htmlPage, org.mozilla.javascript.Function function, org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObject, java.lang.Object[] args)
 Calls the given function taking care of synchronisation issues.
 java.lang.Object callFunction(HtmlPage htmlPage, java.lang.Object javaScriptFunction, java.lang.Object thisObject, java.lang.Object[] args, DomNode htmlElement)
 Call a JavaScript function and return the result.
 java.lang.Object execute(HtmlPage htmlPage, java.lang.String sourceCode, java.lang.String sourceName, HtmlElement htmlElement)
 Execute the specified javascript code in the context of a given html page.
static long getTimeout()
 Returns the number of milliseconds a script is allowed to execute before being terminated.
 void initialize(WebWindow webWindow)
 perform initialization for the given webWindow
 boolean isScriptRunning()
 Indicates if JavaScript is running in current thread.
static void setTimeout(long timeout)
 Set the number of milliseconds a script is allowed to execute before being terminated.
 
Methods inherited from class com.gargoylesoftware.htmlunit.ScriptEngine
execute, getScriptEngineLog, getWebClient, preProcess
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_STARTING_SCOPE

public static final java.lang.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.

See Also:
Constant Field Values
Constructor Detail

JavaScriptEngine

public JavaScriptEngine(WebClient webClient)
Create an instance for the specified webclient

Parameters:
webClient - The webClient that will own this engine.
Method Detail

callFunction

public java.lang.Object callFunction(HtmlPage htmlPage,
                                     org.mozilla.javascript.Function function,
                                     org.mozilla.javascript.Context context,
                                     org.mozilla.javascript.Scriptable scope,
                                     org.mozilla.javascript.Scriptable thisObject,
                                     java.lang.Object[] args)
Calls the given function taking care of synchronisation issues.

Parameters:
htmlPage - the html page that caused this script to executed
function - the js function to execute
context - the context in which execution should occur
scope - the execution scope
thisObject - the 'this' object
args - the function's arguments
Returns:
the function result

callFunction

public java.lang.Object callFunction(HtmlPage htmlPage,
                                     java.lang.Object javaScriptFunction,
                                     java.lang.Object thisObject,
                                     java.lang.Object[] args,
                                     DomNode htmlElement)
Call a JavaScript function and return the result.

Specified by:
callFunction in class ScriptEngine
Parameters:
htmlPage - The page
javaScriptFunction - The function to call.
thisObject - The this object for class method calls.
args - The list of arguments to pass to the function.
htmlElement - The html element that will act as the context.
Returns:
The result of the function call.

execute

public java.lang.Object execute(HtmlPage htmlPage,
                                java.lang.String sourceCode,
                                java.lang.String sourceName,
                                HtmlElement htmlElement)
Execute the specified javascript code in the context of a given html page.

Specified by:
execute in class ScriptEngine
Parameters:
htmlPage - The page that the code will execute within
sourceCode - The javascript code to execute.
sourceName - The name that will be displayed on error conditions.
htmlElement - The element that will be used as context.
Returns:
The result of executing the specified code.

getTimeout

public static long getTimeout()
Returns the number of milliseconds a script is allowed to execute before being terminated. A value of 0 or less means no timeout.

Returns:
the timeout value

initialize

public void initialize(WebWindow webWindow)
perform initialization for the given webWindow

Specified by:
initialize in class ScriptEngine
Parameters:
webWindow - the web window to initialize for

isScriptRunning

public boolean isScriptRunning()
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.

Specified by:
isScriptRunning in class ScriptEngine
Returns:
true if JavaScript is running.

setTimeout

public static void setTimeout(long timeout)
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


Copyright © 2003-2016 AppPerfect Corporation. All Rights Reserved.