Bug 1148770 - Wait for asynchronous operations to complete before resolving in StyleSheetEditor.fetchSource. r=ejpbruel, a=test-only
authorSami Jaktholm <sjakthol@outlook.com>
Wed, 01 Apr 2015 06:41:28 +0300
changeset 266913 4f37bababbe18169a2439db700be7037e412dcab
parent 266912 df2609b5415a448f1a6af276b9d96fe0ea8529bf
child 266914 5662b0aa70fbbde619bdb9e530ca559a9b34b92c
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersejpbruel, test-only
bugs1148770
milestone39.0a2
Bug 1148770 - Wait for asynchronous operations to complete before resolving in StyleSheetEditor.fetchSource. r=ejpbruel, a=test-only
browser/devtools/styleeditor/StyleSheetEditor.jsm
--- a/browser/devtools/styleeditor/StyleSheetEditor.jsm
+++ b/browser/devtools/styleeditor/StyleSheetEditor.jsm
@@ -232,42 +232,34 @@ StyleSheetEditor.prototype = {
       this._fileModDate = info.lastModificationDate.getTime();
     }, this.markLinkedFileBroken);
 
     this.emit("linked-css-file");
   },
 
   /**
    * Start fetching the full text source for this editor's sheet.
+   *
+   * @return {Promise}
+   *         A promise that'll resolve with the source text once the source
+   *         has been loaded or reject on unexpected error.
    */
-  fetchSource: function(callback) {
-    return this.styleSheet.getText().then((longStr) => {
-      longStr.string().then((source) => {
-        let ruleCount = this.styleSheet.ruleCount;
-        if (!this.styleSheet.isOriginalSource) {
-          source = CssLogic.prettifyCSS(source, ruleCount);
-        }
-        this._state.text = source;
-        this.sourceLoaded = true;
+  fetchSource: function () {
+    return Task.spawn(function* () {
+      let longStr = yield this.styleSheet.getText();
+      let source = yield longStr.string();
+      let ruleCount = this.styleSheet.ruleCount;
+      if (!this.styleSheet.isOriginalSource) {
+        source = CssLogic.prettifyCSS(source, ruleCount);
+      }
+      this._state.text = source;
+      this.sourceLoaded = true;
 
-        if (callback) {
-          callback(source);
-        }
-        return source;
-      }, e => {
-        if (this._isDestroyed) {
-          console.warn("Could not fetch the source for " +
-                       this.styleSheet.href +
-                       ", the editor was destroyed");
-          Cu.reportError(e);
-        } else {
-          throw e;
-        }
-      });
-    }, e => {
+      return source;
+    }.bind(this)).then(null, e => {
       if (this._isDestroyed) {
         console.warn("Could not fetch the source for " +
                      this.styleSheet.href +
                      ", the editor was destroyed");
         Cu.reportError(e);
       } else {
         this.emit("error", { key: LOAD_ERROR, append: this.styleSheet.href });
         throw e;