Bug 1091091: Support ErrorResult in Promise::MaybeReject(). r=bz
authorBen Kelly <ben@wanderview.com>
Thu, 30 Oct 2014 11:12:09 -0400
changeset 237504 12bba4eb1cef5461a72d49a3360aea612aa9e6c9
parent 237503 8670dbe3bfcc171b525a258398eb53bb90d96adb
child 237505 2ba76e4bc640806a780cd3c6b5c7a372f97d4940
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1091091
milestone36.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 1091091: Support ErrorResult in Promise::MaybeReject(). r=bz
dom/bindings/ToJSValue.cpp
dom/bindings/ToJSValue.h
dom/promise/Promise.h
--- a/dom/bindings/ToJSValue.cpp
+++ b/dom/bindings/ToJSValue.cpp
@@ -55,10 +55,24 @@ bool
 ToJSValue(JSContext* aCx,
           nsresult aArgument,
           JS::MutableHandle<JS::Value> aValue)
 {
   nsRefPtr<Exception> exception = CreateException(aCx, aArgument);
   return ToJSValue(aCx, exception, aValue);
 }
 
+bool
+ToJSValue(JSContext* aCx,
+          ErrorResult& aArgument,
+          JS::MutableHandle<JS::Value> aValue)
+{
+  MOZ_ASSERT(aArgument.Failed());
+  ThrowMethodFailedWithDetails(aCx, aArgument, "", "");
+  if (!JS_GetPendingException(aCx, aValue)) {
+    return false;
+  }
+  JS_ClearPendingException(aCx);
+  return true;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/bindings/ToJSValue.h
+++ b/dom/bindings/ToJSValue.h
@@ -256,16 +256,24 @@ ToJSValue(JSContext* aCx, const JS::Root
 
 // Accept nsresult, for use in rejections, and create an XPCOM
 // exception object representing that nsresult.
 bool
 ToJSValue(JSContext* aCx,
           nsresult aArgument,
           JS::MutableHandle<JS::Value> aValue);
 
+// Accept ErrorResult, for use in rejections, and create an exception
+// representing the failure.  Note, the ErrorResult must indicate a failure
+// with aArgument.Failure() returning true.
+bool
+ToJSValue(JSContext* aCx,
+          ErrorResult& aArgument,
+          JS::MutableHandle<JS::Value> aValue);
+
 // Accept pointers to other things we accept
 template <typename T>
 typename EnableIf<IsPointer<T>::value, bool>::Type
 ToJSValue(JSContext* aCx,
           T aArgument,
           JS::MutableHandle<JS::Value> aValue)
 {
   return ToJSValue(aCx, *aArgument, aValue);
--- a/dom/promise/Promise.h
+++ b/dom/promise/Promise.h
@@ -96,16 +96,21 @@ public:
     MaybeSomething(aArg, &Promise::MaybeResolve);
   }
 
   inline void MaybeReject(nsresult aArg) {
     MOZ_ASSERT(NS_FAILED(aArg));
     MaybeSomething(aArg, &Promise::MaybeReject);
   }
 
+  inline void MaybeReject(ErrorResult& aArg) {
+    MOZ_ASSERT(aArg.Failed());
+    MaybeSomething(aArg, &Promise::MaybeReject);
+  }
+
   void MaybeReject(const nsRefPtr<MediaStreamError>& aArg);
 
   // DO NOT USE MaybeRejectBrokenly with in new code.  Promises should be
   // rejected with Error instances.
   // Note: MaybeRejectBrokenly is a template so we can use it with DOMError
   // without instantiating the DOMError specialization of MaybeSomething in
   // every translation unit that includes this header, because that would
   // require use to include DOMError.h either here or in all those translation