Interface AbstractJavaScriptEngine<SCRIPT>

  • Type Parameters:
    SCRIPT - the script type
    All Known Implementing Classes:
    JavaScriptEngine

    public interface AbstractJavaScriptEngine<SCRIPT>
    An interface for JavaScriptEngine.
    • Method Detail

      • getJavaScriptConfiguration

        JavaScriptConfiguration getJavaScriptConfiguration()
        Gets the associated configuration.
        Returns:
        the configuration
      • addPostponedAction

        void addPostponedAction​(PostponedAction action)
        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

        void registerWindowAndMaybeStartEventLoop​(WebWindow webWindow)
        Register WebWindow with the JavaScriptExecutor.
        Parameters:
        webWindow - the WebWindow to be registered.
      • initialize

        void initialize​(WebWindow webWindow,
                        Page page)
        Performs initialization for the given webWindow and page.
        Parameters:
        webWindow - the web window to initialize for
        page - 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,
                       java.lang.String sourceCode,
                       java.lang.String sourceName,
                       int startLine)
        Compiles the specified JavaScript code in the context of a given scope.
        Parameters:
        owningPage - the page from which the code started
        scope - the scope in which to execute the javascript code
        sourceCode - the JavaScript code to execute
        sourceName - the name that will be displayed on error conditions
        startLine - the line at which the script source starts
        Returns:
        the result of executing the specified code
      • compile

        @Deprecated
        SCRIPT compile​(HtmlPage page,
                       java.lang.String sourceCode,
                       java.lang.String sourceName,
                       int startLine)
        Deprecated.
        as of version 3.12.0; use compile(HtmlPage, Scriptable, String, String, int) instead
        Compiles the specified JavaScript code in the context of a given HTML page.
        Parameters:
        page - the page that the code will execute within
        sourceCode - the JavaScript code to execute
        sourceName - the name that will be displayed on error conditions
        startLine - the line at which the script source starts
        Returns:
        the result of executing the specified code
      • execute

        java.lang.Object execute​(HtmlPage page,
                                 org.htmlunit.corejs.javascript.Scriptable scope,
                                 SCRIPT script)
        Executes the specified JavaScript code in the context of a given page.
        Parameters:
        page - the page that the code will execute within
        scope - the scope in which to execute
        script - the script to execute
        Returns:
        the result of executing the specified code
      • execute

        @Deprecated
        java.lang.Object execute​(HtmlPage page,
                                 SCRIPT script)
        Deprecated.
        as of version 3.12.0; use execute(HtmlPage, Scriptable, Object) instead
        Executes the specified JavaScript code in the context of a given page.
        Parameters:
        page - the page that the code will execute within
        script - the script to execute
        Returns:
        the result of executing the specified code
      • execute

        java.lang.Object execute​(HtmlPage page,
                                 org.htmlunit.corejs.javascript.Scriptable scope,
                                 java.lang.String sourceCode,
                                 java.lang.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 within
        scope - the scope in which to execute
        sourceCode - the JavaScript code to execute
        sourceName - the name that will be displayed on error conditions
        startLine - the line at which the script source starts
        Returns:
        the result of executing the specified code
      • execute

        @Deprecated
        java.lang.Object execute​(HtmlPage page,
                                 java.lang.String sourceCode,
                                 java.lang.String sourceName,
                                 int startLine)
        Deprecated.
        as of version 3.12.0; use execute(HtmlPage, Scriptable, String, String, int) instead
        Executes the specified JavaScript code in the context of a given page.
        Parameters:
        page - the page that the code will execute within
        sourceCode - the JavaScript code to execute
        sourceName - the name that will be displayed on error conditions
        startLine - the line at which the script source starts
        Returns:
        the result of executing the specified code