Bug 899218 - Scratchpad doesn't handle long strings. r=robcee

This commit is contained in:
Brandon Benvie 2013-07-30 16:27:44 -07:00
parent 093efb8f77
commit 6c57206ed4
3 changed files with 69 additions and 4 deletions

View File

@ -419,8 +419,7 @@ var Scratchpad = {
this.writeAsErrorComment(aError.exception).then(resolve, reject); this.writeAsErrorComment(aError.exception).then(resolve, reject);
} }
else if (VariablesView.isPrimitive({ value: aResult })) { else if (VariablesView.isPrimitive({ value: aResult })) {
this.writeAsComment(aResult.type || aResult); this._writePrimitiveAsComment(aResult).then(resolve, reject);
resolve();
} }
else { else {
this.deselect(); this.deselect();
@ -488,13 +487,13 @@ var Scratchpad = {
this.writeAsErrorComment(aError.exception).then(resolve, reject); this.writeAsErrorComment(aError.exception).then(resolve, reject);
} }
else if (VariablesView.isPrimitive({ value: aResult })) { else if (VariablesView.isPrimitive({ value: aResult })) {
this.writeAsComment(aResult.type || aResult); this._writePrimitiveAsComment(aResult).then(resolve, reject);
resolve();
} }
else { else {
let gripClient = new GripClient(this.debuggerClient, aResult); let gripClient = new GripClient(this.debuggerClient, aResult);
gripClient.getDisplayString(aResponse => { gripClient.getDisplayString(aResponse => {
if (aResponse.error) { if (aResponse.error) {
reportError("display", aResponse);
reject(aResponse); reject(aResponse);
} }
else { else {
@ -513,6 +512,41 @@ var Scratchpad = {
return deferred.promise; 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. * Write out a value at the next line from the current insertion point.
* The comment block will always be preceded by a newline character. * The comment block will always be preceded by a newline character.

View File

@ -37,6 +37,7 @@ MOCHITEST_BROWSER_FILES = \
browser_scratchpad_bug_661762_wrong_window_focus.js \ browser_scratchpad_bug_661762_wrong_window_focus.js \
browser_scratchpad_bug_644413_modeline.js \ browser_scratchpad_bug_644413_modeline.js \
browser_scratchpad_bug807924_cannot_convert_to_string.js \ browser_scratchpad_bug807924_cannot_convert_to_string.js \
browser_scratchpad_long_string.js \
head.js \ head.js \
# Disable test due to bug 807234 becoming basically permanent # Disable test due to bug 807234 becoming basically permanent

View File

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