Bug 856410 - Implement futures - Part 0: ErrorResult::StealJSException. r=bz
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 11 Jun 2013 21:41:21 -0400
changeset 146216 d27ecea31590ae410e65670fe5baa931ae44182a
parent 146215 ca761338dcde31c1a3e23c89c16f1d56231bdabf
child 146217 818909e614510b25eaefcd46c6a273c1195d8abd
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs856410
milestone24.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 856410 - Implement futures - Part 0: ErrorResult::StealJSException. r=bz
dom/bindings/BindingUtils.cpp
dom/bindings/ErrorResult.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -155,16 +155,29 @@ ErrorResult::ReportJSException(JSContext
   if (JS_WrapValue(cx, &mJSException)) {
     JS_SetPendingException(cx, mJSException);
   }
   // If JS_WrapValue failed, not much we can do about it...  No matter
   // what, go ahead and unroot mJSException.
   JS_RemoveValueRoot(cx, &mJSException);
 }
 
+void
+ErrorResult::StealJSException(JSContext* cx,
+                              JS::MutableHandle<JS::Value> value)
+{
+  MOZ_ASSERT(!mMightHaveUnreportedJSException,
+             "Must call WouldReportJSException unconditionally in all codepaths that might call StealJSException");
+  MOZ_ASSERT(IsJSException(), "No exception to steal");
+
+  value.set(mJSException);
+  JS_RemoveValueRoot(cx, &mJSException);
+  mResult = NS_OK;
+}
+
 namespace dom {
 
 bool
 DefineConstants(JSContext* cx, JS::Handle<JSObject*> obj,
                 const ConstantSpec* cs)
 {
   for (; cs->name; ++cs) {
     JSBool ok =
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -59,21 +59,28 @@ public:
   void ThrowTypeError(const dom::ErrNum errorNumber, ...);
   void ReportTypeError(JSContext* cx);
   void ClearMessage();
   bool IsTypeError() const { return ErrorCode() == NS_ERROR_TYPE_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 as needed must
-  // first call WouldReportJSException even if this ErrorResult has not failed.
+  // is being thrown.  Code that would call ReportJSException or
+  // StealJSException as needed must first call WouldReportJSException even if
+  // this ErrorResult has not failed.
   void ThrowJSException(JSContext* cx, JS::Handle<JS::Value> exn);
   void ReportJSException(JSContext* cx);
   bool IsJSException() const { return ErrorCode() == NS_ERROR_DOM_JS_EXCEPTION; }
+
+  // StealJSException steals the JS Exception from the object. This method must
+  // be called only if IsJSException() returns true. This method also resets the
+  // ErrorCode() to NS_OK.
+  void StealJSException(JSContext* cx, JS::MutableHandle<JS::Value> value);
+
   void MOZ_ALWAYS_INLINE MightThrowJSException()
   {
 #ifdef DEBUG
     mMightHaveUnreportedJSException = true;
 #endif
   }
   void MOZ_ALWAYS_INLINE WouldReportJSException()
   {