mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-09 13:25:00 +00:00
Bug 785134 - Update jsb to fix various bugs; r=jwalker
This commit is contained in:
parent
85b551d51c
commit
eaaa95f782
@ -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,13 @@ 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);
|
||||
|
||||
browserWindow.Scratchpad.ScratchpadManager.openScratchpad({text: result});
|
||||
|
||||
promise.resolve();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
promise.resolve("Unable to load page to beautify: " + args.url + " " +
|
||||
xhr.status + " " + xhr.statusText);
|
||||
}
|
||||
|
@ -34,3 +34,6 @@
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.gcli-row-out .nowrap {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
@ -6,52 +6,68 @@
|
||||
const TEST_URI = "http://example.com/browser/browser/devtools/commandline/" +
|
||||
"test/browser_cmd_jsb_script.jsi";
|
||||
|
||||
let scratchpadWin = null;
|
||||
let Scratchpad = null;
|
||||
|
||||
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'
|
||||
});
|
||||
DeveloperToolbarTest.exec({ completed: false });
|
||||
|
||||
gBrowser.addTabsProgressListener({
|
||||
onProgressChange: DeveloperToolbarTest.checkCalled(function GJT_onProgressChange(aBrowser) {
|
||||
gBrowser.removeTabsProgressListener(this);
|
||||
Services.ww.registerNotification(function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "domwindowopened") {
|
||||
Services.ww.unregisterNotification(arguments.callee);
|
||||
|
||||
let win = aBrowser._contentWindow;
|
||||
let uri = win.document.location.href;
|
||||
let result = win.atob(uri.replace(/.*,/, ""));
|
||||
scratchpadWin = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
||||
scratchpadWin.addEventListener("load", function GDT_onLoad() {
|
||||
scratchpadWin.removeEventListener("load", GDT_onLoad, false);
|
||||
Scratchpad = scratchpadWin.Scratchpad;
|
||||
|
||||
result = result.replace(/[\r\n]]/g, "\n");
|
||||
let observer = {
|
||||
onReady: function GJT_onReady() {
|
||||
Scratchpad.removeObserver(observer);
|
||||
|
||||
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" +
|
||||
" }\n" +
|
||||
"}";
|
||||
is(result, correct, "JS has been correctly prettified");
|
||||
})
|
||||
});
|
||||
let result = Scratchpad.getText();
|
||||
result = result.replace(/[\r\n]]*/g, "\n");
|
||||
let correct = "function somefunc() {\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");
|
||||
|
||||
finishUp();
|
||||
},
|
||||
};
|
||||
Scratchpad.addObserver(observer);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
info("Checking beautification");
|
||||
|
||||
helpers.setInput('jsb ' + TEST_URI);
|
||||
/*
|
||||
helpers.check({
|
||||
input: 'jsb',
|
||||
hints: ' [options]',
|
||||
markup: 'VVV',
|
||||
status: 'VALID'
|
||||
DeveloperToolbarTest.exec({
|
||||
typed: "jsb " + TEST_URI,
|
||||
completed: false
|
||||
});
|
||||
*/
|
||||
|
||||
DeveloperToolbarTest.exec({ completed: false });
|
||||
}
|
||||
|
||||
let finishUp = DeveloperToolbarTest.checkCalled(function GJT_finishUp() {
|
||||
if (scratchpadWin) {
|
||||
scratchpadWin.close();
|
||||
scratchpadWin = null;
|
||||
}
|
||||
});
|
||||
|
@ -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
@ -817,11 +817,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
|
||||
@ -854,23 +853,18 @@ jsbJslintHappyManual=When set to true, jslint-stricter mode is enforced
|
||||
# 'jsb <braceStyle>' 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.
|
||||
jsbBraceStyleDesc=Collapse, expand, end-expand, expand-strict
|
||||
jsbBraceStyleDesc=Select the coding style of braces
|
||||
|
||||
# LOCALIZATION NOTE (jsbBraceStyleManual) A fuller description of the
|
||||
# 'jsb <braceStyle>' parameter, displayed when the user asks for help
|
||||
# on what it does.
|
||||
jsbBraceStyleManual=The coding style of braces. Either collapse, expand, end-expand or expand-strict
|
||||
jsbBraceStyleManual=<p class="nowrap">The coding style of braces. Select from one of the following:</p><ul><li>collapse<br/><pre>if (x == 1) {\n ...\n} else {\n ...\n}</pre></li><li>expand<br/><pre>if (x == 1)\n{\n ...\n}\nelse\n{\n ...\n}</pre></li><li>end-expand<br/><pre>if (x == 1) {\n ...\n}\nelse {\n ...\n}</pre></li><li>expand-strict<br/><pre>if (x == 1)\n{\n return // This option can break scripts\n {\n a: 1\n };\n} else {\n ...\n}</pre></li></ul>
|
||||
|
||||
# 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
|
||||
@ -887,6 +881,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.
|
||||
|
@ -63,10 +63,15 @@
|
||||
.gcli-row-out h4,
|
||||
.gcli-row-out h5,
|
||||
.gcli-row-out th,
|
||||
.gcli-row-out strong {
|
||||
.gcli-row-out strong,
|
||||
.gcli-row-out pre {
|
||||
color: hsl(210,30%,95%);
|
||||
}
|
||||
|
||||
.gcli-row-out pre {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.gcli-out-shortcut,
|
||||
.gcli-help-synopsis {
|
||||
padding: 0 3px;
|
||||
|
@ -65,10 +65,15 @@
|
||||
.gcli-row-out h4,
|
||||
.gcli-row-out h5,
|
||||
.gcli-row-out th,
|
||||
.gcli-row-out strong {
|
||||
.gcli-row-out strong,
|
||||
.gcli-row-out pre {
|
||||
color: hsl(210,30%,95%);
|
||||
}
|
||||
|
||||
.gcli-row-out pre {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.gcli-out-shortcut,
|
||||
.gcli-help-synopsis {
|
||||
padding: 0 3px;
|
||||
|
@ -63,10 +63,15 @@
|
||||
.gcli-row-out h4,
|
||||
.gcli-row-out h5,
|
||||
.gcli-row-out th,
|
||||
.gcli-row-out strong {
|
||||
.gcli-row-out strong,
|
||||
.gcli-row-out pre {
|
||||
color: hsl(210,30%,95%);
|
||||
}
|
||||
|
||||
.gcli-row-out pre {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.gcli-out-shortcut,
|
||||
.gcli-help-synopsis {
|
||||
padding: 0 3px;
|
||||
|
Loading…
Reference in New Issue
Block a user