Package org.htmlunit.javascript
Interface AbstractJavaScriptEngine<SCRIPT>
- Type Parameters:
SCRIPT
- the script type
- All Known Implementing Classes:
JavaScriptEngine
public interface AbstractJavaScriptEngine<SCRIPT>
An interface for
JavaScriptEngine
.-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPostponedAction
(PostponedAction action) Adds an action that should be executed first when the script currently being executed has finished.Deprecated.compile
(HtmlPage owningPage, org.htmlunit.corejs.javascript.Scriptable scope, String sourceCode, String sourceName, int startLine) Compiles the specified JavaScript code in the context of a given scope.Deprecated.as of version 3.12.0; useexecute(HtmlPage, Scriptable, String, String, int)
insteadexecute
(HtmlPage page, org.htmlunit.corejs.javascript.Scriptable scope, String sourceCode, String sourceName, int startLine) Executes the specified JavaScript code in the context of a given page.Executes the specified JavaScript code in the context of a given page.Deprecated.as of version 3.12.0; useexecute(HtmlPage, Scriptable, Object)
insteadGets the associated configuration.long
Returns the number of milliseconds that a script is allowed to execute before being terminated.void
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, Page page) Performs initialization for the given webWindow and page.boolean
Indicates if JavaScript is running in current thread.void
Disable starting of new js threads.void
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Process postponed actions, if any.void
registerWindowAndMaybeStartEventLoop
(WebWindow webWindow) Register WebWindow with the JavaScriptExecutor.void
setJavaScriptTimeout
(long timeout) Sets the number of milliseconds that a script is allowed to execute before being terminated.void
shutdown()
Shutdown the JavaScriptEngine.
-
Method Details
-
getJavaScriptConfiguration
JavaScriptConfiguration getJavaScriptConfiguration()Gets the associated configuration.- Returns:
- the configuration
-
addPostponedAction
Adds an action that should be executed first when the script currently being executed has finished.- Parameters:
action
- the action
-
processPostponedActions
void processPostponedActions()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Process postponed actions, if any. -
registerWindowAndMaybeStartEventLoop
Register WebWindow with the JavaScriptExecutor.- Parameters:
webWindow
- the WebWindow to be registered.
-
initialize
Performs initialization for the given webWindow and page.- Parameters:
webWindow
- the web window to initialize forpage
- the page that will become the enclosing page
-
setJavaScriptTimeout
void setJavaScriptTimeout(long timeout) Sets the number of milliseconds that a script is allowed to execute before being terminated. A value of 0 or less means no timeout.- Parameters:
timeout
- the timeout value, in milliseconds
-
getJavaScriptTimeout
long getJavaScriptTimeout()Returns the number of milliseconds that a script is allowed to execute before being terminated. A value of 0 or less means no timeout.- Returns:
- the timeout value, in milliseconds
-
prepareShutdown
void prepareShutdown()Disable starting of new js threads. -
shutdown
void shutdown()Shutdown the JavaScriptEngine. -
isScriptRunning
boolean isScriptRunning()Indicates if JavaScript is running in current thread. This allows code to know if their own evaluation is has been triggered by some JS code.- Returns:
true
if JavaScript is running
-
holdPosponedActions
void holdPosponedActions()INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Indicates that no postponed action should be executed. -
compile
SCRIPT compile(HtmlPage owningPage, org.htmlunit.corejs.javascript.Scriptable scope, String sourceCode, String sourceName, int startLine) Compiles the specified JavaScript code in the context of a given scope.- Parameters:
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 starts- Returns:
- the result of executing the specified code
-
compile
Deprecated.as of version 3.12.0; usecompile(HtmlPage, Scriptable, String, String, int)
insteadCompiles the specified JavaScript code in the context of a given HTML page.- Parameters:
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 starts- Returns:
- the result of executing the specified code
-
execute
Executes the specified JavaScript code in the context of a given page.- Parameters:
page
- the page that the code will execute withinscope
- the scope in which to executescript
- the script to execute- Returns:
- the result of executing the specified code
-
execute
Deprecated.as of version 3.12.0; useexecute(HtmlPage, Scriptable, Object)
insteadExecutes the specified JavaScript code in the context of a given page.- Parameters:
page
- the page that the code will execute withinscript
- the script to execute- Returns:
- the result of executing the specified code
-
execute
Object execute(HtmlPage page, org.htmlunit.corejs.javascript.Scriptable scope, String sourceCode, String sourceName, int startLine) Executes the specified JavaScript code in the context of a given page.- Parameters:
page
- the page that the code will execute withinscope
- the scope in which to executesourceCode
- the JavaScript code to executesourceName
- the name that will be displayed on error conditionsstartLine
- the line at which the script source starts- Returns:
- the result of executing the specified code
-
execute
Deprecated.as of version 3.12.0; useexecute(HtmlPage, Scriptable, String, String, int)
insteadExecutes the specified JavaScript code in the context of a given page.- Parameters:
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 starts- Returns:
- the result of executing the specified code
-
getContextFactory
HtmlUnitContextFactory getContextFactory()- Returns:
- this JavaScript engine's
HtmlUnitContextFactory
-
compile(HtmlPage, Scriptable, String, String, int)
instead