Skip to content

Commit

Permalink
Bug 1802690 - Re-work error handling DocumentL10n::TranslateDocument;…
Browse files Browse the repository at this point in the history
… r=nordzilla

Differential Revision: https://phabricator.services.mozilla.com/D163264
  • Loading branch information
gregtatum committed Dec 16, 2022
1 parent 5d22542 commit 5523bbe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions dom/l10n/DocumentL10n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ already_AddRefed<Promise> DocumentL10n::TranslateDocument(ErrorResult& aRv) {
MOZ_ASSERT(mState == DocumentL10nState::Constructed,
"This method should be called only from Constructed state.");
RefPtr<Promise> promise = Promise::Create(mGlobal, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}

Element* elem = mDocument->GetDocumentElement();
if (!elem) {
Expand Down Expand Up @@ -253,17 +256,18 @@ already_AddRefed<Promise> DocumentL10n::TranslateDocument(ErrorResult& aRv) {
// 2.1.4. Collect promises with Promise::All (maybe empty).
AutoEntryScript aes(mGlobal, "DocumentL10n InitialTranslationCompleted");
promise = Promise::All(aes.cx(), promises, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
} else {
// 2.2. Handle the case when we don't have proto.

// 2.2.1. Otherwise, translate all available elements,
// without attempting to cache them.
promise = TranslateElements(elements, nullptr, aRv);
}

if (NS_WARN_IF(!promise || aRv.Failed())) {
promise->MaybeRejectWithUndefined();
return promise.forget();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
}

return promise.forget();
Expand Down

0 comments on commit 5523bbe

Please sign in to comment.