From 6c57206ed415fdd5359f727fdce9d52d59415b56 Mon Sep 17 00:00:00 2001 From: Brandon Benvie Date: Tue, 30 Jul 2013 16:27:44 -0700 Subject: [PATCH] Bug 899218 - Scratchpad doesn't handle long strings. r=robcee --- browser/devtools/scratchpad/scratchpad.js | 42 +++++++++++++++++-- browser/devtools/scratchpad/test/Makefile.in | 1 + .../test/browser_scratchpad_long_string.js | 30 +++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 browser/devtools/scratchpad/test/browser_scratchpad_long_string.js diff --git a/browser/devtools/scratchpad/scratchpad.js b/browser/devtools/scratchpad/scratchpad.js index a1f134ae648..47d9bcc5a96 100644 --- a/browser/devtools/scratchpad/scratchpad.js +++ b/browser/devtools/scratchpad/scratchpad.js @@ -419,8 +419,7 @@ var Scratchpad = { 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(); @@ -488,13 +487,13 @@ var Scratchpad = { 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 { @@ -513,6 +512,41 @@ var Scratchpad = { 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. diff --git a/browser/devtools/scratchpad/test/Makefile.in b/browser/devtools/scratchpad/test/Makefile.in index 76945eb013f..570b79737dc 100644 --- a/browser/devtools/scratchpad/test/Makefile.in +++ b/browser/devtools/scratchpad/test/Makefile.in @@ -37,6 +37,7 @@ MOCHITEST_BROWSER_FILES = \ 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 diff --git a/browser/devtools/scratchpad/test/browser_scratchpad_long_string.js b/browser/devtools/scratchpad/test/browser_scratchpad_long_string.js new file mode 100644 index 00000000000..d85a7df1cb5 --- /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,

test long string in Scratchpad

"; +} + +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(); + }); +}