Bug 1339540 part 3. Use nsresult values in the ErrorResult error module in place of NS_ERROR_TYPE_ERR/NS_ERROR_RANGE_ERR in ErrorResult code. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 15 Feb 2017 00:02:36 -0500
changeset 342921 b17eeee93d22d89e99355b72c5b46b6125ff99f1
parent 342920 8682efc34f6c8ca80c2d4394870f581c441debc6
child 342922 1de058eb82318ee656c7162dc9516a9db9defc0c
push id86995
push userbzbarsky@mozilla.com
push dateWed, 15 Feb 2017 05:36:17 +0000
treeherdermozilla-inbound@b17eeee93d22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1339540
milestone54.0a1
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
Bug 1339540 part 3. Use nsresult values in the ErrorResult error module in place of NS_ERROR_TYPE_ERR/NS_ERROR_RANGE_ERR in ErrorResult code. r=smaug
dom/bindings/ErrorResult.h
xpcom/base/ErrorList.h
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -182,18 +182,18 @@ public:
 
   // 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 ||
+    if (rv == NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR ||
+        rv == NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR ||
         rv == NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION ||
         rv == NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION) {
       // What to pick here?
       return NS_ERROR_DOM_INVALID_STATE_ERR;
     }
 
     return rv;
   }
@@ -246,28 +246,32 @@ public:
   //
   // When this function returns, JS_IsExceptionPending(cx) will definitely be
   // false.
   void StealExceptionFromJSContext(JSContext* cx);
 
   template<dom::ErrNum errorNumber, typename... Ts>
   void ThrowTypeError(Ts&&... messageArgs)
   {
-    ThrowErrorWithMessage<errorNumber>(NS_ERROR_TYPE_ERR,
+    ThrowErrorWithMessage<errorNumber>(NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR,
                                        Forward<Ts>(messageArgs)...);
   }
 
   template<dom::ErrNum errorNumber, typename... Ts>
   void ThrowRangeError(Ts&&... messageArgs)
   {
-    ThrowErrorWithMessage<errorNumber>(NS_ERROR_RANGE_ERR,
+    ThrowErrorWithMessage<errorNumber>(NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR,
                                        Forward<Ts>(messageArgs)...);
   }
 
-  bool IsErrorWithMessage() const { return ErrorCode() == NS_ERROR_TYPE_ERR || ErrorCode() == NS_ERROR_RANGE_ERR; }
+  bool IsErrorWithMessage() const
+  {
+    return ErrorCode() == NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR ||
+           ErrorCode() == NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR;
+  }
 
   // Facilities for throwing a preexisting JS exception value via this
   // TErrorResult.  The contract is that any code which might end up calling
   // ThrowJSException() or StealExceptionFromJSContext() must call
   // MightThrowJSException() even if no exception is being thrown.  Code that
   // conditionally calls ToJSValue on this TErrorResult only if Failed() must
   // first call WouldReportJSException even if this TErrorResult has not failed.
   //
@@ -395,35 +399,31 @@ private:
 
   MOZ_ALWAYS_INLINE void AssertInOwningThread() const {
 #ifdef DEBUG
     NS_ASSERT_OWNINGTHREAD(TErrorResult);
 #endif
   }
 
   void AssignErrorCode(nsresult aRv) {
-    MOZ_ASSERT(aRv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()");
-    MOZ_ASSERT(aRv != NS_ERROR_RANGE_ERR, "Use ThrowRangeError()");
+    MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR,
+               "Use ThrowTypeError()");
+    MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR,
+               "Use ThrowRangeError()");
     MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
     MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION,
                "Use ThrowJSException()");
     MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
     MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_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_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT,
                "Use NoteJSContextException");
-    // Don't trust people anyway, though.
-    if (aRv == NS_ERROR_TYPE_ERR ||
-        aRv == NS_ERROR_RANGE_ERR) {
-      mResult = NS_ERROR_UNEXPECTED;
-    } else {
-      mResult = aRv;
-    }
+    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
@@ -445,18 +445,18 @@ private:
   MOZ_ALWAYS_INLINE void AssertReportedOrSuppressed()
   {
     MOZ_ASSERT(!Failed());
     MOZ_ASSERT(!mMightHaveUnreportedJSException);
     MOZ_ASSERT(mUnionState == HasNothing);
   }
 
   // Special values of mResult:
-  // NS_ERROR_TYPE_ERR -- ThrowTypeError() called on us.
-  // NS_ERROR_RANGE_ERR -- ThrowRangeError() called on us.
+  // NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR -- ThrowTypeError() called on us.
+  // NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR -- ThrowRangeError() called on us.
   // NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION -- ThrowJSException() called
   //                                               on us.
   // NS_ERROR_UNCATCHABLE_EXCEPTION -- ThrowUncatchableException called on us.
   // NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION -- ThrowDOMException() called
   //                                               on us.
   nsresult mResult;
 
   struct Message;
--- a/xpcom/base/ErrorList.h
+++ b/xpcom/base/ErrorList.h
@@ -1002,16 +1002,20 @@
   /* ======================================================================= */
 #define MODULE NS_ERROR_MODULE_ERRORRESULT
   /* Represents a JS Value being thrown as an exception. */
   ERROR(NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION,           FAILURE(1)),
   /* Used to indicate that we want to throw a DOMException. */
   ERROR(NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION,           FAILURE(2)),
   /* Used to indicate that an exception is already pending on the JSContext. */
   ERROR(NS_ERROR_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT, FAILURE(3)),
+  /* Used to indicate that we want to throw a TypeError. */
+  ERROR(NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR,              FAILURE(4)),
+  /* Used to indicate that we want to throw a RangeError. */
+  ERROR(NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR,             FAILURE(5)),
 #undef MODULE
 
   /* ======================================================================= */
   /* 51: NS_ERROR_MODULE_GENERAL */
   /* ======================================================================= */
 #define MODULE NS_ERROR_MODULE_GENERAL
   /* Error code used internally by the incremental downloader to cancel the
    * network channel when the download is already complete. */