Bug 899218 - Scratchpad doesn't handle long strings. r=robcee
authorBrandon Benvie <bbenvie@mozilla.com>
Tue, 30 Jul 2013 16:27:44 -0700
changeset 140727 6f9c07973a399c5e453c7cc2597d066e29a2ffee
parent 140726 e2ac4f906a29740a71d7407a945edca23478e0e5
child 140728 46668a08f3e4e8891acd27687d3a17367b6fee36
push id25036
push useremorley@mozilla.com
push dateWed, 31 Jul 2013 12:02:58 +0000
treeherdermozilla-central@ffd57aa81b5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs899218
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 899218 - Scratchpad doesn't handle long strings. r=robcee
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/test/Makefile.in
browser/devtools/scratchpad/test/browser_scratchpad_long_string.js
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -414,18 +414,17 @@ var Scratchpad = {
 
     this.execute().then(([aString, aError, aResult]) => {
       let resolve = () => deferred.resolve([aString, aError, aResult]);
 
       if (aError) {
         this.writeAsErrorComment(aError.exception).then(resolve, reject);
       }
       else if (VariablesView.isPrimitive({ value: aResult })) {
-        this.writeAsComment(aResult.type || aResult);
-        resolve();
+        this._writePrimitiveAsComment(aResult).then(resolve, reject);
       }
       else {
         this.deselect();
         this.sidebar.open(aString, aResult).then(resolve, reject);
       }
     }, reject);
 
     return deferred.promise;
@@ -483,23 +482,23 @@ var Scratchpad = {
 
     this.execute().then(([aString, aError, aResult]) => {
       let resolve = () => deferred.resolve([aString, aError, aResult]);
 
       if (aError) {
         this.writeAsErrorComment(aError.exception).then(resolve, reject);
       }
       else if (VariablesView.isPrimitive({ value: aResult })) {
-        this.writeAsComment(aResult.type || aResult);
-        resolve();
+        this._writePrimitiveAsComment(aResult).then(resolve, reject);
       }
       else {
         let gripClient = new GripClient(this.debuggerClient, aResult);
         gripClient.getDisplayString(aResponse => {
           if (aResponse.error) {
+            reportError("display", aResponse);
             reject(aResponse);
           }
           else {
             let string = aResponse.displayString;
             if (string && string.type == "null") {
               string = "Exception: " +
                        this.strings.GetStringFromName("stringConversionFailed");
             }
@@ -509,16 +508,51 @@ var Scratchpad = {
         });
       }
     }, reject);
 
     return deferred.promise;
   },
 
   /**
+   * Writes out a primitive value as a comment. This handles values which are
+   * to be printed directly (number, string) as well as grips to values
+   * (null, undefined, longString).
+   *
+   * @param any aValue
+   *        The value to print.
+   * @return Promise
+   *         The promise that resolves after the value has been printed.
+   */
+  _writePrimitiveAsComment: function SP__writePrimitiveAsComment(aValue)
+  {
+    let deferred = promise.defer();
+
+    if (aValue.type == "longString") {
+      let client = this.webConsoleClient;
+      client.longString(aValue).substring(0, aValue.length, aResponse => {
+        if (aResponse.error) {
+          reportError("display", aResponse);
+          deferred.reject(aResponse);
+        }
+        else {
+          deferred.resolve(aResponse.substring);
+        }
+      });
+    }
+    else {
+      deferred.resolve(aValue.type || aValue);
+    }
+
+    return deferred.promise.then(aComment => {
+      this.writeAsComment(aComment);
+    });
+  },
+
+  /**
    * Write out a value at the next line from the current insertion point.
    * The comment block will always be preceded by a newline character.
    * @param object aValue
    *        The Object to write out as a string
    */
   writeAsComment: function SP_writeAsComment(aValue)
   {
     let selection = this.getSelectionRange();
--- a/browser/devtools/scratchpad/test/Makefile.in
+++ b/browser/devtools/scratchpad/test/Makefile.in
@@ -32,14 +32,15 @@ MOCHITEST_BROWSER_FILES = \
 		browser_scratchpad_bug_650760_help_key.js \
 		browser_scratchpad_bug_651942_recent_files.js \
 		browser_scratchpad_bug756681_display_non_error_exceptions.js \
 		browser_scratchpad_bug_751744_revert_to_saved.js \
 		browser_scratchpad_bug740948_reload_and_run.js \
 		browser_scratchpad_bug_661762_wrong_window_focus.js \
 		browser_scratchpad_bug_644413_modeline.js \
 		browser_scratchpad_bug807924_cannot_convert_to_string.js \
+		browser_scratchpad_long_string.js \
 		head.js \
 
 # Disable test due to bug 807234 becoming basically permanent
 #		browser_scratchpad_bug_653427_confirm_close.js \
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/browser/devtools/scratchpad/test/browser_scratchpad_long_string.js
@@ -0,0 +1,30 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test()
+{
+  waitForExplicitFinish();
+
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
+    gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
+    openScratchpad(runTests);
+  }, true);
+
+  content.location = "data:text/html;charset=utf8,<p>test long string in Scratchpad</p>";
+}
+
+function runTests()
+{
+  let sp = gScratchpadWindow.Scratchpad;
+
+  sp.setText("'0'.repeat(10000)");
+
+  sp.display().then(() => {
+    is(sp.getText(), "'0'.repeat(10000)\n" +
+                     "/*\n" + "0".repeat(10000) + "\n*/",
+       "display()ing a long string works");
+    finish();
+  });
+}