Bug 1195977, part 5 - Hoist out inner part of ErrorResult::ThrowErrorWithMessage() into a helper. r=peterv
authorAndrew McCreight <continuation@gmail.com>
Tue, 15 Sep 2015 11:47:04 -0700
changeset 295265 fba22ced664c2b945b1f34ed142a6ed46ad27dcb
parent 295264 f3075fbc955dcb3606b005875f45293a661220b2
child 295266 8fbf291b2fdc7d23da7e02ea85edbe6d8c44cb62
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 5 - Hoist out inner part of ErrorResult::ThrowErrorWithMessage() into a helper. r=peterv This will enable us to move it to the header later, which is needed to turn it into a template.
dom/bindings/BindingUtils.cpp
dom/bindings/ErrorResult.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -160,38 +160,45 @@ struct ErrorResult::Message {
   dom::ErrNum mErrorNumber;
 
   bool HasCorrectNumberOfArguments()
   {
     return GetErrorArgCount(mErrorNumber) == mArgs.Length();
   }
 };
 
+nsTArray<nsString>&
+ErrorResult::CreateErrorMessageHelper(const dom::ErrNum errorNumber, nsresult errorType)
+{
+  if (IsErrorWithMessage()) {
+    delete mMessage;
+  }
+  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;
   }
-  if (IsErrorWithMessage()) {
-    delete mMessage;
-  }
-  mResult = errorType;
-  Message* message = new Message();
-  message->mErrorNumber = errorNumber;
+  nsTArray<nsString>& messageArgsArray = CreateErrorMessageHelper(errorNumber, errorType);
   uint16_t argCount = dom::GetErrorArgCount(errorNumber);
   while (argCount--) {
-    message->mArgs.AppendElement(*va_arg(ap, const nsAString*));
+    messageArgsArray.AppendElement(*va_arg(ap, const nsAString*));
   }
-  mMessage = message;
 #ifdef DEBUG
   mHasMessage = true;
 #endif
 }
 
 void
 ErrorResult::SerializeMessage(IPC::Message* aMsg) const
 {
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -169,16 +169,20 @@ protected:
     return mResult;
   }
 
 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 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()");