Bug 933378 part 4. Change the ErrorResult destructor to suppress the exception, after asserting that it's already suppressed. r=bkelly
☠☠ backed out by a795d0003a44 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 15 Jul 2016 22:35:13 -0400
changeset 330257 ed38780a242cb738c331a9abaf63b94ae325d325
parent 330256 b33a9a88daa6663ffbfa84ce5478ddcce898f3d9
child 330258 7fef388bc6cf208be8015f654bb0415118cda6b3
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs933378
milestone50.0a1
Bug 933378 part 4. Change the ErrorResult destructor to suppress the exception, after asserting that it's already suppressed. r=bkelly
dom/bindings/BindingUtils.cpp
dom/bindings/ErrorResult.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -574,16 +574,18 @@ TErrorResult<CleanupPolicy>::NoteJSConte
   if (JS_IsExceptionPending(aCx)) {
     mResult = NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT;
   } else {
     mResult = NS_ERROR_UNCATCHABLE_EXCEPTION;
   }
 }
 
 template class TErrorResult<JustAssertCleanupPolicy>;
+template class TErrorResult<AssertAndSuppressCleanupPolicy>;
+template class TErrorResult<JustSuppressCleanupPolicy>;
 
 } // namespace binding_danger
 
 namespace dom {
 
 bool
 DefineConstants(JSContext* cx, JS::Handle<JSObject*> obj,
                 const ConstantSpec* cs)
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -455,23 +455,34 @@ private:
   void operator=(const TErrorResult&) = delete;
 };
 
 struct JustAssertCleanupPolicy {
   static const bool assertHandled = true;
   static const bool suppress = false;
 };
 
+struct AssertAndSuppressCleanupPolicy {
+  static const bool assertHandled = true;
+  static const bool suppress = true;
+};
+
+struct JustSuppressCleanupPolicy {
+  static const bool assertHandled = false;
+  static const bool suppress = true;
+};
+
 } // namespace binding_danger
 
 // A class people should normally use on the stack when they plan to actually
 // do something with the exception.
-class ErrorResult : public binding_danger::TErrorResult<binding_danger::JustAssertCleanupPolicy>
+class ErrorResult :
+    public binding_danger::TErrorResult<binding_danger::AssertAndSuppressCleanupPolicy>
 {
-  typedef binding_danger::TErrorResult<binding_danger::JustAssertCleanupPolicy> BaseErrorResult;
+  typedef binding_danger::TErrorResult<binding_danger::AssertAndSuppressCleanupPolicy> BaseErrorResult;
 
 public:
   ErrorResult()
     : BaseErrorResult()
   {}
 
   ErrorResult(ErrorResult&& aRHS)
     : BaseErrorResult(Move(aRHS))
@@ -498,27 +509,25 @@ private:
   ErrorResult(const ErrorResult&) = delete;
   void operator=(const ErrorResult&) = delete;
 };
 
 template<typename CleanupPolicy>
 binding_danger::TErrorResult<CleanupPolicy>::operator ErrorResult&()
 {
   return *static_cast<ErrorResult*>(
-     reinterpret_cast<TErrorResult<JustAssertCleanupPolicy>*>(this));
+     reinterpret_cast<TErrorResult<AssertAndSuppressCleanupPolicy>*>(this));
 }
 
 // A class for use when an ErrorResult should just automatically be ignored.
-class IgnoredErrorResult : public ErrorResult
+// This doesn't inherit from ErrorResult so we don't make two separate calls to
+// SuppressException.
+class IgnoredErrorResult :
+    public binding_danger::TErrorResult<binding_danger::JustSuppressCleanupPolicy>
 {
-public:
-  ~IgnoredErrorResult()
-  {
-    SuppressException();
-  }
 };
 
 /******************************************************************************
  ** Macros for checking results
  ******************************************************************************/
 
 #define ENSURE_SUCCESS(res, ret)                                          \
   do {                                                                    \