Fix bug 643450. r=peterv
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 08 Apr 2011 14:28:24 -0700
changeset 67693 a91752ea97cf305921e5d791e2bc8d66cbcb1c06
parent 67692 bed34ea0027c571338167b736846fbcad9320d55
child 67694 a089731c47d5cee62c33c6423befeaf7f14a921c
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs643450
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix bug 643450. r=peterv
dom/base/nsJSEnvironment.cpp
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -1899,49 +1899,40 @@ nsJSContext::CallEventHandler(nsISupport
     NS_ENSURE_SUCCESS(rv, rv);
 
     ++mExecuteDepth;
     PRBool ok = ::JS_CallFunctionValue(mContext, target,
                                        funval, argc, argv, &rval);
     --mExecuteDepth;
 
     if (!ok) {
-      // Tell XPConnect about any pending exceptions. This is needed
-      // to avoid dropping JS exceptions in case we got here through
-      // nested calls through XPConnect.
-
-      ReportPendingException();
-
       // Don't pass back results from failed calls.
       rval = JSVAL_VOID;
 
       // Tell the caller that the handler threw an error.
       rv = NS_ERROR_FAILURE;
+    } else if (rval == JSVAL_NULL) {
+      *arv = nsnull;
+    } else if (!JS_WrapValue(mContext, &rval)) {
+      rv = NS_ERROR_FAILURE;
+    } else {
+      rv = nsContentUtils::XPConnect()->JSToVariant(mContext, rval, arv);
     }
 
+    // Tell XPConnect about any pending exceptions. This is needed
+    // to avoid dropping JS exceptions in case we got here through
+    // nested calls through XPConnect.
+    if (NS_FAILED(rv))
+      ReportPendingException();
+
     sSecurityManager->PopContextPrincipal(mContext);
   }
 
   pusher.Pop();
 
-  // Convert to variant before calling ScriptEvaluated, as it may GC, meaning
-  // we would need to root rval.
-  if (NS_SUCCEEDED(rv)) {
-    if (rval == JSVAL_NULL) {
-      *arv = nsnull;
-    } else {
-      if (!JS_WrapValue(mContext, &rval)) {
-        ReportPendingException();
-        rv = NS_ERROR_FAILURE;
-      } else {
-        rv = nsContentUtils::XPConnect()->JSToVariant(mContext, rval, arv);
-      }
-    }
-  }
-
   // ScriptEvaluated needs to come after we pop the stack
   ScriptEvaluated(PR_TRUE);
 
   return rv;
 }
 
 nsresult
 nsJSContext::BindCompiledEventHandler(nsISupports* aTarget, void *aScope,