Bug 618344 - Web Console pprint() command should display something useful for functions; f=rcampbell r=sdwilsh a=gavin.sharp

This commit is contained in:
Mihai Sucan 2011-01-04 11:31:48 -06:00
parent bf37e8952f
commit f421f55a98
2 changed files with 16 additions and 0 deletions

View File

@ -215,6 +215,9 @@ const MINIMUM_PAGE_HEIGHT = 50;
// The default console height, as a ratio from the content window inner height. // The default console height, as a ratio from the content window inner height.
const DEFAULT_CONSOLE_HEIGHT = 0.33; const DEFAULT_CONSOLE_HEIGHT = 0.33;
// Constant used when checking the typeof objects.
const TYPEOF_FUNCTION = "function";
const ERRORS = { LOG_MESSAGE_MISSING_ARGS: const ERRORS = { LOG_MESSAGE_MISSING_ARGS:
"Missing arguments: aMessage, aConsoleNode and aMessageNode are required.", "Missing arguments: aMessage, aConsoleNode and aMessageNode are required.",
CANNOT_GET_HUD: "Cannot getHeads Up Display with provided ID", CANNOT_GET_HUD: "Cannot getHeads Up Display with provided ID",
@ -3682,6 +3685,11 @@ function JSTermHelper(aJSTerm)
aJSTerm.console.error(HUDService.getStr("helperFuncUnsupportedTypeError")); aJSTerm.console.error(HUDService.getStr("helperFuncUnsupportedTypeError"));
return; return;
} }
else if (typeof aObject === TYPEOF_FUNCTION) {
aJSTerm.writeOutput(aObject + "\n", CATEGORY_OUTPUT, SEVERITY_LOG);
return;
}
let output = []; let output = [];
let pairs = namesAndValuesOf(unwrap(aObject)); let pairs = namesAndValuesOf(unwrap(aObject));

View File

@ -23,6 +23,7 @@
* Julian Viereck <jviereck@mozilla.com> * Julian Viereck <jviereck@mozilla.com>
* Patrick Walton <pcwalton@mozilla.com> * Patrick Walton <pcwalton@mozilla.com>
* Rob Campbell <rcampbell@mozilla.com> * Rob Campbell <rcampbell@mozilla.com>
* Mihai Șucan <mihai.sucan@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -145,5 +146,12 @@ function testJSTerm()
let label = jsterm.outputNode.querySelector(".webconsole-msg-output"); let label = jsterm.outputNode.querySelector(".webconsole-msg-output");
is(label.textContent.trim(), '0: "h"\n 1: "i"', 'pprint("hi") worked'); is(label.textContent.trim(), '0: "h"\n 1: "i"', 'pprint("hi") worked');
// check that pprint(function) shows function source, bug 618344
jsterm.clearOutput();
jsterm.execute("pprint(print)");
label = jsterm.outputNode.querySelector(".webconsole-msg-output");
isnot(label.textContent.indexOf("SEVERITY_LOG"), -1,
"pprint(function) shows function source");
finishTest(); finishTest();
} }