Bug 1576343 - fix l10n.setAttributes use from inside DOMContentLoaded listeners when the proto is cached, r=smaug,zbraniecki a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 03 Sep 2019 05:40:02 +0000
changeset 551651 234d078a056b153975f5295244f1a6a6ce1abb02
parent 551650 eb147c90d7dbc7de17580f60cd6c1d5f3bbf0931
child 551652 18769c877f82d0790ed8a0b56b50171d967fb82b
push id11905
push usershindli@mozilla.com
push dateFri, 06 Sep 2019 18:47:35 +0000
treeherdermozilla-beta@3735e8cb4cad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, zbraniecki, lizzard
bugs1576343
milestone70.0
Bug 1576343 - fix l10n.setAttributes use from inside DOMContentLoaded listeners when the proto is cached, r=smaug,zbraniecki a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D43818
dom/l10n/DocumentL10n.cpp
--- a/dom/l10n/DocumentL10n.cpp
+++ b/dom/l10n/DocumentL10n.cpp
@@ -170,34 +170,35 @@ void DocumentL10n::TriggerInitialDocumen
       promises.AppendElement(nonProtoTranslatePromise);
     }
 
     // 2.1.4. Check if anything has to be translated.
     if (promises.IsEmpty()) {
       // 2.1.4.1. If not, resolve the mReady and complete
       //          initial translation.
       mReady->MaybeResolveWithUndefined();
+      ConnectRoot(*elem, rv);
       InitialDocumentTranslationCompleted();
-    } else {
-      // 2.1.4.2. If we have any TranslateElements promises,
-      //          collect them with Promise::All and schedule
-      //          the L10nReadyHandler.
-      AutoEntryScript aes(mGlobal,
-                          "DocumentL10n InitialDocumentTranslationCompleted");
-      RefPtr<Promise> promise = Promise::All(aes.cx(), promises, rv);
-      if (NS_WARN_IF(!promise || rv.Failed())) {
-        mReady->MaybeRejectWithUndefined();
-        InitialDocumentTranslationCompleted();
-        return;
-      }
+      return;
+    }
+    // 2.1.4.2. If we have any TranslateElements promises,
+    //          collect them with Promise::All and schedule
+    //          the L10nReadyHandler.
+    AutoEntryScript aes(mGlobal,
+                        "DocumentL10n InitialDocumentTranslationCompleted");
+    RefPtr<Promise> promise = Promise::All(aes.cx(), promises, rv);
+    if (NS_WARN_IF(!promise || rv.Failed())) {
+      mReady->MaybeRejectWithUndefined();
+      InitialDocumentTranslationCompleted();
+      return;
+    }
 
-      RefPtr<PromiseNativeHandler> l10nReadyHandler =
-          new L10nReadyHandler(mReady, this);
-      promise->AppendNativeHandler(l10nReadyHandler);
-    }
+    RefPtr<PromiseNativeHandler> l10nReadyHandler =
+        new L10nReadyHandler(mReady, this);
+    promise->AppendNativeHandler(l10nReadyHandler);
   } 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 and schedule
     //        the L10nReadyHandler.
     RefPtr<Promise> promise = TranslateElements(elements, nullptr, rv);
     if (NS_WARN_IF(!promise || rv.Failed())) {
@@ -240,9 +241,9 @@ void DocumentL10n::InitialDocumentTransl
     mIsSync = false;
 
     mLocalization->SetIsSync(mIsSync);
   }
 }
 
 Promise* DocumentL10n::Ready() { return mReady; }
 
-void DocumentL10n::OnCreatePresShell() { mMutations->OnCreatePresShell(); }
\ No newline at end of file
+void DocumentL10n::OnCreatePresShell() { mMutations->OnCreatePresShell(); }