Bug 1195977, part 6 - Inline ErrorResult throw error methods into the header. r=peterv
authorAndrew McCreight <continuation@gmail.com>
Tue, 15 Sep 2015 11:47:04 -0700
changeset 295266 8fbf291b2fdc7d23da7e02ea85edbe6d8c44cb62
parent 295265 fba22ced664c2b945b1f34ed142a6ed46ad27dcb
child 295267 eae3e7c3dbbd7fdd56c29eb26345c26780f2a122
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1195977
milestone43.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 1195977, part 6 - Inline ErrorResult throw error methods into the header. r=peterv This is needed to turn these into templates later.
dom/bindings/BindingUtils.cpp
dom/bindings/ErrorResult.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -174,37 +174,16 @@ ErrorResult::CreateErrorMessageHelper(co
   mResult = errorType;
 
   mMessage = new Message();
   mMessage->mErrorNumber = errorNumber;
   return mMessage->mArgs;
 }
 
 void
-ErrorResult::ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber,
-                                   nsresult errorType)
-{
-  if (IsJSException()) {
-    // We have rooted our mJSException, and we don't have the info
-    // needed to unroot here, so just bail.
-    MOZ_ASSERT(false,
-               "Ignoring ThrowErrorWithMessage call because we have a JS exception");
-    return;
-  }
-  nsTArray<nsString>& messageArgsArray = CreateErrorMessageHelper(errorNumber, errorType);
-  uint16_t argCount = dom::GetErrorArgCount(errorNumber);
-  while (argCount--) {
-    messageArgsArray.AppendElement(*va_arg(ap, const nsAString*));
-  }
-#ifdef DEBUG
-  mHasMessage = true;
-#endif
-}
-
-void
 ErrorResult::SerializeMessage(IPC::Message* aMsg) const
 {
   using namespace IPC;
   MOZ_ASSERT(mMessage);
   MOZ_ASSERT(mHasMessage);
   WriteParam(aMsg, mMessage->mArgs);
   WriteParam(aMsg, mMessage->mErrorNumber);
 }
@@ -226,34 +205,16 @@ ErrorResult::DeserializeMessage(const IP
   mMessage = readMessage.forget();
 #ifdef DEBUG
   mHasMessage = true;
 #endif
   return true;
 }
 
 void
-ErrorResult::ThrowTypeError(const dom::ErrNum errorNumber, ...)
-{
-  va_list ap;
-  va_start(ap, errorNumber);
-  ThrowErrorWithMessage(ap, errorNumber, NS_ERROR_TYPE_ERR);
-  va_end(ap);
-}
-
-void
-ErrorResult::ThrowRangeError(const dom::ErrNum errorNumber, ...)
-{
-  va_list ap;
-  va_start(ap, errorNumber);
-  ThrowErrorWithMessage(ap, errorNumber, NS_ERROR_RANGE_ERR);
-  va_end(ap);
-}
-
-void
 ErrorResult::ReportErrorWithMessage(JSContext* aCx)
 {
   MOZ_ASSERT(mMessage, "ReportErrorWithMessage() can be called only once");
   MOZ_ASSERT(mHasMessage);
 
   Message* message = mMessage;
   MOZ_RELEASE_ASSERT(message->HasCorrectNumberOfArguments());
   const uint32_t argCount = message->mArgs.Length();
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -13,16 +13,17 @@
 
 #include <stdarg.h>
 
 #include "js/Value.h"
 #include "nscore.h"
 #include "nsStringGlue.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Move.h"
+#include "nsTArray.h"
 
 namespace IPC {
 class Message;
 template <typename> struct ParamTraits;
 } // namespace IPC
 
 namespace mozilla {
 
@@ -31,16 +32,19 @@ namespace dom {
 enum ErrNum {
 #define MSG_DEF(_name, _argc, _exn, _str) \
   _name,
 #include "mozilla/dom/Errors.msg"
 #undef MSG_DEF
   Err_Limit
 };
 
+uint16_t
+GetErrorArgCount(const ErrNum aErrorNumber);
+
 bool
 ThrowErrorMessage(JSContext* aCx, const ErrNum aErrorNumber, ...);
 
 } // namespace dom
 
 class ErrorResult {
 public:
   ErrorResult() {
@@ -86,18 +90,34 @@ public:
   // 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();
     return rv;
   }
 
-  void ThrowTypeError(const dom::ErrNum errorNumber, ...);
-  void ThrowRangeError(const dom::ErrNum errorNumber, ...);
+  void
+  ThrowTypeError(const dom::ErrNum errorNumber, ...)
+  {
+    va_list ap;
+    va_start(ap, errorNumber);
+    ThrowErrorWithMessage(ap, errorNumber, NS_ERROR_TYPE_ERR);
+    va_end(ap);
+  }
+
+  void
+  ThrowRangeError(const dom::ErrNum errorNumber, ...)
+  {
+    va_list ap;
+    va_start(ap, errorNumber);
+    ThrowErrorWithMessage(ap, errorNumber, NS_ERROR_RANGE_ERR);
+    va_end(ap);
+  }
+
   void ReportErrorWithMessage(JSContext* cx);
   bool IsErrorWithMessage() const { return ErrorCode() == NS_ERROR_TYPE_ERR || ErrorCode() == NS_ERROR_RANGE_ERR; }
 
   // Facilities for throwing a preexisting JS exception value via this
   // ErrorResult.  The contract is that any code which might end up calling
   // ThrowJSException() must call MightThrowJSException() even if no exception
   // is being thrown.  Code that would call ReportJSException or
   // StealJSException as needed must first call WouldReportJSException even if
@@ -173,18 +193,35 @@ private:
   friend struct IPC::ParamTraits<ErrorResult>;
   void SerializeMessage(IPC::Message* aMsg) const;
   bool DeserializeMessage(const IPC::Message* aMsg, void** aIter);
 
   // Helper method that creates a new Message for this ErrorResult,
   // and returns the arguments array from that Message.
   nsTArray<nsString>& CreateErrorMessageHelper(const dom::ErrNum errorNumber, nsresult errorType);
 
-  void ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber,
-                             nsresult errorType);
+  void
+  ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber, nsresult errorType)
+  {
+    if (IsJSException()) {
+      // We have rooted our mJSException, and we don't have the info
+      // needed to unroot here, so just bail.
+      MOZ_ASSERT(false,
+                 "Ignoring ThrowErrorWithMessage call because we have a JS exception");
+      return;
+    }
+    nsTArray<nsString>& messageArgsArray = CreateErrorMessageHelper(errorNumber, errorType);
+    uint16_t argCount = dom::GetErrorArgCount(errorNumber);
+    while (argCount--) {
+      messageArgsArray.AppendElement(*va_arg(ap, const nsAString*));
+    }
+#ifdef DEBUG
+    mHasMessage = true;
+#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(!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_XPC_NOT_ENOUGH_ARGS, "May need to bring back ThrowNotEnoughArgsError");