Update user code to use $entry.

Patch by: bobv
Review by: jgw

http://gwt-code-reviews.appspot.com/77813

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@6401 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/http/client/Request.java b/user/src/com/google/gwt/http/client/Request.java
index 70c13c4..212b13f 100644
--- a/user/src/com/google/gwt/http/client/Request.java
+++ b/user/src/com/google/gwt/http/client/Request.java
@@ -15,8 +15,6 @@
  */
 package com.google.gwt.http.client;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.xhr.client.XMLHttpRequest;
 
@@ -148,7 +146,7 @@
    * and set this field to null.
    */
   private XMLHttpRequest xmlHttpRequest;
-  
+
   /**
    * Only used for building a
    * {@link com.google.gwt.user.client.rpc.impl.FailedRequest}.
@@ -265,33 +263,6 @@
    * reaches 4 (LOADED).
    */
   void fireOnResponseReceived(RequestCallback callback) {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireOnResponseReceivedAndCatch(handler, callback);
-    } else {
-      fireOnResponseReceivedImpl(callback);
-    }
-  }
-
-  /*
-   * Stops the current HTTPRequest timer if there is one.
-   */
-  private void cancelTimer() {
-    if (timer != null) {
-      timer.cancel();
-    }
-  }
-
-  private void fireOnResponseReceivedAndCatch(UncaughtExceptionHandler handler,
-      RequestCallback callback) {
-    try {
-      fireOnResponseReceivedImpl(callback);
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
-  private void fireOnResponseReceivedImpl(RequestCallback callback) {
     if (xmlHttpRequest == null) {
       // the request has timed out at this point
       return;
@@ -318,6 +289,15 @@
   }
 
   /*
+   * Stops the current HTTPRequest timer if there is one.
+   */
+  private void cancelTimer() {
+    if (timer != null) {
+      timer.cancel();
+    }
+  }
+
+  /*
    * Method called when this request times out.
    * 
    * NOTE: this method is called from JSNI
@@ -340,22 +320,20 @@
    * <ol>
    * <li>On Mozilla, after a network error, attempting to read the status code
    * results in an exception being thrown. See <a
-   * href="https://bugzilla.mozilla.org/show_bug.cgi?id=238559">https://bugzilla.mozilla.org/show_bug.cgi?id=238559</a>.
-   * </li>
-   * <li>On Safari, if the HTTP response does not include any response text.
-   * See <a
-   * href="http://bugs.webkit.org/show_bug.cgi?id=3810">http://bugs.webkit.org/show_bug.cgi?id=3810</a>.
-   * </li>
+   * href="https://bugzilla.mozilla.org/show_bug.cgi?id=238559"
+   * >https://bugzilla.mozilla.org/show_bug.cgi?id=238559</a>.</li>
+   * <li>On Safari, if the HTTP response does not include any response text. See
+   * <a
+   * href="http://bugs.webkit.org/show_bug.cgi?id=3810">http://bugs.webkit.org
+   * /show_bug.cgi?id=3810</a>.</li>
    * </ol>
    * 
-   * @param xhr the JavaScript <code>XmlHttpRequest</code> object
-   *          to test
+   * @param xhr the JavaScript <code>XmlHttpRequest</code> object to test
    * @return a String message containing an error message if the
    *         <code>XmlHttpRequest.status</code> code is unreadable or null if
    *         the status code could be successfully read.
    */
-  private native String getBrowserSpecificFailure(
-      XMLHttpRequest xhr) /*-{
+  private native String getBrowserSpecificFailure(XMLHttpRequest xhr) /*-{
     try {
       if (xhr.status === undefined) {
         return "XmlHttpRequest.status == undefined, please see Safari bug " +
diff --git a/user/src/com/google/gwt/jsonp/client/JsonpRequest.java b/user/src/com/google/gwt/jsonp/client/JsonpRequest.java
index 97f2713..ad8d5d4 100644
--- a/user/src/com/google/gwt/jsonp/client/JsonpRequest.java
+++ b/user/src/com/google/gwt/jsonp/client/JsonpRequest.java
@@ -191,7 +191,7 @@
     var self = this;
     var callback = new Object();
     callbacks[this.@com.google.gwt.jsonp.client.JsonpRequest::callbackId] = callback;
-    callback.onSuccess = function(data) {
+    callback.onSuccess = $entry(function(data) {
       // Box primitive types
       if (typeof data == 'boolean') {
         data = @java.lang.Boolean::new(Z)(data);
@@ -203,11 +203,11 @@
         }
       }
       self.@com.google.gwt.jsonp.client.JsonpRequest::onSuccess(Ljava/lang/Object;)(data);
-    };
+    });
     if (this.@com.google.gwt.jsonp.client.JsonpRequest::failureCallbackParam) {
-      callback.onFailure = function(message) {
+      callback.onFailure = $entry(function(message) {
         self.@com.google.gwt.jsonp.client.JsonpRequest::onFailure(Ljava/lang/String;)(message);
-      };
+      });
     }
   }-*/;
 
diff --git a/user/src/com/google/gwt/layout/client/LayoutImplIE6.java b/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
index c99b324..53f6287 100644
--- a/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
+++ b/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
@@ -242,6 +242,10 @@
     resize();
   }-*/;
 
+  /**
+   * This does not call $entry() because no user code is reachable from
+   * resizeHandler.
+   */
   private native void initResizeHandler(Element parent) /*-{
     // Potential leak: This is cleaned up in detach().
     var self = this;
@@ -250,6 +254,10 @@
     };
   }-*/;
 
+  /**
+   * This does not call $entry() because no user code is reachable from
+   * resizeHandler.
+   */
   private native void initUnitChangeHandler(Element parent, Element ruler) /*-{
     // Potential leak: This is cleaned up in detach().
     var self = this;
diff --git a/user/src/com/google/gwt/user/client/AsyncProxy.java b/user/src/com/google/gwt/user/client/AsyncProxy.java
index 908235d..91c7bad 100644
--- a/user/src/com/google/gwt/user/client/AsyncProxy.java
+++ b/user/src/com/google/gwt/user/client/AsyncProxy.java
@@ -178,7 +178,9 @@
      * Invokes the global uncaught exception handler.
      */
     public void onFailure(Throwable t) {
-      GWT.getUncaughtExceptionHandler().onUncaughtException(t);
+      if (GWT.getUncaughtExceptionHandler() != null) {
+        GWT.getUncaughtExceptionHandler().onUncaughtException(t);
+      }
     }
 
     /**
diff --git a/user/src/com/google/gwt/user/client/DOM.java b/user/src/com/google/gwt/user/client/DOM.java
index 7ef6973..7cc2660 100644
--- a/user/src/com/google/gwt/user/client/DOM.java
+++ b/user/src/com/google/gwt/user/client/DOM.java
@@ -16,7 +16,6 @@
 package com.google.gwt.user.client;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.ImageElement;
 import com.google.gwt.dom.client.OptionElement;
@@ -1261,12 +1260,7 @@
     Event prevCurrentEvent = currentEvent;
     currentEvent = evt;
 
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      dispatchEventAndCatch(evt, elem, listener, handler);
-    } else {
-      dispatchEventImpl(evt, elem, listener);
-    }
+    dispatchEventImpl(evt, elem, listener);
 
     currentEvent = prevCurrentEvent;
   }
@@ -1299,15 +1293,6 @@
     return ret;
   }
 
-  private static void dispatchEventAndCatch(Event evt, Element elem,
-      EventListener listener, UncaughtExceptionHandler handler) {
-    try {
-      dispatchEventImpl(evt, elem, listener);
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
   private static void dispatchEventImpl(Event evt, Element elem,
       EventListener listener) {
     // If this element has capture...
diff --git a/user/src/com/google/gwt/user/client/HTTPRequest.java b/user/src/com/google/gwt/user/client/HTTPRequest.java
index 50acb62..c947321 100644
--- a/user/src/com/google/gwt/user/client/HTTPRequest.java
+++ b/user/src/com/google/gwt/user/client/HTTPRequest.java
@@ -84,14 +84,14 @@
     try {
       xmlHttp.open("GET", url, true);
       xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
-      xmlHttp.onreadystatechange = function() {
+      xmlHttp.onreadystatechange = $entry(function() {
         if (xmlHttp.readyState == 4) {
           $wnd.setTimeout(function() {
             xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
           }, 0);
           handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
         }
-      };
+      });
       xmlHttp.send('');
       return true;
     } catch (e) {
@@ -106,14 +106,14 @@
     try {
       xmlHttp.open("POST", url, true);
       xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
-      xmlHttp.onreadystatechange = function() {
+      xmlHttp.onreadystatechange = $entry(function() {
         if (xmlHttp.readyState == 4) {
           $wnd.setTimeout(function() {
             xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
           }, 0);
           handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
         }
-      };
+      });
       xmlHttp.send(postData);
       return true;
     }
diff --git a/user/src/com/google/gwt/user/client/Timer.java b/user/src/com/google/gwt/user/client/Timer.java
index dadf6c8..d75e2a6 100644
--- a/user/src/com/google/gwt/user/client/Timer.java
+++ b/user/src/com/google/gwt/user/client/Timer.java
@@ -15,8 +15,6 @@
  */
 package com.google.gwt.user.client;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.event.logical.shared.CloseEvent;
 import com.google.gwt.event.logical.shared.CloseHandler;
 
@@ -53,13 +51,13 @@
 
   private static native int createInterval(Timer timer, int period) /*-{
     return $wnd.setInterval(
-      function() { timer.@com.google.gwt.user.client.Timer::fire()(); },
+      $entry(function() { timer.@com.google.gwt.user.client.Timer::fire()(); }),
       period);
   }-*/;
 
   private static native int createTimeout(Timer timer, int delay) /*-{
     return $wnd.setTimeout(
-      function() { timer.@com.google.gwt.user.client.Timer::fire()(); },
+      $entry(function() { timer.@com.google.gwt.user.client.Timer::fire()(); }),
       delay);
   }-*/;
 
@@ -133,23 +131,6 @@
    * Called by native code when this timer fires.
    */
   final void fire() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireAndCatch(handler);
-    } else {
-      fireImpl();
-    }
-  }
-
-  private void fireAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      fireImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
-  private void fireImpl() {
     // If this is a one-shot timer, remove it from the timer list. This will
     // allow it to be garbage collected.
     if (!isRepeating) {
diff --git a/user/src/com/google/gwt/user/client/Window.java b/user/src/com/google/gwt/user/client/Window.java
index 022d1ff..09c2fdb 100644
--- a/user/src/com/google/gwt/user/client/Window.java
+++ b/user/src/com/google/gwt/user/client/Window.java
@@ -16,7 +16,6 @@
 package com.google.gwt.user.client;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.event.logical.shared.CloseEvent;
 import com.google.gwt.event.logical.shared.CloseHandler;
@@ -705,38 +704,37 @@
   }-*/;
 
   static void onClosed() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireClosedAndCatch(handler);
-    } else {
-      fireClosedImpl();
+    if (closeHandlersInitialized) {
+      CloseEvent.fire(getHandlers(), null);
     }
   }
 
   static String onClosing() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      return fireClosingAndCatch(handler);
-    } else {
-      return fireClosingImpl();
+    if (closeHandlersInitialized) {
+      Window.ClosingEvent event = new Window.ClosingEvent();
+      fireEvent(event);
+      return event.getMessage();
     }
+    return null;
   }
 
   static void onResize() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireResizedAndCatch(handler);
-    } else {
-      fireResizedImpl();
+    if (resizeHandlersInitialized) {
+      // On webkit and IE we sometimes get duplicate window resize events.
+      // Here, we manually filter them.
+      int width = getClientWidth();
+      int height = getClientHeight();
+      if (lastResizeWidth != width || lastResizeHeight != height) {
+        lastResizeWidth = width;
+        lastResizeHeight = height;
+        ResizeEvent.fire(getHandlers(), width, height);
+      }
     }
   }
 
   static void onScroll() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireScrollAndCatch(handler);
-    } else {
-      fireScrollImpl();
+    if (scrollHandlersInitialized) {
+      fireEvent(new Window.ScrollEvent(getScrollLeft(), getScrollTop()));
     }
   }
 
@@ -753,38 +751,6 @@
     return getHandlers().addHandler(type, handler);
   }
 
-  private static void fireClosedAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      fireClosedImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
-  private static void fireClosedImpl() {
-    if (closeHandlersInitialized) {
-      CloseEvent.fire(getHandlers(), null);
-    }
-  }
-
-  private static String fireClosingAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      return fireClosingImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-      return null;
-    }
-  }
-
-  private static String fireClosingImpl() {
-    if (closeHandlersInitialized) {
-      Window.ClosingEvent event = new Window.ClosingEvent();
-      fireEvent(event);
-      return event.getMessage();
-    }
-    return null;
-  }
-
   /**
    * Fires an event.
    * 
@@ -796,42 +762,6 @@
     }
   }
 
-  private static void fireResizedAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      fireResizedImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
-  private static void fireResizedImpl() {
-    if (resizeHandlersInitialized) {
-      // On webkit and IE we sometimes get duplicate window resize events.
-      // Here, we manually filter them.
-      int width = getClientWidth();
-      int height = getClientHeight();
-      if (lastResizeWidth != width || lastResizeHeight != height) {
-        lastResizeWidth = width;
-        lastResizeHeight = height;
-        ResizeEvent.fire(getHandlers(), width, height);
-      }
-    }
-  }
-
-  private static void fireScrollAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      fireScrollImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
-  private static void fireScrollImpl() {
-    if (scrollHandlersInitialized) {
-      fireEvent(new Window.ScrollEvent(getScrollLeft(), getScrollTop()));
-    }
-  }
-
   private static WindowHandlers getHandlers() {
     if (handlers == null) {
       handlers = new WindowHandlers();
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java b/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
index a647aa1..44b9cfd 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplMozilla.java
@@ -43,7 +43,7 @@
   private native void initSyntheticMouseUpEvents() /*-{
     $wnd.addEventListener(
       'mouseout',
-      function(evt) {
+      $entry(function(evt) {
         var cap = $wnd.__captureElem;
         if (cap && !evt.relatedTarget) {
           // Mozilla has the interesting habit of sending a mouseout event
@@ -59,7 +59,7 @@
             cap.dispatchEvent(muEvent);
           }
         }
-      },
+      }),
       true
     );
 
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java b/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
index 49d8931..4160aab 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
@@ -143,7 +143,7 @@
 
   @Override
   protected native void initEventSystem() /*-{
-    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedMouseEvent = function(evt) {
+    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedMouseEvent = $entry(function(evt) {
       if ((@com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedEvent)(evt)) {
         var cap = @com.google.gwt.user.client.impl.DOMImplStandard::captureElem;
         if (cap && cap.__listener) {
@@ -153,9 +153,9 @@
           }
         }
       }  
-    };
+    });
 
-    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedEvent = function(evt) {
+    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedEvent = $entry(function(evt) {
       if (!@com.google.gwt.user.client.DOM::previewEvent(Lcom/google/gwt/user/client/Event;)(evt)) {
         evt.stopPropagation();
         evt.preventDefault();
@@ -163,9 +163,9 @@
       }
 
       return true;
-    };
+    });
 
-    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent = function(evt) {
+    @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent = $entry(function(evt) {
       var listener, curElem = this;
       while (curElem && !(listener = curElem.__listener)) {
         curElem = curElem.parentNode;
@@ -180,7 +180,7 @@
           @com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, curElem, listener);
         }
       }
-    };
+    });
 
     $wnd.addEventListener('click', @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedMouseEvent, true);
     $wnd.addEventListener('dblclick', @com.google.gwt.user.client.impl.DOMImplStandard::dispatchCapturedMouseEvent, true);
diff --git a/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java b/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java
index af01b54..19ea536 100644
--- a/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java
+++ b/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java
@@ -99,11 +99,11 @@
     if ($wnd.__gwt_globalEventArray == null) {
       $wnd.__gwt_globalEventArray = new Array();
     }
-    $wnd.__gwt_globalEventArray[$wnd.__gwt_globalEventArray.length] = function() {
+    $wnd.__gwt_globalEventArray[$wnd.__gwt_globalEventArray.length] = $entry(function() {
       return @com.google.gwt.user.client.DOM::previewEvent(Lcom/google/gwt/user/client/Event;)($wnd.event);
-    }
+    });
 
-    @com.google.gwt.user.client.impl.DOMImplTrident::dispatchEvent = function() {
+    @com.google.gwt.user.client.impl.DOMImplTrident::dispatchEvent = $entry(function() {
       // IE doesn't define event.currentTarget, so we squirrel it away here. It
       // also seems that IE won't allow you to add expandos to the event object,
       // so we have to store it in a global. This is ok because only one event
@@ -134,9 +134,9 @@
       }
 
       @com.google.gwt.dom.client.DOMImplTrident::currentEventTarget = oldEventTarget;
-    };
+    });
 
-    @com.google.gwt.user.client.impl.DOMImplTrident::dispatchDblClickEvent = function() {
+    @com.google.gwt.user.client.impl.DOMImplTrident::dispatchDblClickEvent = $entry(function() {
       var newEvent = $doc.createEventObject();
       // Synthesize a click event if one hasn't already been synthesized.
       if ($wnd.event.returnValue == null) {
@@ -149,13 +149,13 @@
         $wnd.event.returnValue = true;
         @com.google.gwt.user.client.impl.DOMImplTrident::previewEventImpl()();
       }
-    };
+    });
 
     // We need to create these delegate functions to fix up the 'this' context.
     // Normally, 'this' is the firing element, but this is only true for
     // 'onclick = ...' event handlers, not for handlers setup via attachEvent().
-    var bodyDispatcher = function() { @com.google.gwt.user.client.impl.DOMImplTrident::dispatchEvent.call($doc.body); };
-    var bodyDblClickDispatcher = function() { @com.google.gwt.user.client.impl.DOMImplTrident::dispatchDblClickEvent.call($doc.body); };
+    var bodyDispatcher = $entry(function() { @com.google.gwt.user.client.impl.DOMImplTrident::dispatchEvent.call($doc.body); });
+    var bodyDblClickDispatcher = $entry(function() { @com.google.gwt.user.client.impl.DOMImplTrident::dispatchDblClickEvent.call($doc.body); });
 
     $doc.body.attachEvent('onclick', bodyDispatcher);
     $doc.body.attachEvent('onmousedown', bodyDispatcher);
diff --git a/user/src/com/google/gwt/user/client/impl/HTTPRequestImpl.java b/user/src/com/google/gwt/user/client/impl/HTTPRequestImpl.java
index 46c1cbd..aa01fb6 100644
--- a/user/src/com/google/gwt/user/client/impl/HTTPRequestImpl.java
+++ b/user/src/com/google/gwt/user/client/impl/HTTPRequestImpl.java
@@ -68,14 +68,14 @@
     try {
       xmlHttp.open("GET", url, true);
       xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
-      xmlHttp.onreadystatechange = function() {
+      xmlHttp.onreadystatechange = $entry(function() {
         if (xmlHttp.readyState == 4) {
-          $wnd.setTimeout(function() {
+          $wnd.setTimeout($entry(function() {
             xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
-          }, 0);
+          }), 0);
           handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
         }
-      };
+      });
       xmlHttp.send('');
       return true;
     } catch (e) {
@@ -90,14 +90,14 @@
     try {
       xmlHttp.open("POST", url, true);
       xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
-      xmlHttp.onreadystatechange = function() {
+      xmlHttp.onreadystatechange = $entry(function() {
         if (xmlHttp.readyState == 4) {
-          $wnd.setTimeout(function() {
+          $wnd.setTimeout($entry(function() {
             xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
-          }, 0);
+          }), 0);
           handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
         }
-      };
+      });
       xmlHttp.send(postData);
       return true;
     }
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImpl.java b/user/src/com/google/gwt/user/client/impl/HistoryImpl.java
index 4aa6ac9..bf3461a 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImpl.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImpl.java
@@ -15,8 +15,6 @@
  */
 package com.google.gwt.user.client.impl;
 
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
@@ -27,16 +25,15 @@
 
 /**
  * Native implementation associated with
- * {@link com.google.gwt.user.client.History}.
- * User classes should not use this class directly.
+ * {@link com.google.gwt.user.client.History}. User classes should not use this
+ * class directly.
  * 
  * <p>
  * This base version uses the HTML5 standard window.onhashchange event to
  * determine when the URL hash identifier changes.
  * </p>
  */
-public class HistoryImpl implements HasValueChangeHandlers<String>,
-    HasHandlers {
+public class HistoryImpl implements HasValueChangeHandlers<String>, HasHandlers {
 
   public static native String getToken() /*-{
     return $wnd.__gwt_historyToken || "";
@@ -45,11 +42,11 @@
   /**
    * Sets whether the IE6 history implementation will update the URL hash when
    * creating a new item. This should be used only for applications with large
-   * DOM structures that are suffering from performance problems when creating
-   * a new history item on IE6 and 7.
-   *
+   * DOM structures that are suffering from performance problems when creating a
+   * new history item on IE6 and 7.
+   * 
    * @deprecated This is no longer necessary, as the underlying performance
-   * problem has been solved. It is now a no-op.
+   *             problem has been solved. It is now a no-op.
    */
   @Deprecated
   public static void setUpdateHashOnIE6(boolean updateHash) {
@@ -99,14 +96,14 @@
     @com.google.gwt.user.client.impl.HistoryImpl::setToken(Ljava/lang/String;)(token);
 
     var historyImpl = this;
-    $wnd.onhashchange = function() {
+    $wnd.onhashchange = $entry(function() {
       var token = '', hash = $wnd.location.hash;
       if (hash.length > 0) {
         token = historyImpl.@com.google.gwt.user.client.impl.HistoryImpl::decodeFragment(Ljava/lang/String;)(hash.substring(1));
       }
 
       historyImpl.@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
-    };
+    });
 
     return true;
   }-*/;
@@ -127,7 +124,7 @@
     if (!historyToken.equals(getToken())) {
       setToken(historyToken);
       nativeUpdateOnEvent(historyToken);
-      fireHistoryChanged(historyToken);
+      fireHistoryChangedImpl(historyToken);
     }
   }
 
@@ -152,22 +149,4 @@
   protected void nativeUpdateOnEvent(String historyToken) {
     // Do nothing, the hash is already updated.
   }
-
-  private void fireHistoryChanged(String newToken) {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      fireHistoryChangedAndCatch(newToken, handler);
-    } else {
-      fireHistoryChangedImpl(newToken);
-    }
-  }
-
-  private void fireHistoryChangedAndCatch(String newToken,
-      UncaughtExceptionHandler handler) {
-    try {
-      fireHistoryChangedImpl(newToken);
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
 }
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java b/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
index 0d73ba5..e0b7f1e 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImplIE6.java
@@ -148,7 +148,7 @@
     // nasty bug that totally mangles its history stack and causes the location
     // bar in the UI to stop working under these circumstances.
     var historyImplRef = this;
-    var urlChecker = function() {
+    var urlChecker = $entry(function() {
       $wnd.setTimeout(urlChecker, 250);
 
       // Reset the hash if the user cancels a window reload triggered by the 
@@ -173,16 +173,16 @@
           historyImplRef.@com.google.gwt.user.client.impl.HistoryImplIE6::reloadWindow()();
         }
       }
-    };
+    });
     urlChecker();
   }-*/;
 
   private native void injectGlobalHandler() /*-{
     var historyImplRef = this;
 
-    $wnd.__gwt_onHistoryLoad = function(token) {
+    $wnd.__gwt_onHistoryLoad = $entry(function(token) {
       historyImplRef.@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
-    };
+    });
   }-*/;
 
   private native void navigateFrame(String token) /*-{
diff --git a/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java b/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
index 825fecd..f5002b5 100644
--- a/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
+++ b/user/src/com/google/gwt/user/client/impl/HistoryImplTimer.java
@@ -35,7 +35,7 @@
 
     // Create the timer that checks the browser's url hash every 1/4 s.
     var historyImpl = this;
-    $wnd.__checkHistory = function() {
+    $wnd.__checkHistory = $entry(function() {
       $wnd.setTimeout($wnd.__checkHistory, 250);
 
       var token = '', hash = $wnd.location.hash;
@@ -44,7 +44,7 @@
       }
 
       historyImpl.@com.google.gwt.user.client.impl.HistoryImpl::newItemOnEvent(Ljava/lang/String;)(token);
-    };
+    });
 
     // Kick off the timer.
     $wnd.__checkHistory();
diff --git a/user/src/com/google/gwt/user/client/impl/WindowImpl.java b/user/src/com/google/gwt/user/client/impl/WindowImpl.java
index 3be39bc..71e625e 100644
--- a/user/src/com/google/gwt/user/client/impl/WindowImpl.java
+++ b/user/src/com/google/gwt/user/client/impl/WindowImpl.java
@@ -33,10 +33,14 @@
     var oldOnBeforeUnload = $wnd.onbeforeunload;
     var oldOnUnload = $wnd.onunload;
     
+    // Old mozilla doesn't like $entry's explicit return statement and
+    // will always pop up a confirmation dialog.  This is worked around by
+    // just wrapping the call to onClosing(), which still has the semantics
+    // that we want.
     $wnd.onbeforeunload = function(evt) {
       var ret, oldRet;
       try {
-        ret = @com.google.gwt.user.client.Window::onClosing()();
+        ret = $entry(@com.google.gwt.user.client.Window::onClosing())();
       } finally {
         oldRet = oldOnBeforeUnload && oldOnBeforeUnload(evt);
       }
@@ -51,7 +55,7 @@
       // returns undefined.
     };
     
-    $wnd.onunload = function(evt) {
+    $wnd.onunload = $entry(function(evt) {
       try {
         @com.google.gwt.user.client.Window::onClosed()();
       } finally {
@@ -61,28 +65,28 @@
         $wnd.onbeforeunload = null;
         $wnd.onunload = null;
       }
-    };
+    });
   }-*/;
 
   public native void initWindowResizeHandler() /*-{
     var oldOnResize = $wnd.onresize;
-    $wnd.onresize = function(evt) {
+    $wnd.onresize = $entry(function(evt) {
       try {
         @com.google.gwt.user.client.Window::onResize()();
       } finally {
         oldOnResize && oldOnResize(evt);
       }
-    };
+    });
   }-*/;
 
   public native void initWindowScrollHandler() /*-{
     var oldOnScroll = $wnd.onscroll;
-    $wnd.onscroll = function(evt) {
+    $wnd.onscroll = $entry(function(evt) {
       try {
         @com.google.gwt.user.client.Window::onScroll()();
       } finally {
         oldOnScroll && oldOnScroll(evt);
       }
-    };
+    });
   }-*/;
 }
diff --git a/user/src/com/google/gwt/user/client/impl/WindowImplIE.java b/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
index 386aa35..447028e 100644
--- a/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
+++ b/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
@@ -133,28 +133,20 @@
 
   private native void initWindowCloseHandlerImpl() /*-{
     $wnd.__gwt_initWindowCloseHandler(
-      function() {
-        return @com.google.gwt.user.client.Window::onClosing()();
-      },
-      function() {
-        @com.google.gwt.user.client.Window::onClosed()();
-      }
+      $entry(@com.google.gwt.user.client.Window::onClosing()),
+      $entry(@com.google.gwt.user.client.Window::onClosed())
     );
   }-*/;
 
   private native void initWindowResizeHandlerImpl() /*-{
     $wnd.__gwt_initWindowResizeHandler(
-      function() {
-        @com.google.gwt.user.client.Window::onResize()();
-      }
+      $entry(@com.google.gwt.user.client.Window::onResize())
     );
   }-*/;
 
   private native void initWindowScrollHandlerImpl() /*-{
     $wnd.__gwt_initWindowScrollHandler(
-      function() {
-        @com.google.gwt.user.client.Window::onScroll()();
-      }
+      $entry(@com.google.gwt.user.client.Window::onScroll())
     );
   }-*/;
 
diff --git a/user/src/com/google/gwt/user/client/ui/FormPanel.java b/user/src/com/google/gwt/user/client/ui/FormPanel.java
index cf7407a..c3ae4c6 100644
--- a/user/src/com/google/gwt/user/client/ui/FormPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/FormPanel.java
@@ -16,7 +16,6 @@
 package com.google.gwt.user.client.ui;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.FormElement;
@@ -310,8 +309,8 @@
    * 'text/html', meaning that the text returned will be treated as HTML. If any
    * other content-type is specified by the server, then the result HTML sent in
    * the onFormSubmit event will be unpredictable across browsers, and the
-   * {@link SubmitCompleteHandler#onSubmitComplete(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) onSubmitComplete} event
-   * may not fire at all.
+   * {@link SubmitCompleteHandler#onSubmitComplete(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)
+   * onSubmitComplete} event may not fire at all.
    * </p>
    * 
    * @tip The initial implementation of FormPanel specified that the server
@@ -404,7 +403,7 @@
 
   /**
    * @deprecated Use {@link #addSubmitCompleteHandler} and
-   * {@link #addSubmitHandler} instead
+   *             {@link #addSubmitHandler} instead
    */
   @Deprecated
   public void addFormHandler(FormHandler handler) {
@@ -479,26 +478,16 @@
    * @return true if the form is submitted, false if canceled
    */
   public boolean onFormSubmit() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      return onFormSubmitAndCatch(handler);
-    } else {
-      return onFormSubmitImpl();
-    }
+    return onFormSubmitImpl();
   }
 
   public void onFrameLoad() {
-    UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
-    if (handler != null) {
-      onFrameLoadAndCatch(handler);
-    } else {
-      onFrameLoadImpl();
-    }
+    onFrameLoadImpl();
   }
 
   /**
-   * @deprecated Use the {@link HandlerRegistration#removeHandler}
-   * method on the object returned by and add*Handler method instead
+   * @deprecated Use the {@link HandlerRegistration#removeHandler} method on the
+   *             object returned by and add*Handler method instead
    */
   @Deprecated
   public void removeFormHandler(FormHandler handler) {
@@ -624,15 +613,6 @@
     return getElement().cast();
   }
 
-  private boolean onFormSubmitAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      return onFormSubmitImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-      return false;
-    }
-  }
-
   /**
    * @return true if the form is submitted, false if canceled
    */
@@ -640,14 +620,6 @@
     return fireSubmitEvent();
   }
 
-  private void onFrameLoadAndCatch(UncaughtExceptionHandler handler) {
-    try {
-      onFrameLoadImpl();
-    } catch (Throwable e) {
-      handler.onUncaughtException(e);
-    }
-  }
-
   private void onFrameLoadImpl() {
     // Fire onComplete events in a deferred command. This is necessary
     // because clients that detach the form panel when submission is
diff --git a/user/src/com/google/gwt/user/client/ui/HorizontalSplitPanel.java b/user/src/com/google/gwt/user/client/ui/HorizontalSplitPanel.java
index e0ff61c..cd7ff74 100644
--- a/user/src/com/google/gwt/user/client/ui/HorizontalSplitPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/HorizontalSplitPanel.java
@@ -290,9 +290,9 @@
 
     private native void addResizeListener(Element container) /*-{
       var self = this;
-      container.onresize = function() {
+      container.onresize = $entry(function() {
         self.@com.google.gwt.user.client.ui.HorizontalSplitPanel$ImplIE6::onResize()();
-      };
+      });
     }-*/;
 
     private void onResize() {
diff --git a/user/src/com/google/gwt/user/client/ui/VerticalSplitPanel.java b/user/src/com/google/gwt/user/client/ui/VerticalSplitPanel.java
index d5bac1c..240f6b8 100644
--- a/user/src/com/google/gwt/user/client/ui/VerticalSplitPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/VerticalSplitPanel.java
@@ -220,9 +220,9 @@
 
     private native void addResizeListener(Element container) /*-{
          var self = this;
-         container.onresize = function() {
+         container.onresize = $entry(function() {
            self.@com.google.gwt.user.client.ui.VerticalSplitPanel$ImplIE6::onResize()();
-         };
+         });
       }-*/;
 
     private void onResize() {
diff --git a/user/src/com/google/gwt/user/client/ui/impl/FormPanelImpl.java b/user/src/com/google/gwt/user/client/ui/impl/FormPanelImpl.java
index 73b9854..2438c0a 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/FormPanelImpl.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/FormPanelImpl.java
@@ -63,23 +63,23 @@
   public native void hookEvents(Element iframe, Element form,
       FormPanelImplHost listener) /*-{
     if (iframe) {
-      iframe.onload = function() {
+      iframe.onload = $entry(function() {
         // If there is no __formAction yet, this is a spurious onload
         // generated when the iframe is first added to the DOM.
         if (!iframe.__formAction)
           return;
 
         listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFrameLoad()();
-      };
+      });
     }
 
-    form.onsubmit = function() {
+    form.onsubmit = $entry(function() {
       // Hang on to the form's action url, needed in the
       // onload/onreadystatechange handler.
       if (iframe)
         iframe.__formAction = form.action;
       return listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFormSubmit()();
-    };
+    });
   }-*/;
 
   /**
diff --git a/user/src/com/google/gwt/user/client/ui/impl/FormPanelImplIE6.java b/user/src/com/google/gwt/user/client/ui/impl/FormPanelImplIE6.java
index bb52b3e..09397db 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/FormPanelImplIE6.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/FormPanelImplIE6.java
@@ -25,7 +25,7 @@
   @Override
   public native void hookEvents(Element iframe, Element form, FormPanelImplHost listener) /*-{
     if (iframe) {
-      iframe.onreadystatechange = function() {
+      iframe.onreadystatechange = $entry(function() {
         // If there is no __formAction yet, this is a spurious onreadystatechange
         // generated when the iframe is first added to the DOM.
         if (!iframe.__formAction)
@@ -36,16 +36,16 @@
           // url, then it must be an error, so we ignore it.
           listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFrameLoad()();
         }
-      };
+      });
     }
 
-    form.onsubmit = function() {
+    form.onsubmit = $entry(function() {
       // Hang on to the form's action url, needed in the
       // onload/onreadystatechange handler.
       if (iframe)
         iframe.__formAction = form.action;
       return listener.@com.google.gwt.user.client.ui.impl.FormPanelImplHost::onFormSubmit()();
-    };
+    });
   }-*/;
 
   @Override
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
index 338359a..ad56246 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplIE6.java
@@ -35,7 +35,7 @@
     var _this = this;
     _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::initializing = true;
 
-    setTimeout(function() {
+    setTimeout($entry(function() {
       if (_this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::initializing == false) {
         return;
       }
@@ -57,7 +57,7 @@
 
       // Send notification that the iframe has reached design mode.
       _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitialized()();
-    }, 1);
+    }, 1));
   }-*/;
 
   @Override
@@ -91,14 +91,14 @@
     var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
     var body = elem.contentWindow.document.body;
 
-    var handler = function() {
+    var handler = $entry(function() {
       if (elem.__listener) {
         // Weird: this code has the context of the script frame, but we need the
         // event from the edit iframe's window.
         var evt = elem.contentWindow.event;
         elem.__listener.@com.google.gwt.user.client.ui.Widget::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(evt);
       }
-    };
+    });
 
     body.onkeydown =
     body.onkeyup =
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplMozilla.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplMozilla.java
index a43219e..88dc548 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplMozilla.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplMozilla.java
@@ -28,7 +28,7 @@
     var iframe = _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
     _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::initializing = true;
 
-    iframe.onload = function() {
+    iframe.onload = $entry(function() {
       // Some Mozillae have the nasty habit of calling onload again when you set
       // designMode, so let's avoid doing it more than once.
       iframe.onload = null;
@@ -58,7 +58,7 @@
         iframe.contentWindow.onmouseover = null;
         iframe.contentWindow.document.designMode = 'On';
       };
-    };
+    });
   }-*/;
 
   @Override
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
index 86dac58..5735cef 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
@@ -90,13 +90,13 @@
     // just fine.
     var _this = this;
     _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::initializing = true;
-    setTimeout(function() {
+    setTimeout($entry(function() {
       // Turn on design mode.
       _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.contentWindow.document.designMode = 'On';
 
       // Send notification that the iframe has reached design mode.
       _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitialized()();
-    }, 1);
+    }), 1);
   }-*/;
 
   public void insertHorizontalRule() {
@@ -286,11 +286,11 @@
     var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
     var wnd = elem.contentWindow;
 
-    elem.__gwt_handler = function(evt) {
+    elem.__gwt_handler = $entry(function(evt) {
       if (elem.__listener) {
         elem.__listener.@com.google.gwt.user.client.ui.Widget::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(evt);
       }
-    };
+    });
 
     elem.__gwt_focusHandler = function(evt) {
       if (elem.__gwt_isFocused) {
diff --git a/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java b/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
index c7ca653..8d3a6a4 100644
--- a/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
+++ b/user/src/com/google/gwt/xhr/client/XMLHttpRequest.java
@@ -251,9 +251,9 @@
     // The 'this' context is always supposed to point to the xhr object in the
     // onreadystatechange handler, but we reference it via closure to be extra sure.
     var _this = this;
-    this.onreadystatechange = function() {
+    this.onreadystatechange = $entry(function() {
       handler.@com.google.gwt.xhr.client.ReadyStateChangeHandler::onReadyStateChange(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
-    };
+    });
   }-*/;
 
   /**