public class JavaScriptEngine extends Object implements AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
Like all classes in this package, this class is not intended for direct use and may change without notice.
Modifier and Type | Field and Description |
---|---|
static String |
KEY_STARTING_PAGE
Key used to place the
HtmlPage for which the JavaScript code is executed
as thread local attribute in current context. |
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.
|
Constructor and Description |
---|
JavaScriptEngine(WebClient webClient)
Creates an instance for the specified
WebClient . |
Modifier and Type | Method and Description |
---|---|
void |
addPostponedAction(PostponedAction action)
Adds an action that should be executed first when the script currently being executed has finished.
|
Object |
callFunction(HtmlPage page,
net.sourceforge.htmlunit.corejs.javascript.Function javaScriptFunction,
net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject,
Object[] args,
DomNode node)
Calls a JavaScript function and return the result.
|
Object |
callFunction(HtmlPage page,
net.sourceforge.htmlunit.corejs.javascript.Function function,
net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject,
Object[] args)
Calls the given function taking care of synchronization issues.
|
net.sourceforge.htmlunit.corejs.javascript.Script |
compile(HtmlPage owningPage,
net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
String sourceCode,
String sourceName,
int startLine)
Compiles the specified JavaScript code in the context of a given scope.
|
net.sourceforge.htmlunit.corejs.javascript.Script |
compile(HtmlPage page,
String sourceCode,
String sourceName,
int startLine)
Compiles the specified JavaScript code in the context of a given HTML page.
|
static HtmlUnitScriptable |
configureClass(ClassConfiguration config,
net.sourceforge.htmlunit.corejs.javascript.Scriptable window,
BrowserVersion browserVersion)
Configures the specified class for access via JavaScript.
|
Object |
execute(HtmlPage page,
net.sourceforge.htmlunit.corejs.javascript.Script script)
Executes the specified JavaScript code in the context of a given page.
|
Object |
execute(HtmlPage page,
net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
net.sourceforge.htmlunit.corejs.javascript.Script script)
Executes the specified JavaScript code in the given scope.
|
Object |
execute(HtmlPage page,
String sourceCode,
String sourceName,
int startLine)
Executes the specified JavaScript code in the context of a given page.
|
HtmlUnitContextFactory |
getContextFactory()
Returns this JavaScript engine's Rhino
ContextFactory . |
Class<? extends HtmlUnitScriptable> |
getJavaScriptClass(Class<?> c)
Gets the class of the JavaScript object for the node class.
|
JavaScriptConfiguration |
getJavaScriptConfiguration()
Gets the associated configuration.
|
JavaScriptExecutor |
getJavaScriptExecutor()
Returns the JavaScriptExecutor.
|
long |
getJavaScriptTimeout()
Returns the javascript timeout.
|
WebClient |
getWebClient()
Returns the web client that this engine is associated with.
|
protected void |
handleJavaScriptException(ScriptException scriptException,
boolean triggerOnError)
Handles an exception that occurred during execution of JavaScript code.
|
void |
holdPosponedActions()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Indicates that no postponed action should be executed. |
void |
initialize(WebWindow webWindow)
Performs initialization for the given webWindow.
|
boolean |
isScriptRunning()
Indicates if JavaScript is running in current thread.
|
void |
processPostponedActions()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Process postponed actions, if any. |
int |
pumpEventLoop(long timeoutMillis)
Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty.
|
void |
registerWindowAndMaybeStartEventLoop(WebWindow webWindow)
Register WebWindow with the JavaScriptExecutor.
|
void |
setJavaScriptTimeout(long timeout)
Sets the javascript timeout.
|
void |
shutdown()
Shutdown the JavaScriptEngine.
|
public static final String KEY_STARTING_SCOPE
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.
public static final String KEY_STARTING_PAGE
HtmlPage
for which the JavaScript code is executed
as thread local attribute in current context.public final WebClient getWebClient()
public HtmlUnitContextFactory getContextFactory()
ContextFactory
.ContextFactory
public void initialize(WebWindow webWindow)
initialize
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
webWindow
- the web window to initialize forpublic JavaScriptExecutor getJavaScriptExecutor()
public static HtmlUnitScriptable configureClass(ClassConfiguration config, net.sourceforge.htmlunit.corejs.javascript.Scriptable window, BrowserVersion browserVersion) throws InstantiationException, IllegalAccessException
config
- the configuration settings for the class to be configuredwindow
- the scope within which to configure the classbrowserVersion
- the browser versionInstantiationException
- if the new class cannot be instantiatedIllegalAccessException
- if we don't have access to create the new instancepublic void registerWindowAndMaybeStartEventLoop(WebWindow webWindow)
registerWindowAndMaybeStartEventLoop
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
webWindow
- the WebWindow to be registered.public int pumpEventLoop(long timeoutMillis)
GAEUtils.isGaeMode()
.timeoutMillis
- the timeout in millisecondspublic void shutdown()
shutdown
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
public net.sourceforge.htmlunit.corejs.javascript.Script compile(HtmlPage page, String sourceCode, String sourceName, int startLine)
compile
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
page
- the page that the code will execute withinsourceCode
- the JavaScript code to executesourceName
- the name that will be displayed on error conditionsstartLine
- the line at which the script source startspublic net.sourceforge.htmlunit.corejs.javascript.Script compile(HtmlPage owningPage, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, String sourceCode, String sourceName, int startLine)
owningPage
- the page from which the code startedscope
- the scope in which to execute the javascript codesourceCode
- the JavaScript code to executesourceName
- the name that will be displayed on error conditionsstartLine
- the line at which the script source startspublic Object execute(HtmlPage page, String sourceCode, String sourceName, int startLine)
execute
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
page
- the page that the code will execute withinsourceCode
- the JavaScript code to executesourceName
- the name that will be displayed on error conditionsstartLine
- the line at which the script source startspublic Object execute(HtmlPage page, net.sourceforge.htmlunit.corejs.javascript.Script script)
execute
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
page
- the page that the code will execute withinscript
- the script to executepublic Object execute(HtmlPage page, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, net.sourceforge.htmlunit.corejs.javascript.Script script)
page
- the page that started the executionscope
- the scope in which to executescript
- the script to executepublic Object callFunction(HtmlPage page, net.sourceforge.htmlunit.corejs.javascript.Function javaScriptFunction, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject, Object[] args, DomNode node)
page
- the pagejavaScriptFunction
- the function to callthisObject
- the this object for class method callsargs
- the list of arguments to pass to the functionnode
- the HTML element that will act as the contextpublic Object callFunction(HtmlPage page, net.sourceforge.htmlunit.corejs.javascript.Function function, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject, Object[] args)
page
- the interactive page that caused this script to executedfunction
- the JavaScript function to executescope
- the execution scopethisObject
- the 'this' objectargs
- the function's argumentspublic boolean isScriptRunning()
This allows code to know if there own evaluation is has been triggered by some JS code.
isScriptRunning
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
true
if JavaScript is runningpublic void addPostponedAction(PostponedAction action)
addPostponedAction
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
action
- the actionprotected void handleJavaScriptException(ScriptException scriptException, boolean triggerOnError)
scriptException
- the exceptiontriggerOnError
- if true, this triggers the onerror handlerpublic void holdPosponedActions()
holdPosponedActions
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
public void processPostponedActions()
processPostponedActions
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
public Class<? extends HtmlUnitScriptable> getJavaScriptClass(Class<?> c)
c
- the node class DomNode
or some subclass.null
if none foundpublic JavaScriptConfiguration getJavaScriptConfiguration()
getJavaScriptConfiguration
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
public long getJavaScriptTimeout()
getJavaScriptTimeout
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
public void setJavaScriptTimeout(long timeout)
setJavaScriptTimeout
in interface AbstractJavaScriptEngine<net.sourceforge.htmlunit.corejs.javascript.Script>
timeout
- the timeoutCopyright © 2002–2017 Gargoyle Software Inc.. All rights reserved.