Bug 856410 - Implement futures - Part 0: ErrorResult::StealJSException. r=bz

This commit is contained in:
Andrea Marchesini 2013-06-11 21:41:21 -04:00
parent 21b3447e37
commit 5bd0488290
2 changed files with 22 additions and 2 deletions

View File

@ -160,6 +160,19 @@ ErrorResult::ReportJSException(JSContext* cx)
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

View File

@ -64,11 +64,18 @@ public:
// 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