Bug 1091091: Support ErrorResult in Promise::MaybeReject(). r=bz

This commit is contained in:
Ben Kelly 2014-10-30 11:12:09 -04:00
parent 97197969ad
commit 600ab9bfb9
3 changed files with 27 additions and 0 deletions

View File

@ -60,5 +60,19 @@ ToJSValue(JSContext* aCx,
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

View File

@ -261,6 +261,14 @@ 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

View File

@ -101,6 +101,11 @@ public:
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