Bug 605419 - [Web Console] Provide a help command to list the available helper functions; r=gavin.sharp approval2.0=gavin.sharp

This commit is contained in:
Joe Walker 2010-11-02 12:58:37 +00:00
parent c8bb8de65f
commit 0369dc2d88
2 changed files with 26 additions and 0 deletions

View File

@ -3910,6 +3910,16 @@ function JSTermHelper(aJSTerm)
return arrValues;
};
/**
* Opens a help window in MDC
*/
aJSTerm.sandbox.help = function JSTH_help()
{
aJSTerm._window.open(
"https://developer.mozilla.org/AppLinks/WebConsoleHelp?locale=" +
aJSTerm._window.navigator.language, "help", "");
};
/**
* Inspects the passed aObject. This is done by opening the PropertyPanel.
*
@ -4052,6 +4062,10 @@ JSTerm.prototype = {
*/
evalInSandbox: function JST_evalInSandbox(aString)
{
// The help function needs to be easy to guess, so we make the () optional
if (aString.trim() === "help" || aString.trim() === "?") {
aString = "help()";
}
return Cu.evalInSandbox(aString, this.sandbox, "1.8", "Web Console", 1);
},

View File

@ -92,6 +92,18 @@ function testJSTerm()
jsterm.execute("'valuesResult=' + (values({b:1})[0] == 1)");
checkResult("valuesResult=true", "values() worked", 1);
jsterm.clearOutput();
jsterm.execute("help()");
checkResult("undefined", "help() worked", 1);
jsterm.clearOutput();
jsterm.execute("help");
checkResult("undefined", "help() worked", 1);
jsterm.clearOutput();
jsterm.execute("?");
checkResult("undefined", "help() worked", 1);
jsterm.clearOutput();
jsterm.execute("pprint({b:2, a:1})");
// Doesn't conform to checkResult format