bug 788754: simplify SourceClient's api; r=past
authorNick Fitzgerald <fitzgen@gmail.com>
Fri, 28 Sep 2012 08:27:00 +0300
changeset 109264 d2850363666b163d6b8833f90974d1e65cc5c838
parent 109263 ac84886e4d05a6effd913d3f778d2ba981c6c3ae
child 109265 b3a19d36344ae51b7a7985873a53bf69acbefc4b
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerspast
bugs788754
milestone18.0a1
bug 788754: simplify SourceClient's api; r=past
browser/devtools/debugger/debugger-controller.js
toolkit/devtools/debugger/dbg-client.jsm
toolkit/devtools/debugger/tests/unit/test_source-01.js
--- a/browser/devtools/debugger/debugger-controller.js
+++ b/browser/devtools/debugger/debugger-controller.js
@@ -1267,38 +1267,19 @@ SourceScripts.prototype = {
     let options = aEvent.detail.options;
 
     let sourceClient = this.activeThread.source(script.source);
     sourceClient.source(function (aResponse) {
       if (aResponse.error) {
         return this._logError(script.url, -1);
       }
 
-      if (typeof aResponse.source === "string") {
-        // We did not receive a long string, instead we got the source directly.
-        this._onLoadSourceFinished(script.url,
-                                   aResponse.source,
-                                   options);
-        return;
-      }
-
-      if (aResponse.source.type !== "longString") {
-        return this._logError(script.url, -1);
-      }
-
-      let sourceTextClient = this.activeThread.threadLongString(aResponse.source);
-      let length = sourceTextClient.length;
-      sourceTextClient.substring(0, length, function (aResponse) {
-        if (aResponse.error) {
-          return this._logError(script.url, -1);
-        }
-        this._onLoadSourceFinished(script.url,
-                                   aResponse.substring,
-                                   options);
-      }.bind(this));
+      this._onLoadSourceFinished(script.url,
+                                 aResponse.source,
+                                 options);
     }.bind(this));
   },
 
   /**
    * Called when a script's source has been loaded.
    *
    * @private
    * @param string aScriptUrl
--- a/toolkit/devtools/debugger/dbg-client.jsm
+++ b/toolkit/devtools/debugger/dbg-client.jsm
@@ -1110,17 +1110,40 @@ SourceClient.prototype = {
   /**
    * Get a long string grip for this SourceClient's source.
    */
   source: function SC_source(aCallback) {
     let packet = {
       to: this._actor,
       type: "source"
     };
-    this._client.request(packet, aCallback);
+    this._client.request(packet, function (aResponse) {
+      if (aResponse.error) {
+        aCallback(aResponse);
+        return;
+      }
+
+      if (typeof aResponse.source === "string") {
+        aCallback(aResponse);
+        return;
+      }
+
+      let longString = this._client.activeThread.threadLongString(
+        aResponse.source);
+      longString.substring(0, longString.length, function (aResponse) {
+        if (aResponse.error) {
+          aCallback(aResponse);
+          return;
+        }
+
+        aCallback({
+          source: aResponse.substring
+        });
+      });
+    }.bind(this));
   }
 };
 
 /**
  * Breakpoint clients are used to remove breakpoints that are no longer used.
  *
  * @param aClient DebuggerClient
  *        The debugger client parent.
--- a/toolkit/devtools/debugger/tests/unit/test_source-01.js
+++ b/toolkit/devtools/debugger/tests/unit/test_source-01.js
@@ -52,36 +52,26 @@ function test_source()
       do_check_true(!!script.source);
 
       let sourceClient = gThreadClient.source(script.source);
       sourceClient.source(function (aResponse) {
         do_check_true(!!aResponse);
         do_check_true(!aResponse.error);
         do_check_true(!!aResponse.source);
 
-        let source = aResponse.source;
-        do_check_eq(source.type, "longString");
-
-        let sourceStringClient = gThreadClient.threadLongString(source);
-        let len = sourceStringClient.length;
-        sourceStringClient.substring(0, len, function (aResponse) {
-          do_check_true(!!aResponse);
-          do_check_true(!!aResponse.substring);
+        let f = do_get_file("test_source-01.js", false);
+        let s = Cc["@mozilla.org/network/file-input-stream;1"]
+          .createInstance(Ci.nsIFileInputStream);
+        s.init(f, -1, -1, false);
 
-          let f = do_get_file("test_source-01.js", false);
-          let s = Cc["@mozilla.org/network/file-input-stream;1"]
-            .createInstance(Ci.nsIFileInputStream);
-          s.init(f, -1, -1, false);
+        do_check_eq(NetUtil.readInputStreamToString(s, s.available()),
+                    aResponse.source);
 
-          do_check_eq(NetUtil.readInputStreamToString(s, s.available()),
-                      aResponse.substring);
-
-          s.close();
-          gThreadClient.resume(function () {
-            finishClient(gClient);
-          });
+        s.close();
+        gThreadClient.resume(function () {
+          finishClient(gClient);
         });
       });
     });
   });
 
   gDebuggee.eval('stopMe()');
 }