Class JavaScriptEngine

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private static void additionalCtor​(Window window, java.util.Map<java.lang.String,​org.htmlunit.corejs.javascript.Scriptable> prototypesPerJSName, java.lang.reflect.Method ctorMethod, java.lang.String prop, java.lang.String clazzName)  
      void addPostponedAction​(PostponedAction action)
      Adds an action that should be executed first when the script currently being executed has finished.
      static void applyPolyfills​(WebClient webClient, BrowserVersion browserVersion, org.htmlunit.corejs.javascript.Context context, HtmlUnitScriptable scriptable)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      static org.htmlunit.corejs.javascript.RhinoException asJavaScriptException​(Window window, DOMException exception)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Encapsulates the given DOMException into a Rhino-compatible exception.
      java.lang.Object callFunction​(HtmlPage page, org.htmlunit.corejs.javascript.Function javaScriptFunction, org.htmlunit.corejs.javascript.Scriptable thisObject, java.lang.Object[] args, DomNode node)
      Calls a JavaScript function and return the result.
      java.lang.Object callFunction​(HtmlPage page, org.htmlunit.corejs.javascript.Function function, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObject, java.lang.Object[] args)
      Calls the given function taking care of synchronization issues.
      <T> T callSecured​(org.htmlunit.corejs.javascript.ContextAction<T> action, HtmlPage page)
      Forwards this to the HtmlUnitContextFactory but with checking shutdown handling.
      org.htmlunit.corejs.javascript.Script compile​(HtmlPage owningPage, java.lang.String sourceCode, java.lang.String sourceName, int startLine)
      Deprecated.
      org.htmlunit.corejs.javascript.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.
      static HtmlUnitScriptable configureClass​(ClassConfiguration config, org.htmlunit.corejs.javascript.Scriptable window, BrowserVersion browserVersion)
      Configures the specified class for access via JavaScript.
      private static void configureConstants​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      private static void configureConstantsPropertiesAndFunctions​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      Configures constants, properties and functions on the object.
      private static void configureConstantsStaticPropertiesAndStaticFunctions​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      Configures constants, static properties and static functions on the object.
      private static void configureFunctions​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      private static void configureProperties​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      static void configureRhino​(WebClient webClient, BrowserVersion browserVersion, HtmlUnitScriptable scriptable)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      private static void configureStaticFunctions​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      private static void configureStaticProperties​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      private static void configureSymbolConstants​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      private static void configureSymbols​(ClassConfiguration config, org.htmlunit.corejs.javascript.ScriptableObject scriptable)  
      static org.htmlunit.corejs.javascript.EcmaError constructError​(java.lang.String error, java.lang.String message)  
      private static void defineConstructor​(Window window, org.htmlunit.corejs.javascript.Scriptable prototype, org.htmlunit.corejs.javascript.ScriptableObject constructor)  
      private static void deleteProperties​(org.htmlunit.corejs.javascript.Scriptable scope, java.lang.String... propertiesToDelete)
      Deletes the properties with the provided names.
      (package private) void doProcessPostponedActions()  
      static java.lang.String evaluateProxyAutoConfig​(BrowserVersion browserVersion, java.lang.String content, java.net.URL url)
      Evaluates the FindProxyForURL method of the specified content.
      java.lang.Object execute​(HtmlPage page, java.lang.String sourceCode, java.lang.String sourceName, int startLine)
      Deprecated.
      java.lang.Object execute​(HtmlPage page, org.htmlunit.corejs.javascript.Script script)
      Deprecated.
      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.
      java.lang.Object execute​(HtmlPage page, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Script script)
      Executes the specified JavaScript code in the context of a given page.
      HtmlUnitContextFactory getContextFactory()
      java.lang.Class<? extends HtmlUnitScriptable> getJavaScriptClass​(java.lang.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.
      private static org.htmlunit.corejs.javascript.Scriptable getScope​(HtmlPage page, DomNode node)  
      private 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.
      protected void handleJavaScriptTimeoutError​(HtmlPage page, TimeoutError e)
      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.
      private void init​(WebWindow webWindow, Page page, org.htmlunit.corejs.javascript.Context context)
      Initializes all the JS stuff for the window.
      void initialize​(WebWindow webWindow, Page page)
      Performs initialization for the given webWindow.
      private void initTransientFields()  
      static boolean isNaN​(java.lang.Object obj)  
      boolean isScriptRunning()
      Indicates if JavaScript is running in current thread.
      static boolean isUndefined​(java.lang.Object obj)  
      static org.htmlunit.corejs.javascript.Scriptable newArray​(org.htmlunit.corejs.javascript.Scriptable scope, int length)
      Create an array with a specified initial length.
      static org.htmlunit.corejs.javascript.Scriptable newArray​(org.htmlunit.corejs.javascript.Scriptable scope, java.lang.Object[] elements)
      Create an array with a specified initial length.
      static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeEntries​(org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable arrayLike)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.ENTRIES
      static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeKeys​(org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable arrayLike)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.KEYS
      static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeValues​(org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable arrayLike)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.VALUES
      void prepareShutdown()
      Disable starting of new js threads.
      void processPostponedActions()
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Process postponed actions, if any.
      static org.htmlunit.corejs.javascript.EcmaError rangeError​(java.lang.String message)
      Report a runtime error using the error reporter for the current thread.
      private void readObject​(java.io.ObjectInputStream in)
      Re-initializes transient fields when an object of this type is deserialized.
      void registerWindowAndMaybeStartEventLoop​(WebWindow webWindow)
      Register WebWindow with the JavaScriptExecutor.
      private static void removePrototypeProperties​(org.htmlunit.corejs.javascript.Scriptable scope, java.lang.String className, java.lang.String... properties)
      Removes prototype properties.
      static java.lang.RuntimeException reportRuntimeError​(java.lang.String message)
      Report a runtime error using the error reporter for the current thread.
      void setJavaScriptTimeout​(long timeout)
      Sets the javascript timeout.
      void shutdown()
      Shutdown the JavaScriptEngine.
      static java.lang.RuntimeException throwAsScriptRuntimeEx​(java.lang.Throwable e)
      Rethrow the exception wrapping it as the script runtime exception.
      static boolean toBoolean​(java.lang.Object value)
      Convert the value to a JavaScript boolean value.
      static int toInt32​(java.lang.Object o)  
      static double toInteger​(java.lang.Object o)  
      static double toInteger​(java.lang.Object[] args, int index)  
      static double toNumber​(java.lang.Object value)
      Convert the value to a JavaScript Number value.
      static java.lang.String toString​(java.lang.Object value)
      Convert the value to a JavaScript String value.
      static org.htmlunit.corejs.javascript.EcmaError typeError​(java.lang.String message)
      Report a runtime error using the error reporter for the current thread.
      static java.lang.String uncompressJavaScript​(java.lang.String scriptSource, java.lang.String scriptName)
      Tries to uncompress the JavaScript code in the provided response.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • emptyArgs

        public static final java.lang.Object[] emptyArgs
        ScriptRuntime.emptyArgs.
      • Undefined

        public static final java.lang.Object Undefined
        org.htmlunit.corejs.javascript.Undefined.instance.
      • javaScriptRunning_

        private transient java.lang.ThreadLocal<java.lang.Boolean> javaScriptRunning_
      • postponedActions_

        private transient java.lang.ThreadLocal<java.util.List<PostponedAction>> postponedActions_
      • holdPostponedActions_

        private transient boolean holdPostponedActions_
      • shutdownPending_

        private transient boolean shutdownPending_
      • javaScriptExecutor_

        private transient JavaScriptExecutor javaScriptExecutor_
        The JavaScriptExecutor corresponding to all windows of this Web client
      • 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
      • KEY_STARTING_PAGE

        public static final java.lang.String KEY_STARTING_PAGE
        Key used to place the HtmlPage for which the JavaScript code is executed as thread local attribute in current context.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JavaScriptEngine

        public JavaScriptEngine​(WebClient webClient)
        Creates an instance for the specified WebClient.
        Parameters:
        webClient - the client that will own this engine
    • Method Detail

      • getWebClient

        private WebClient getWebClient()
        Returns the web client that this engine is associated with.
        Returns:
        the web client
      • initialize

        public void initialize​(WebWindow webWindow,
                               Page page)
        Performs initialization for the given webWindow.
        Specified by:
        initialize in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        webWindow - the web window to initialize for
        page - the page that will become the enclosing page
      • getJavaScriptExecutor

        public JavaScriptExecutor getJavaScriptExecutor()
        Returns the JavaScriptExecutor.
        Returns:
        the JavaScriptExecutor or null if javascript is disabled or no executor was required so far.
      • init

        private void init​(WebWindow webWindow,
                          Page page,
                          org.htmlunit.corejs.javascript.Context context)
                   throws java.lang.Exception
        Initializes all the JS stuff for the window.
        Parameters:
        webWindow - the web window
        context - the current context
        Throws:
        java.lang.Exception - if something goes wrong
      • additionalCtor

        private static void additionalCtor​(Window window,
                                           java.util.Map<java.lang.String,​org.htmlunit.corejs.javascript.Scriptable> prototypesPerJSName,
                                           java.lang.reflect.Method ctorMethod,
                                           java.lang.String prop,
                                           java.lang.String clazzName)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • configureRhino

        public static void configureRhino​(WebClient webClient,
                                          BrowserVersion browserVersion,
                                          HtmlUnitScriptable scriptable)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        webClient - the WebClient
        browserVersion - the BrowserVersion
        scriptable - the window or the DedicatedWorkerGlobalScope
      • applyPolyfills

        public static void applyPolyfills​(WebClient webClient,
                                          BrowserVersion browserVersion,
                                          org.htmlunit.corejs.javascript.Context context,
                                          HtmlUnitScriptable scriptable)
                                   throws java.io.IOException
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Parameters:
        webClient - the WebClient
        browserVersion - the BrowserVersion
        context - the current context
        scriptable - the window or the DedicatedWorkerGlobalScope
        Throws:
        java.io.IOException - in case of problems
      • defineConstructor

        private static void defineConstructor​(Window window,
                                              org.htmlunit.corejs.javascript.Scriptable prototype,
                                              org.htmlunit.corejs.javascript.ScriptableObject constructor)
      • deleteProperties

        private static void deleteProperties​(org.htmlunit.corejs.javascript.Scriptable scope,
                                             java.lang.String... propertiesToDelete)
        Deletes the properties with the provided names.
        Parameters:
        scope - the scope from which properties have to be removed
        propertiesToDelete - the list of property names
      • removePrototypeProperties

        private static void removePrototypeProperties​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                      java.lang.String className,
                                                      java.lang.String... properties)
        Removes prototype properties.
        Parameters:
        scope - the scope
        className - the class for which properties should be removed
        properties - the properties to remove
      • configureClass

        public static HtmlUnitScriptable configureClass​(ClassConfiguration config,
                                                        org.htmlunit.corejs.javascript.Scriptable window,
                                                        BrowserVersion browserVersion)
                                                 throws java.lang.InstantiationException,
                                                        java.lang.IllegalAccessException
        Configures the specified class for access via JavaScript.
        Parameters:
        config - the configuration settings for the class to be configured
        window - the scope within which to configure the class
        browserVersion - the browser version
        Returns:
        the created prototype
        Throws:
        java.lang.InstantiationException - if the new class cannot be instantiated
        java.lang.IllegalAccessException - if we don't have access to create the new instance
      • configureConstantsStaticPropertiesAndStaticFunctions

        private static void configureConstantsStaticPropertiesAndStaticFunctions​(ClassConfiguration config,
                                                                                 org.htmlunit.corejs.javascript.ScriptableObject scriptable)
        Configures constants, static properties and static functions on the object.
        Parameters:
        config - the configuration for the object
        scriptable - the object to configure
      • configureConstantsPropertiesAndFunctions

        private static void configureConstantsPropertiesAndFunctions​(ClassConfiguration config,
                                                                     org.htmlunit.corejs.javascript.ScriptableObject scriptable)
        Configures constants, properties and functions on the object.
        Parameters:
        config - the configuration for the object
        scriptable - the object to configure
      • configureFunctions

        private static void configureFunctions​(ClassConfiguration config,
                                               org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureConstants

        private static void configureConstants​(ClassConfiguration config,
                                               org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureProperties

        private static void configureProperties​(ClassConfiguration config,
                                                org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureStaticProperties

        private static void configureStaticProperties​(ClassConfiguration config,
                                                      org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureStaticFunctions

        private static void configureStaticFunctions​(ClassConfiguration config,
                                                     org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureSymbolConstants

        private static void configureSymbolConstants​(ClassConfiguration config,
                                                     org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • configureSymbols

        private static void configureSymbols​(ClassConfiguration config,
                                             org.htmlunit.corejs.javascript.ScriptableObject scriptable)
      • registerWindowAndMaybeStartEventLoop

        public void registerWindowAndMaybeStartEventLoop​(WebWindow webWindow)
        Register WebWindow with the JavaScriptExecutor.
        Specified by:
        registerWindowAndMaybeStartEventLoop in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        webWindow - the WebWindow to be registered.
      • shutdown

        public void shutdown()
        Shutdown the JavaScriptEngine.
        Specified by:
        shutdown in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
      • compile

        public org.htmlunit.corejs.javascript.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.
        Specified by:
        compile in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        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
        public org.htmlunit.corejs.javascript.Script compile​(HtmlPage owningPage,
                                                             java.lang.String sourceCode,
                                                             java.lang.String sourceName,
                                                             int startLine)
        Deprecated.
        Compiles the specified JavaScript code in the context of a given HTML page.
        Specified by:
        compile in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        owningPage - 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
      • callSecured

        public final <T> T callSecured​(org.htmlunit.corejs.javascript.ContextAction<T> action,
                                       HtmlPage page)
        Forwards this to the HtmlUnitContextFactory but with checking shutdown handling.
        Type Parameters:
        T - return type of the action
        Parameters:
        action - the contextAction
        page - the page
        Returns:
        the result of the call
      • execute

        public 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.
        Specified by:
        execute in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        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
        public java.lang.Object execute​(HtmlPage page,
                                        java.lang.String sourceCode,
                                        java.lang.String sourceName,
                                        int startLine)
        Deprecated.
        Executes the specified JavaScript code in the context of a given page.
        Specified by:
        execute in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        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

        public java.lang.Object execute​(HtmlPage page,
                                        org.htmlunit.corejs.javascript.Scriptable scope,
                                        org.htmlunit.corejs.javascript.Script script)
        Executes the specified JavaScript code in the context of a given page.
        Specified by:
        execute in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        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
        public java.lang.Object execute​(HtmlPage page,
                                        org.htmlunit.corejs.javascript.Script script)
        Deprecated.
        Executes the specified JavaScript code in the context of a given page.
        Specified by:
        execute in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        page - the page that the code will execute within
        script - the script to execute
        Returns:
        the result of executing the specified code
      • callFunction

        public java.lang.Object callFunction​(HtmlPage page,
                                             org.htmlunit.corejs.javascript.Function javaScriptFunction,
                                             org.htmlunit.corejs.javascript.Scriptable thisObject,
                                             java.lang.Object[] args,
                                             DomNode node)
        Calls a JavaScript function and return the result.
        Parameters:
        page - 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
        node - the HTML element that will act as the context
        Returns:
        the result of the function call
      • callFunction

        public java.lang.Object callFunction​(HtmlPage page,
                                             org.htmlunit.corejs.javascript.Function function,
                                             org.htmlunit.corejs.javascript.Scriptable scope,
                                             org.htmlunit.corejs.javascript.Scriptable thisObject,
                                             java.lang.Object[] args)
        Calls the given function taking care of synchronization issues.
        Parameters:
        page - the interactive page that caused this script to executed
        function - the JavaScript function to execute
        scope - the execution scope
        thisObject - the 'this' object
        args - the function's arguments
        Returns:
        the function result
      • getScope

        private static org.htmlunit.corejs.javascript.Scriptable getScope​(HtmlPage page,
                                                                          DomNode node)
      • 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 interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Returns:
        true if JavaScript is running
      • doProcessPostponedActions

        void doProcessPostponedActions()
      • addPostponedAction

        public void addPostponedAction​(PostponedAction action)
        Adds an action that should be executed first when the script currently being executed has finished.
        Specified by:
        addPostponedAction in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        action - the action
      • handleJavaScriptException

        protected void handleJavaScriptException​(ScriptException scriptException,
                                                 boolean triggerOnError)
        Handles an exception that occurred during execution of JavaScript code.
        Parameters:
        scriptException - the exception
        triggerOnError - if true, this triggers the onerror handler
      • handleJavaScriptTimeoutError

        protected void handleJavaScriptTimeoutError​(HtmlPage page,
                                                    TimeoutError e)
        Handles an exception that occurred during execution of JavaScript code.
        Parameters:
        page - the page in which the script causing this exception was executed
        e - the timeout error that was thrown from the script engine
      • holdPosponedActions

        public void holdPosponedActions()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Indicates that no postponed action should be executed.
        Specified by:
        holdPosponedActions in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
      • processPostponedActions

        public void processPostponedActions()
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Process postponed actions, if any.
        Specified by:
        processPostponedActions in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
      • readObject

        private void readObject​(java.io.ObjectInputStream in)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Re-initializes transient fields when an object of this type is deserialized.
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • initTransientFields

        private void initTransientFields()
      • getJavaScriptClass

        public java.lang.Class<? extends HtmlUnitScriptable> getJavaScriptClass​(java.lang.Class<?> c)
        Gets the class of the JavaScript object for the node class.
        Parameters:
        c - the node class DomNode or some subclass.
        Returns:
        null if none found
      • getJavaScriptTimeout

        public long getJavaScriptTimeout()
        Returns the javascript timeout.
        Specified by:
        getJavaScriptTimeout in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Returns:
        the javascript timeout
      • setJavaScriptTimeout

        public void setJavaScriptTimeout​(long timeout)
        Sets the javascript timeout.
        Specified by:
        setJavaScriptTimeout in interface AbstractJavaScriptEngine<org.htmlunit.corejs.javascript.Script>
        Parameters:
        timeout - the timeout
      • toNumber

        public static double toNumber​(java.lang.Object value)
        Convert the value to a JavaScript Number value.
        Parameters:
        value - a JavaScript value
        Returns:
        the corresponding double value converted using the ECMA rules
      • toString

        public static java.lang.String toString​(java.lang.Object value)
        Convert the value to a JavaScript String value.
        Parameters:
        value - a JavaScript value
        Returns:
        the corresponding String value converted using the ECMA rules
      • toBoolean

        public static boolean toBoolean​(java.lang.Object value)
        Convert the value to a JavaScript boolean value.
        Parameters:
        value - a JavaScript value
        Returns:
        the corresponding boolean value converted using the ECMA rules
      • throwAsScriptRuntimeEx

        public static java.lang.RuntimeException throwAsScriptRuntimeEx​(java.lang.Throwable e)
        Rethrow the exception wrapping it as the script runtime exception.
        Parameters:
        e - the exception to rethrow
        Returns:
        RuntimeException as dummy the method always throws
      • reportRuntimeError

        public static java.lang.RuntimeException reportRuntimeError​(java.lang.String message)
        Report a runtime error using the error reporter for the current thread.
        Parameters:
        message - the error message to report
        Returns:
        RuntimeException as dummy the method always throws
      • typeError

        public static org.htmlunit.corejs.javascript.EcmaError typeError​(java.lang.String message)
        Report a runtime error using the error reporter for the current thread.
        Parameters:
        message - the error message to report
        Returns:
        EcmaError
      • rangeError

        public static org.htmlunit.corejs.javascript.EcmaError rangeError​(java.lang.String message)
        Report a runtime error using the error reporter for the current thread.
        Parameters:
        message - the error message to report
        Returns:
        EcmaError
      • constructError

        public static org.htmlunit.corejs.javascript.EcmaError constructError​(java.lang.String error,
                                                                              java.lang.String message)
        Parameters:
        error - the error
        message - the message
        Returns:
        a new EcmaError
      • asJavaScriptException

        public static org.htmlunit.corejs.javascript.RhinoException asJavaScriptException​(Window window,
                                                                                          DOMException exception)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Encapsulates the given DOMException into a Rhino-compatible exception.
        Parameters:
        window - the window to be used as parent scope
        exception - the exception to encapsulate
        Returns:
        the created exception
      • newArray

        public static org.htmlunit.corejs.javascript.Scriptable newArray​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                                         int length)
        Create an array with a specified initial length.
        Parameters:
        scope - the scope to create the object in
        length - the initial length (JavaScript arrays may have additional properties added dynamically).
        Returns:
        the new array object
      • newArrayIteratorTypeKeys

        public static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeKeys​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                                                         org.htmlunit.corejs.javascript.Scriptable arrayLike)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.KEYS
        Parameters:
        scope - the scope to create the object in
        arrayLike - the backend
        Returns:
        the new NativeArrayIterator
      • newArrayIteratorTypeValues

        public static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeValues​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                                                           org.htmlunit.corejs.javascript.Scriptable arrayLike)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.VALUES
        Parameters:
        scope - the scope to create the object in
        arrayLike - the backend
        Returns:
        the new NativeArrayIterator
      • newArrayIteratorTypeEntries

        public static org.htmlunit.corejs.javascript.Scriptable newArrayIteratorTypeEntries​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                                                            org.htmlunit.corejs.javascript.Scriptable arrayLike)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Create a new ArrayIterator of type NativeArrayIterator.ARRAY_ITERATOR_TYPE.ENTRIES
        Parameters:
        scope - the scope to create the object in
        arrayLike - the backend
        Returns:
        the new NativeArrayIterator
      • newArray

        public static org.htmlunit.corejs.javascript.Scriptable newArray​(org.htmlunit.corejs.javascript.Scriptable scope,
                                                                         java.lang.Object[] elements)
        Create an array with a specified initial length.
        Parameters:
        scope - the scope to create the object in
        elements - the initial elements. Each object in this array must be an acceptable JavaScript type and type of array should be exactly Object[], not SomeObjectSubclass[].
        Returns:
        the new array object
      • toInt32

        public static int toInt32​(java.lang.Object o)
        Parameters:
        o - the object to convert
        Returns:
        int value
      • toInteger

        public static double toInteger​(java.lang.Object o)
        Parameters:
        o - the object to convert
        Returns:
        double value
      • toInteger

        public static double toInteger​(java.lang.Object[] args,
                                       int index)
        Parameters:
        args - an array
        index - the index in the array
        Returns:
        double value
      • isUndefined

        public static boolean isUndefined​(java.lang.Object obj)
        Parameters:
        obj - the value to check
        Returns:
        whether obj is undefined
      • isNaN

        public static boolean isNaN​(java.lang.Object obj)
        Parameters:
        obj - the value to check
        Returns:
        whether obj is NAN
      • uncompressJavaScript

        public static java.lang.String uncompressJavaScript​(java.lang.String scriptSource,
                                                            java.lang.String scriptName)
        Tries to uncompress the JavaScript code in the provided response.
        Parameters:
        scriptSource - the souce
        scriptName - the name
        Returns:
        the uncompressed JavaScript code
      • evaluateProxyAutoConfig

        public static java.lang.String evaluateProxyAutoConfig​(BrowserVersion browserVersion,
                                                               java.lang.String content,
                                                               java.net.URL url)
        Evaluates the FindProxyForURL method of the specified content.
        Parameters:
        browserVersion - the browser version to use
        content - the JavaScript content
        url - the URL to be retrieved
        Returns:
        semicolon-separated result