Bug 1581278 part 1. Implement ErrorResult overload of DetailedPromise::MaybeReject. r=bholley

Differential Revision: https://phabricator.services.mozilla.com/D46382

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2019-09-19 20:46:15 +00:00
parent 417c6749c3
commit 6bfd85094a
2 changed files with 13 additions and 6 deletions

View File

@ -35,23 +35,29 @@ DetailedPromise::~DetailedPromise() {
MaybeReportTelemetry(kFailed);
}
void DetailedPromise::MaybeReject(nsresult aArg, const nsACString& aReason) {
void DetailedPromise::LogRejectionReason(uint32_t aErrorCode,
const nsACString& aReason) {
nsPrintfCString msg("%s promise rejected 0x%" PRIx32 " '%s'", mName.get(),
static_cast<uint32_t>(aArg),
PromiseFlatCString(aReason).get());
aErrorCode, PromiseFlatCString(aReason).get());
EME_LOG("%s", msg.get());
MaybeReportTelemetry(kFailed);
LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
}
void DetailedPromise::MaybeReject(nsresult aArg, const nsACString& aReason) {
LogRejectionReason(static_cast<uint32_t>(aArg), aReason);
ErrorResult rv;
rv.ThrowDOMException(aArg, aReason);
Promise::MaybeReject(rv);
}
void DetailedPromise::MaybeReject(ErrorResult&, const nsACString& aReason) {
MOZ_ASSERT_UNREACHABLE("nsresult expected in MaybeReject()");
void DetailedPromise::MaybeReject(ErrorResult& aArg,
const nsACString& aReason) {
LogRejectionReason(aArg.ErrorCodeAsInt(), aReason);
Promise::MaybeReject(aArg);
}
/* static */

View File

@ -41,7 +41,7 @@ class DetailedPromise : public Promise {
void MaybeReject(nsresult aArg, const nsACString& aReason);
void MaybeReject(ErrorResult& aArg) = delete;
void MaybeReject(ErrorResult&, const nsACString& aReason);
void MaybeReject(ErrorResult& aArg, const nsACString& aReason);
private:
explicit DetailedPromise(nsIGlobalObject* aGlobal, const nsACString& aName);
@ -53,6 +53,7 @@ class DetailedPromise : public Promise {
enum eStatus { kSucceeded, kFailed };
void MaybeReportTelemetry(eStatus aStatus);
void LogRejectionReason(uint32_t aErrorCode, const nsACString& aReason);
nsCString mName;
bool mResponded;