Bug 1328861 - Be a little less trusting about our error codes in ErrorResult. r=smaug a=abillings
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 10 Feb 2017 23:06:34 -0500
changeset 376116 46116604aa0b07bffac9c4c27e19f27805e56883
parent 376115 88fc184793213bd139b752681ac51a057d4b48d5
child 376117 447a9c40939c591b7bda5ca763a69f1f32ac87d6
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, abillings
bugs1328861
milestone53.0a2
Bug 1328861 - Be a little less trusting about our error codes in ErrorResult. r=smaug a=abillings
dom/bindings/ErrorResult.h
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -181,16 +181,27 @@ public:
   void SuppressException();
 
   // Use StealNSResult() when you want to safely convert the TErrorResult to
   // an nsresult that you will then return to a caller.  This will
   // SuppressException(), since there will no longer be a way to report it.
   nsresult StealNSResult() {
     nsresult rv = ErrorCode();
     SuppressException();
+    // Don't propagate out our internal error codes that have special meaning.
+    if (rv == NS_ERROR_TYPE_ERR ||
+        rv == NS_ERROR_RANGE_ERR ||
+        rv == NS_ERROR_DOM_JS_EXCEPTION ||
+        rv == NS_ERROR_DOM_DOMEXCEPTION) {
+      // What about NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT?  I guess that can be
+      // legitimately passed on through....
+      // What to pick here?
+      return NS_ERROR_DOM_INVALID_STATE_ERR;
+    }
+
     return rv;
   }
 
   // Use MaybeSetPendingException to convert a TErrorResult to a pending
   // exception on the given JSContext.  This is the normal "throw an exception"
   // codepath.
   //
   // The return value is false if the TErrorResult represents success, true
@@ -390,17 +401,25 @@ private:
     MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
     MOZ_ASSERT(aRv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
     MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
     MOZ_ASSERT(aRv != NS_ERROR_DOM_DOMEXCEPTION, "Use ThrowDOMException()");
     MOZ_ASSERT(!IsDOMException(), "Don't overwrite DOM exceptions");
     MOZ_ASSERT(aRv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "May need to bring back ThrowNotEnoughArgsError");
     MOZ_ASSERT(aRv != NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT,
                "Use NoteJSContextException");
-    mResult = aRv;
+    // Don't trust people anyway, though.
+    if (aRv == NS_ERROR_TYPE_ERR ||
+        aRv == NS_ERROR_RANGE_ERR ||
+        aRv == NS_ERROR_DOM_JS_EXCEPTION ||
+        aRv == NS_ERROR_DOM_DOMEXCEPTION) {
+      mResult = NS_ERROR_UNEXPECTED;
+    } else {
+      mResult = aRv;
+    }
   }
 
   void ClearMessage();
   void ClearDOMExceptionInfo();
 
   // ClearUnionData will try to clear the data in our
   // mMessage/mJSException/mDOMExceptionInfo union.  After this the union may be
   // in an uninitialized state (e.g. mMessage or mDOMExceptionInfo may be