Bug 1455048 - Revert the workaround added to Fluent for microtasks bug. r?mossop draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Wed, 18 Apr 2018 11:05:19 -0700
changeset 784513 86e99fbac5ad4956885c4a8f2d7a9f145aa53295
parent 783746 5ded36cb383d3ccafd9b6c231c5120dcdae196a2
push id106952
push userbmo:gandalf@aviary.pl
push dateWed, 18 Apr 2018 18:05:58 +0000
reviewersmossop
bugs1455048
milestone61.0a1
Bug 1455048 - Revert the workaround added to Fluent for microtasks bug. r?mossop MozReview-Commit-ID: AFpNRPfJpm7
intl/l10n/l10n.js
--- a/intl/l10n/l10n.js
+++ b/intl/l10n/l10n.js
@@ -1,45 +1,36 @@
 {
   const { DOMLocalization } =
     ChromeUtils.import("resource://gre/modules/DOMLocalization.jsm", {});
 
   /**
    * Polyfill for document.ready polyfill.
    * See: https://github.com/whatwg/html/issues/127 for details.
    *
-   * XXX: The callback is a temporary workaround for bug 1193394. Once Promises in Gecko
-   *      start beeing a microtask and stop pushing translation post-layout, we can
-   *      remove it and start using the returned Promise again.
-   *
-   * @param {Function} callback - function to be called when the document is ready.
    * @returns {Promise}
    */
-  function documentReady(callback) {
+  function documentReady() {
     if (document.contentType === "application/vnd.mozilla.xul+xml") {
       // XUL
       return new Promise(
         resolve => document.addEventListener(
-          "MozBeforeInitialXULLayout", () => {
-            resolve(callback());
-          }, { once: true }
+          "MozBeforeInitialXULLayout", resolve, { once: true }
         )
       );
     }
 
     // HTML
     const rs = document.readyState;
     if (rs === "interactive" || rs === "completed") {
-      return Promise.resolve(callback);
+      return Promise.resolve();
     }
     return new Promise(
       resolve => document.addEventListener(
-        "readystatechange", () => {
-          resolve(callback());
-        }, { once: true }
+        "readystatechange", resolve, { once: true }
       )
     );
   }
 
   /**
    * Scans the `elem` for links with localization resources.
    *
    * @param {Element} elem
@@ -53,14 +44,14 @@
 
   const resourceIds = getResourceLinks(document.head || document);
 
   document.l10n = new DOMLocalization(window, resourceIds);
 
   // trigger first context to be fetched eagerly
   document.l10n.ctxs.touchNext();
 
-  document.l10n.ready = documentReady(() => {
+  document.l10n.ready = documentReady().then(() => {
     document.l10n.registerObservers();
     document.l10n.connectRoot(document.documentElement);
     return document.l10n.translateRoots();
   });
 }