Upgrade GWT's htmlunit dependencies.

Review at http://gwt-code-reviews.appspot.com/1590804

Review by: danielwh@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10750 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/build.xml b/dev/build.xml
index 48381ab..7318650 100755
--- a/dev/build.xml
+++ b/dev/build.xml
@@ -90,17 +90,17 @@
           <include name="tomcat/tomcat-jk2-2.1.jar" />
           <include name="tomcat/tomcat-util-5.1.jar" />
           <!-- htmlunit dependencies not already included: BEGIN -->
-          <include name="apache/http/httpclient-4.0.1.jar" />
-          <include name="apache/http/httpcore-4.0.1.jar" />
-          <include name="apache/http/httpmime-4.0.1.jar" />
+          <include name="apache/http/httpclient-4.1.2.jar" />
+          <include name="apache/http/httpcore-4.1.2.jar" />
+          <include name="apache/http/httpmime-4.1.2.jar" />
           <include name="apache/james/apache-mime4j-0.6.jar" />
           <include name="apache/commons/commons-codec-1.3.jar" />
           <include name="apache/commons/commons-io-1.4.jar" />
-          <include name="apache/commons/commons-lang-2.4.jar" />
+          <include name="apache/commons/commons-lang-2.6.jar" />
           <include name="cssparser/cssparser-0.9.5.jar" />
-          <include name="htmlunit/htmlunit-r5940/htmlunit-r5940.jar" />
-          <include name="htmlunit/htmlunit-r5940/htmlunit-core-js-r5940.jar" />
-          <include name="nekohtml/nekohtml-1.9.13.jar" />
+          <include name="htmlunit/htmlunit-2.9/htmlunit-v2.9.jar" />
+          <include name="htmlunit/htmlunit-2.9/htmlunit-core-js-v2.9.jar" />
+          <include name="nekohtml/nekohtml-1.9.15.jar" />
           <include name="streamhtmlparser/streamhtmlparser-jsilver-r10/streamhtmlparser-jsilver-r10-1.5-rebased.jar" />
           <include name="cup/java-cup-11a.jar" />
           <include name="xalan/xalan-2.7.1-nocup.jar" />
@@ -155,17 +155,17 @@
           <zipfileset src="${gwt.tools.lib}/tomcat/tomcat-jk2-2.1.jar" />
           <zipfileset src="${gwt.tools.lib}/tomcat/tomcat-util-5.1.jar" />
           <!-- htmlunit dependencies not already included: BEGIN -->
-          <zipfileset src="${gwt.tools.lib}/apache/http/httpclient-4.0.1.jar" />
-          <zipfileset src="${gwt.tools.lib}/apache/http/httpcore-4.0.1.jar" />
-          <zipfileset src="${gwt.tools.lib}/apache/http/httpmime-4.0.1.jar" />
+          <zipfileset src="${gwt.tools.lib}/apache/http/httpclient-4.1.2.jar" />
+          <zipfileset src="${gwt.tools.lib}/apache/http/httpcore-4.1.2.jar" />
+          <zipfileset src="${gwt.tools.lib}/apache/http/httpmime-4.1.2.jar" />
           <zipfileset src="${gwt.tools.lib}/apache/james/apache-mime4j-0.6.jar" />
           <zipfileset src="${gwt.tools.lib}/apache/commons/commons-codec-1.3.jar" />
           <zipfileset src="${gwt.tools.lib}/apache/commons/commons-io-1.4.jar" />
-          <zipfileset src="${gwt.tools.lib}/apache/commons/commons-lang-2.4.jar" />
+          <zipfileset src="${gwt.tools.lib}/apache/commons/commons-lang-2.6.jar" />
           <zipfileset src="${gwt.tools.lib}/cssparser/cssparser-0.9.5.jar" />
-          <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-r5940/htmlunit-r5940.jar" />
-          <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940.jar" />
-          <zipfileset src="${gwt.tools.lib}/nekohtml/nekohtml-1.9.13.jar" />
+          <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-2.9/htmlunit-2.9.jar" />
+          <zipfileset src="${gwt.tools.lib}/htmlunit/htmlunit-2.9/htmlunit-core-js-2.9.jar" />
+          <zipfileset src="${gwt.tools.lib}/nekohtml/nekohtml-1.9.15.jar" />
           <zipfileset src="${gwt.tools.lib}/cup/java-cup-11a.jar" />
           <zipfileset src="${gwt.tools.lib}/xalan/xalan-2.7.1-nocup.jar" />
           <zipfileset src="${gwt.tools.lib}/xerces/xerces-2_9_1/serializer.jar" />
diff --git a/dev/core/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java b/dev/core/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java
index b40d6d8..024b659 100644
--- a/dev/core/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java
+++ b/dev/core/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java
@@ -23,6 +23,7 @@
 import com.google.gwt.dev.shell.BrowserChannelClient.SessionHandlerClient;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
 
+import com.gargoylesoftware.htmlunit.ScriptException;
 import com.gargoylesoftware.htmlunit.ScriptResult;
 import com.gargoylesoftware.htmlunit.WebWindow;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
@@ -220,15 +221,26 @@
           } while (webWindow != webWindow.getTopWindow());
         }
       }
-      result = jsEngine.callFunction(htmlPage, jsFunction, jsContext, window,
+      result = jsEngine.callFunction(htmlPage, jsFunction, window,
           jsThis, jsArgs);     
-    } catch (JavaScriptException ex) {
-      if (logger.isLoggable(TreeLogger.INFO)) {
-        logger.log(TreeLogger.INFO, "INVOKE: JavaScriptException " + ex
-            + ", message: " + ex.getMessage() + " when invoking " + methodName);
+    } catch (ScriptException se) {
+      if (se.getCause() instanceof JavaScriptException) {
+        JavaScriptException ex = (JavaScriptException) se.getCause();
+        if (logger.isLoggable(TreeLogger.INFO)) {
+          logger.log(TreeLogger.INFO, "INVOKE: JavaScriptException " + ex
+              + ", message: " + ex.getMessage() + " when invoking "
+              + methodName);
+        }
+        return new ExceptionOrReturnValue(true, makeValueFromJsval(jsContext,
+            ex.getValue()));
+      } else {
+        if (logger.isLoggable(TreeLogger.INFO)) {
+          logger.log(TreeLogger.INFO, "INVOKE: exception " + se + ", message: "
+            + se.getMessage() + " when invoking " + methodName);
+        }
+        return new ExceptionOrReturnValue(true, makeValueFromJsval(jsContext,
+          Undefined.instance));
       }
-      return new ExceptionOrReturnValue(true, makeValueFromJsval(jsContext,
-          ex.getValue()));
     } catch (Exception ex) {
       if (logger.isLoggable(TreeLogger.INFO)) {
         logger.log(TreeLogger.INFO, "INVOKE: exception " + ex + ", message: "
diff --git a/eclipse/dev/.classpath b/eclipse/dev/.classpath
index cb797481..63c6c07 100644
--- a/eclipse/dev/.classpath
+++ b/eclipse/dev/.classpath
@@ -37,8 +37,8 @@
 	<classpathentry kind="var" path="GWT_TOOLS/lib/tomcat/tomcat-jk2-2.1.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/tomcat/tomcat-util-5.1.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/sun/swingworker/swing-worker-1.1.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940-sources.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940-sources.jar"/>
+        <classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-core-js-2.9.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-core-js-2.9-sources.jar"/>
+        <classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-2.9.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-2.9-sources.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/protobuf/protobuf-2.2.0/protobuf-java-rebased-2.2.0.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/guava/guava-r06/guava-r06-rebased.jar"/>
 	<classpathentry kind="output" path="bin"/>
diff --git a/eclipse/user/.classpath b/eclipse/user/.classpath
index eff0d1c..140687d 100644
--- a/eclipse/user/.classpath
+++ b/eclipse/user/.classpath
@@ -9,17 +9,17 @@
 	<classpathentry exported="true" kind="var" path="GWT_TOOLS/lib/apache/tapestry-util-text-4.0.2.jar" sourcepath="/GWT_TOOLS/lib/apache/tapestry-util-text-4.0.2-src.zip"/>
 	<classpathentry exported="true" kind="var" path="GWT_TOOLS/lib/junit/junit-4.8.2.jar" sourcepath="/GWT_TOOLS/lib/junit/junit-4.8.2-src.jar"/>
 	<classpathentry exported="true" kind="var" path="GWT_TOOLS/lib/tomcat/servlet-api-2.5.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpclient-4.0.1.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpcore-4.0.1.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpmime-4.0.1.jar"/>
+	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpclient-4.1.2.jar"/>
+	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpcore-4.1.2.jar"/>
+	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/http/httpmime-4.1.2.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/james/apache-mime4j-0.6.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/commons/commons-codec-1.3.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/tomcat/commons-collections-3.1.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/commons/commons-lang-2.4.jar"/>
+	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/commons/commons-lang-2.6.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/tomcat/commons-logging-1.0.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/apache/commons/commons-io-1.4.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/cssparser/cssparser-0.9.5.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/nekohtml/nekohtml-1.9.13.jar"/>
+	<classpathentry kind="var" path="GWT_TOOLS/lib/nekohtml/nekohtml-1.9.15.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/selenium/selenium-java-client-driver.jar" sourcepath="/GWT_TOOLS/lib/selenium/selenium-java-client-driver-sources.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/cup/java-cup-11a.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/xalan/xalan-2.7.1-nocup.jar"/>
@@ -33,8 +33,8 @@
 	<classpathentry kind="var" path="GWT_TOOLS/lib/easymock/easymock-3.0.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/lib/objectweb/asm-3.1.jar"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/gwt-dev"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-r5940-sources.jar"/>
-	<classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-r5940/htmlunit-core-js-r5940-sources.jar"/>
+        <classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-2.9.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-2.9-sources.jar"/>
+        <classpathentry kind="var" path="GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-core-js-2.9.jar" sourcepath="/GWT_TOOLS/lib/htmlunit/htmlunit-2.9/htmlunit-core-js-2.9-sources.jar"/>
 	<classpathentry kind="var" path="GWT_TOOLS/redist/json/r2_20080312/json-1.5.jar" sourcepath="/GWT_TOOLS/redist/json/r2_20080312/json-src.jar"/>
 	<classpathentry exported="true" kind="var" path="GWT_TOOLS/lib/javax/validation/validation-api-1.0.0.GA.jar" sourcepath="/GWT_TOOLS/lib/javax/validation/validation-api-1.0.0.GA-sources.jar"/>
 	<classpathentry exported="true" kind="var" path="GWT_TOOLS/lib/javax/validation/validation-api-1.0.0.GA-sources.jar"/>
diff --git a/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java b/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
index f4eaed2..2c18533 100644
--- a/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
+++ b/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java
@@ -25,10 +25,12 @@
 import com.gargoylesoftware.htmlunit.IncorrectnessListener;
 import com.gargoylesoftware.htmlunit.OnbeforeunloadHandler;
 import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.ScriptException;
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.WebWindow;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import com.gargoylesoftware.htmlunit.javascript.JavaScriptErrorListener;
 import com.gargoylesoftware.htmlunit.javascript.host.Window;
 
 import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject;
@@ -38,6 +40,7 @@
 
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -118,6 +121,37 @@
       webClient.setThrowExceptionOnFailingStatusCode(false);
       webClient.setThrowExceptionOnScriptError(true);
       webClient.setOnbeforeunloadHandler(this);
+      webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {
+
+        @Override
+        public void loadScriptError(HtmlPage htmlPage, URL scriptUrl,
+            Exception exception) {
+            treeLogger.log(TreeLogger.ERROR,
+              "Load Script Error: " + exception, exception);
+        }
+
+        @Override
+        public void malformedScriptURL(HtmlPage htmlPage, String url,
+            MalformedURLException malformedURLException) {
+          treeLogger.log(TreeLogger.ERROR,
+              "Malformed Script URL: " + malformedURLException.getLocalizedMessage());
+        }
+
+        @Override
+        public void scriptException(HtmlPage htmlPage,
+            ScriptException scriptException) {
+          treeLogger.log(TreeLogger.DEBUG,
+              "Script Exception: " + scriptException.getLocalizedMessage() +
+               ", line " + scriptException.getFailingLine());
+        }
+
+        @Override
+        public void timeoutError(HtmlPage htmlPage, long allowedTime,
+            long executionTime) {
+          treeLogger.log(TreeLogger.ERROR,
+              "Script Timeout Error " + executionTime + " > " + allowedTime);
+        }
+      });
       setupWebClient(webClient);
       try {
         Page page = webClient.getPage(url);