Skip to content

Commit 600ab9b

Browse files
committed
Bug 1091091: Support ErrorResult in Promise::MaybeReject(). r=bz
1 parent 9719796 commit 600ab9b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

dom/bindings/ToJSValue.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,19 @@ ToJSValue(JSContext* aCx,
6060
return ToJSValue(aCx, exception, aValue);
6161
}
6262

63+
bool
64+
ToJSValue(JSContext* aCx,
65+
ErrorResult& aArgument,
66+
JS::MutableHandle<JS::Value> aValue)
67+
{
68+
MOZ_ASSERT(aArgument.Failed());
69+
ThrowMethodFailedWithDetails(aCx, aArgument, "", "");
70+
if (!JS_GetPendingException(aCx, aValue)) {
71+
return false;
72+
}
73+
JS_ClearPendingException(aCx);
74+
return true;
75+
}
76+
6377
} // namespace dom
6478
} // namespace mozilla

dom/bindings/ToJSValue.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ ToJSValue(JSContext* aCx,
261261
nsresult aArgument,
262262
JS::MutableHandle<JS::Value> aValue);
263263

264+
// Accept ErrorResult, for use in rejections, and create an exception
265+
// representing the failure. Note, the ErrorResult must indicate a failure
266+
// with aArgument.Failure() returning true.
267+
bool
268+
ToJSValue(JSContext* aCx,
269+
ErrorResult& aArgument,
270+
JS::MutableHandle<JS::Value> aValue);
271+
264272
// Accept pointers to other things we accept
265273
template <typename T>
266274
typename EnableIf<IsPointer<T>::value, bool>::Type

dom/promise/Promise.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ class Promise : public nsISupports,
101101
MaybeSomething(aArg, &Promise::MaybeReject);
102102
}
103103

104+
inline void MaybeReject(ErrorResult& aArg) {
105+
MOZ_ASSERT(aArg.Failed());
106+
MaybeSomething(aArg, &Promise::MaybeReject);
107+
}
108+
104109
void MaybeReject(const nsRefPtr<MediaStreamError>& aArg);
105110

106111
// DO NOT USE MaybeRejectBrokenly with in new code. Promises should be

0 commit comments

Comments
 (0)