Bug 785134 - Update jsb to fix various bugs. r=jwalker

This commit is contained in:
Michael Ratcliffe 2012-09-24 14:36:41 +01:00
parent d502515f9b
commit 83dcc5791e
5 changed files with 1306 additions and 1323 deletions

View File

@ -28,79 +28,82 @@ gcli.addCommand({
description: gcli.lookup('jsbUrlDesc')
},
{
name: 'indentSize',
type: 'number',
description: gcli.lookup('jsbIndentSizeDesc'),
manual: gcli.lookup('jsbIndentSizeManual'),
defaultValue: 2
},
{
name: 'indentChar',
type: {
name: 'selection',
lookup: [
{ name: "space", value: " " },
{ name: "tab", value: "\t" }
]
},
description: gcli.lookup('jsbIndentCharDesc'),
manual: gcli.lookup('jsbIndentCharManual'),
defaultValue: ' ',
},
{
name: 'preserveNewlines',
type: 'boolean',
description: gcli.lookup('jsbPreserveNewlinesDesc'),
manual: gcli.lookup('jsbPreserveNewlinesManual')
},
{
name: 'preserveMaxNewlines',
type: 'number',
description: gcli.lookup('jsbPreserveMaxNewlinesDesc'),
manual: gcli.lookup('jsbPreserveMaxNewlinesManual'),
defaultValue: -1
},
{
name: 'jslintHappy',
type: 'boolean',
description: gcli.lookup('jsbJslintHappyDesc'),
manual: gcli.lookup('jsbJslintHappyManual')
},
{
name: 'braceStyle',
type: {
name: 'selection',
data: ['collapse', 'expand', 'end-expand', 'expand-strict']
},
description: gcli.lookup('jsbBraceStyleDesc'),
manual: gcli.lookup('jsbBraceStyleManual'),
defaultValue: "collapse"
},
{
name: 'spaceBeforeConditional',
type: 'boolean',
description: gcli.lookup('jsbSpaceBeforeConditionalDesc'),
manual: gcli.lookup('jsbSpaceBeforeConditionalManual')
},
{
name: 'unescapeStrings',
type: 'boolean',
description: gcli.lookup('jsbUnescapeStringsDesc'),
manual: gcli.lookup('jsbUnescapeStringsManual')
group: gcli.lookup("jsbOptionsDesc"),
params: [
{
name: 'indentSize',
type: 'number',
description: gcli.lookup('jsbIndentSizeDesc'),
manual: gcli.lookup('jsbIndentSizeManual'),
defaultValue: 2
},
{
name: 'indentChar',
type: {
name: 'selection',
lookup: [
{ name: "space", value: " " },
{ name: "tab", value: "\t" }
]
},
description: gcli.lookup('jsbIndentCharDesc'),
manual: gcli.lookup('jsbIndentCharManual'),
defaultValue: ' ',
},
{
name: 'doNotPreserveNewlines',
type: 'boolean',
description: gcli.lookup('jsbDoNotPreserveNewlinesDesc')
},
{
name: 'preserveMaxNewlines',
type: 'number',
description: gcli.lookup('jsbPreserveMaxNewlinesDesc'),
manual: gcli.lookup('jsbPreserveMaxNewlinesManual'),
defaultValue: -1
},
{
name: 'jslintHappy',
type: 'boolean',
description: gcli.lookup('jsbJslintHappyDesc'),
manual: gcli.lookup('jsbJslintHappyManual')
},
{
name: 'braceStyle',
type: {
name: 'selection',
data: ['collapse', 'expand', 'end-expand', 'expand-strict']
},
description: gcli.lookup('jsbBraceStyleDesc'),
manual: gcli.lookup('jsbBraceStyleManual'),
defaultValue: "collapse"
},
{
name: 'noSpaceBeforeConditional',
type: 'boolean',
description: gcli.lookup('jsbNoSpaceBeforeConditionalDesc')
},
{
name: 'unescapeStrings',
type: 'boolean',
description: gcli.lookup('jsbUnescapeStringsDesc'),
manual: gcli.lookup('jsbUnescapeStringsManual')
}
]
}
],
exec: function(args, context) {
let opts = {
indent_size: args.indentSize,
indent_char: args.indentChar,
preserve_newlines: args.preserveNewlines,
preserve_newlines: !args.doNotPreserveNewlines,
max_preserve_newlines: args.preserveMaxNewlines == -1 ?
undefined : args.preserveMaxNewlines,
jslint_happy: args.jslintHappy,
brace_style: args.braceStyle,
space_before_conditional: args.spaceBeforeConditional,
space_before_conditional: !args.noSpaceBeforeConditional,
unescape_strings: args.unescapeStrings
}
};
let xhr = new XMLHttpRequest();
@ -117,13 +120,15 @@ gcli.addCommand({
if (xhr.status == 200 || xhr.status == 0) {
let browserDoc = context.environment.chromeDocument;
let browserWindow = browserDoc.defaultView;
let browser = browserWindow.gBrowser;
browser.selectedTab = browser.addTab("data:text/plain;base64," +
browserWindow.btoa(js_beautify(xhr.responseText, opts)));
let gBrowser = browserWindow.gBrowser;
let result = js_beautify(xhr.responseText, opts);
// FIXME: btoa currently only works with ISO-8859-1
// Remove "unescape(encodeURIComponent(" when Bug 213047 is fixed.
gBrowser.selectedTab = gBrowser.addTab("data:text/plain;base64," +
browserWindow.btoa(unescape(encodeURIComponent(result))));
promise.resolve();
}
else {
} else {
promise.resolve("Unable to load page to beautify: " + args.url + " " +
xhr.status + " " + xhr.statusText);
}

View File

@ -7,14 +7,14 @@ const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" +
"test/browser_cmd_jsb_script.jsi";
function test() {
DeveloperToolbarTest.test("about:blank", [ /*GJT_test*/ ]);
DeveloperToolbarTest.test("about:blank", [ GJT_test ]);
}
function GJT_test() {
helpers.setInput('jsb');
helpers.check({
input: 'jsb',
hints: ' <url> [indentSize] [indentChar] [preserveNewlines] [preserveMaxNewlines] [jslintHappy] [braceStyle] [spaceBeforeConditional] [unescapeStrings]',
hints: ' <url> [options]',
markup: 'VVV',
status: 'ERROR'
});
@ -30,28 +30,21 @@ function GJT_test() {
result = result.replace(/[\r\n]]/g, "\n");
let correct = "function somefunc() {\n" +
" for (let n = 0; n < 500; n++) {\n" +
" if (n % 2 == 1) {\n" +
" console.log(n);\n" +
" console.log(n + 1);\n" +
" }\n" +
" if (true) // Some comment\n" +
" doSomething();\n" +
" for (let n = 0; n < 500; n++) {\n" +
" if (n % 2 == 1) {\n" +
" console.log(n);\n" +
" console.log(n + 1);\n" +
" }\n" +
" }\n" +
"}";
is(result, correct, "JS has been correctly prettified");
})
});
info("Checking beautification");
helpers.setInput('jsb ' + TEST_URI);
/*
helpers.check({
input: 'jsb',
hints: ' [options]',
markup: 'VVV',
status: 'VALID'
});
*/
DeveloperToolbarTest.exec({ completed: false });
}

View File

@ -1 +1,2 @@
function somefunc(){for(let n=0;n<500;n++){if(n%2==1){console.log(n);console.log(n+1);}}}
function somefunc(){if (true) // Some comment
doSomething();for(let n=0;n<500;n++){if(n%2==1){console.log(n);console.log(n+1);}}}

File diff suppressed because it is too large Load Diff

View File

@ -809,11 +809,10 @@ jsbIndentCharDesc=The chars used to indent each line
# does.
jsbIndentCharManual=The chars used to indent each line. The possible choices are space or tab.
# LOCALIZATION NOTE (jsbPreserveNewlinesDesc) A very short description of the
# 'jsb <jsbPreserveNewlines>' parameter. This string is designed to be shown
# in a menu alongside the command name, which is why it should be as short as
# possible.
jsbPreserveNewlinesDesc=Keep existing line breaks?
# the 'jsb <doNotPreserveNewlines>' parameter. This string is designed to be
# shown in a menu alongside the command name, which is why it should be as short
# as possible.
jsbDoNotPreserveNewlinesDesc=Do not preserve line breaks
# LOCALIZATION NOTE (jsbPreserveNewlinesManual) A fuller description of the
# 'jsb <jsbPreserveNewlines>' parameter, displayed when the user asks for help
@ -853,16 +852,11 @@ jsbBraceStyleDesc=Collapse, expand, end-expand, expand-strict
# on what it does.
jsbBraceStyleManual=The coding style of braces. Either collapse, expand, end-expand or expand-strict
# LOCALIZATION NOTE (jsbSpaceBeforeConditionalDesc) A very short description of
# the 'jsb <spaceBeforeConditional>' parameter. This string is designed to be
# shown in a menu alongside the command name, which is why it should be as short
# as possible.
jsbSpaceBeforeConditionalDesc=Space before if statements?
# LOCALIZATION NOTE (jsbSpaceBeforeConditionalManual) A fuller description of
# the 'jsb <spaceBeforeConditional>' parameter, displayed when the user asks for
# help on what it does.
jsbSpaceBeforeConditionalManual=Should a space be added before conditional statements?
# LOCALIZATION NOTE (jsbNoSpaceBeforeConditionalDesc) A very short description
# of the 'jsb <noSpaceBeforeConditional>' parameter. This string is designed to
# be shown in a menu alongside the command name, which is why it should be as
# short as possible.
jsbNoSpaceBeforeConditionalDesc=No space before conditional statements
# LOCALIZATION NOTE (jsbUnescapeStringsDesc) A very short description of the
# 'jsb <unescapeStrings>' parameter. This string is designed to be shown
@ -879,6 +873,10 @@ jsbUnescapeStringsManual=Should printable characters in strings encoded in \\xNN
# the jsb command.
jsbInvalidURL=Please enter a valid URL
# LOCALIZATION NOTE (jsbOptionsDesc) The title of a set of options to
# the 'jsb' command, displayed as a heading to the list of options.
jsbOptionsDesc=Options
# LOCALIZATION NOTE (calllogDesc) A very short description of the
# 'calllog' command. This string is designed to be shown in a menu
# alongside the command name, which is why it should be as short as possible.