mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1314057 - Remove old debugger's breakpoints-button, parser, and scripts-switching tests r=jlast
--HG-- extra : histedit_source : d927c35523b12aa490be9ae44c7555d1b82f4499
This commit is contained in:
parent
d59a8d5878
commit
aa73feb253
@ -167,10 +167,6 @@ uses-unsafe-cpows = true
|
|||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
[browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js]
|
[browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js]
|
||||||
skip-if = e10s # Bug 1093535
|
skip-if = e10s # Bug 1093535
|
||||||
[browser_dbg_breakpoints-button-01.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
[browser_dbg_breakpoints-button-02.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
[browser_dbg_breakpoints-condition-thrown-message.js]
|
[browser_dbg_breakpoints-condition-thrown-message.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
|
@ -121,9 +121,6 @@ support-files =
|
|||||||
[browser_dbg_no-dangling-breakpoints.js]
|
[browser_dbg_no-dangling-breakpoints.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
[browser_dbg_no-page-sources.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_on-pause-raise.js]
|
[browser_dbg_on-pause-raise.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug || os == "linux" # Bug 888811 & bug 891176
|
skip-if = e10s && debug || os == "linux" # Bug 888811 & bug 891176
|
||||||
@ -133,32 +130,6 @@ skip-if = e10s && debug
|
|||||||
[browser_dbg_panel-size.js]
|
[browser_dbg_panel-size.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
[browser_dbg_parser-01.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-02.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-03.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-04.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-05.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-06.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-07.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-08.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-09.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-10.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_parser-11.js]
|
|
||||||
[browser_dbg_parser-computed-name.js]
|
|
||||||
[browser_dbg_parser-function-defaults.js]
|
|
||||||
[browser_dbg_parser-spread-expression.js]
|
|
||||||
[browser_dbg_parser-template-strings.js]
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_pause-exceptions-01.js]
|
[browser_dbg_pause-exceptions-01.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
@ -202,15 +173,6 @@ skip-if = e10s && debug
|
|||||||
[browser_dbg_reload-same-script.js]
|
[browser_dbg_reload-same-script.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
[browser_dbg_scripts-switching-01.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_scripts-switching-02.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_scripts-switching-03.js]
|
|
||||||
uses-unsafe-cpows = true
|
|
||||||
skip-if = e10s && debug
|
|
||||||
[browser_dbg_search-autofill-identifier.js]
|
[browser_dbg_search-autofill-identifier.js]
|
||||||
uses-unsafe-cpows = true
|
uses-unsafe-cpows = true
|
||||||
skip-if = e10s && debug
|
skip-if = e10s && debug
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if the breakpoints toggle button works as advertised.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let options = {
|
|
||||||
source: EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
line: 1
|
|
||||||
};
|
|
||||||
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
|
|
||||||
const gTab = aTab;
|
|
||||||
const gPanel = aPanel;
|
|
||||||
const gDebugger = gPanel.panelWin;
|
|
||||||
const gSources = gDebugger.DebuggerView.Sources;
|
|
||||||
const actions = bindActionCreators(gPanel);
|
|
||||||
const getState = gDebugger.DebuggerController.getState;
|
|
||||||
|
|
||||||
function checkBreakpointsDisabled(isDisabled, total = 3) {
|
|
||||||
let breakpoints = gDebugger.queries.getBreakpoints(getState());
|
|
||||||
|
|
||||||
is(breakpoints.length, total,
|
|
||||||
"Breakpoints should still be set.");
|
|
||||||
is(breakpoints.filter(bp => bp.disabled === isDisabled).length, total,
|
|
||||||
"Breakpoints should be " + (isDisabled ? "disabled" : "enabled") + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.spawn(function* () {
|
|
||||||
yield actions.addBreakpoint({ actor: gSources.values[0], line: 5 });
|
|
||||||
yield actions.addBreakpoint({ actor: gSources.values[1], line: 6 });
|
|
||||||
yield actions.addBreakpoint({ actor: gSources.values[1], line: 7 });
|
|
||||||
yield ensureThreadClientState(gPanel, "resumed");
|
|
||||||
|
|
||||||
gSources.toggleBreakpoints();
|
|
||||||
yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT, 3);
|
|
||||||
checkBreakpointsDisabled(true);
|
|
||||||
|
|
||||||
const finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 3);
|
|
||||||
gSources.toggleBreakpoints();
|
|
||||||
yield waitForDispatch(gPanel, gDebugger.constants.ADD_BREAKPOINT, 3);
|
|
||||||
checkBreakpointsDisabled(false);
|
|
||||||
|
|
||||||
if (gDebugger.gThreadClient.state !== "attached") {
|
|
||||||
yield waitForThreadEvents(gPanel, "resumed");
|
|
||||||
}
|
|
||||||
closeDebuggerAndFinish(gPanel);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if the breakpoints toggle button works as advertised when there are
|
|
||||||
* some breakpoints already disabled.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let options = {
|
|
||||||
source: EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
line: 1
|
|
||||||
};
|
|
||||||
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
|
|
||||||
const gTab = aTab;
|
|
||||||
const gPanel = aPanel;
|
|
||||||
const gDebugger = gPanel.panelWin;
|
|
||||||
const gSources = gDebugger.DebuggerView.Sources;
|
|
||||||
const actions = bindActionCreators(gPanel);
|
|
||||||
const getState = gDebugger.DebuggerController.getState;
|
|
||||||
|
|
||||||
function checkBreakpointsDisabled(isDisabled, total = 3) {
|
|
||||||
let breakpoints = gDebugger.queries.getBreakpoints(getState());
|
|
||||||
|
|
||||||
is(breakpoints.length, total,
|
|
||||||
"Breakpoints should still be set.");
|
|
||||||
is(breakpoints.filter(bp => bp.disabled === isDisabled).length, total,
|
|
||||||
"Breakpoints should be " + (isDisabled ? "disabled" : "enabled") + ".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.spawn(function* () {
|
|
||||||
yield promise.all([
|
|
||||||
actions.addBreakpoint({ actor: gSources.values[0], line: 5 }),
|
|
||||||
actions.addBreakpoint({ actor: gSources.values[1], line: 6 }),
|
|
||||||
actions.addBreakpoint({ actor: gSources.values[1], line: 7 })
|
|
||||||
]);
|
|
||||||
if (gDebugger.gThreadClient.state !== "attached") {
|
|
||||||
yield waitForThreadEvents(gPanel, "resumed");
|
|
||||||
}
|
|
||||||
|
|
||||||
yield promise.all([
|
|
||||||
actions.disableBreakpoint({ actor: gSources.values[0], line: 5 }),
|
|
||||||
actions.disableBreakpoint({ actor: gSources.values[1], line: 6 })
|
|
||||||
]);
|
|
||||||
|
|
||||||
gSources.toggleBreakpoints();
|
|
||||||
yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT, 1);
|
|
||||||
checkBreakpointsDisabled(true);
|
|
||||||
|
|
||||||
gSources.toggleBreakpoints();
|
|
||||||
yield waitForDispatch(gPanel, gDebugger.constants.ADD_BREAKPOINT, 3);
|
|
||||||
checkBreakpointsDisabled(false);
|
|
||||||
|
|
||||||
if (gDebugger.gThreadClient.state !== "attached") {
|
|
||||||
yield waitForThreadEvents(gPanel, "resumed");
|
|
||||||
}
|
|
||||||
closeDebuggerAndFinish(gPanel);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure the right text shows when the page has no sources.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_no-page-sources.html";
|
|
||||||
|
|
||||||
var gTab, gDebuggee, gPanel, gDebugger;
|
|
||||||
var gEditor, gSources;
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
initDebugger(TAB_URL, { source: null }).then(([aTab, aDebuggee, aPanel]) => {
|
|
||||||
gTab = aTab;
|
|
||||||
gDebuggee = aDebuggee;
|
|
||||||
gPanel = aPanel;
|
|
||||||
gDebugger = gPanel.panelWin;
|
|
||||||
gEditor = gDebugger.DebuggerView.editor;
|
|
||||||
gSources = gDebugger.DebuggerView.Sources;
|
|
||||||
const constants = gDebugger.require("./content/constants");
|
|
||||||
|
|
||||||
reloadActiveTab(gPanel);
|
|
||||||
waitForNavigation(gPanel)
|
|
||||||
.then(testSourcesEmptyText)
|
|
||||||
.then(() => closeDebuggerAndFinish(gPanel))
|
|
||||||
.catch(aError => {
|
|
||||||
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSourcesEmptyText() {
|
|
||||||
is(gSources.itemCount, 0,
|
|
||||||
"Found no entries in the sources widget.");
|
|
||||||
|
|
||||||
is(gEditor.getText().length, 0,
|
|
||||||
"The source editor should not have any text displayed.");
|
|
||||||
|
|
||||||
is(gDebugger.document.querySelector("#sources .side-menu-widget-empty-text").getAttribute("value"),
|
|
||||||
gDebugger.L10N.getStr("noSourcesText"),
|
|
||||||
"The sources widget should now display 'This page has no sources'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCleanupFunction(function () {
|
|
||||||
gTab = null;
|
|
||||||
gDebuggee = null;
|
|
||||||
gPanel = null;
|
|
||||||
gDebugger = null;
|
|
||||||
gEditor = null;
|
|
||||||
gSources = null;
|
|
||||||
});
|
|
@ -1,33 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that simple JS can be parsed and cached with the reflection API.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = "let x = 42;";
|
|
||||||
let parser = new Parser();
|
|
||||||
let first = parser.get(source);
|
|
||||||
let second = parser.get(source);
|
|
||||||
|
|
||||||
isnot(first, second,
|
|
||||||
"The two syntax trees should be different.");
|
|
||||||
|
|
||||||
let third = parser.get(source, "url");
|
|
||||||
let fourth = parser.get(source, "url");
|
|
||||||
|
|
||||||
isnot(first, third,
|
|
||||||
"The new syntax trees should be different than the old ones.");
|
|
||||||
is(third, fourth,
|
|
||||||
"The new syntax trees were cached once an identifier was specified.");
|
|
||||||
|
|
||||||
is(parser.errors.length, 0,
|
|
||||||
"There should be no errors logged when parsing.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that syntax errors are reported correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = "let x + 42;";
|
|
||||||
let parser = new Parser();
|
|
||||||
// Don't pollute the logs with exceptions that we are going to check anyhow.
|
|
||||||
parser.logExceptions = false;
|
|
||||||
let parsed = parser.get(source);
|
|
||||||
|
|
||||||
ok(parsed,
|
|
||||||
"An object should be returned even though the source had a syntax error.");
|
|
||||||
|
|
||||||
is(parser.errors.length, 1,
|
|
||||||
"There should be one error logged when parsing.");
|
|
||||||
is(parser.errors[0].name, "SyntaxError",
|
|
||||||
"The correct exception was caught.");
|
|
||||||
is(parser.errors[0].message, "unexpected token: \'+\'",
|
|
||||||
"The correct exception was caught.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that JS inside HTML can be separated and parsed correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = [
|
|
||||||
"<!doctype html>",
|
|
||||||
"<head>",
|
|
||||||
"<script>",
|
|
||||||
"let a = 42;",
|
|
||||||
"</script>",
|
|
||||||
"<script type='text/javascript'>",
|
|
||||||
"let b = 42;",
|
|
||||||
"</script>",
|
|
||||||
"<script type='text/javascript'>",
|
|
||||||
"let c = 42;",
|
|
||||||
"</script>",
|
|
||||||
"</head>"
|
|
||||||
].join("\n");
|
|
||||||
let parser = new Parser();
|
|
||||||
let parsed = parser.get(source);
|
|
||||||
|
|
||||||
ok(parsed,
|
|
||||||
"HTML code should be parsed correctly.");
|
|
||||||
is(parser.errors.length, 0,
|
|
||||||
"There should be no errors logged when parsing.");
|
|
||||||
|
|
||||||
is(parsed.scriptCount, 3,
|
|
||||||
"There should be 3 scripts parsed in the parent HTML source.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(0).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"There is no script at the beginning of the parent source.");
|
|
||||||
is(parsed.getScriptInfo(source.length - 1).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"There is no script at the end of the parent source.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:31, length:13, index:0})",
|
|
||||||
"The first script was located correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:1})",
|
|
||||||
"The second script was located correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:139, length:13, index:2})",
|
|
||||||
"The third script was located correctly.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a") - 1).toSource(), "({start:31, length:13, index:0})",
|
|
||||||
"The left edge of the first script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b") - 1).toSource(), "({start:85, length:13, index:1})",
|
|
||||||
"The left edge of the second script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c") - 1).toSource(), "({start:139, length:13, index:2})",
|
|
||||||
"The left edge of the third script was interpreted correctly.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a") - 2).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The left outside of the first script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b") - 2).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The left outside of the second script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c") - 2).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The left outside of the third script was interpreted correctly.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a") + 12).toSource(), "({start:31, length:13, index:0})",
|
|
||||||
"The right edge of the first script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b") + 12).toSource(), "({start:85, length:13, index:1})",
|
|
||||||
"The right edge of the second script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c") + 12).toSource(), "({start:139, length:13, index:2})",
|
|
||||||
"The right edge of the third script was interpreted correctly.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a") + 13).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The right outside of the first script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b") + 13).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The right outside of the second script was interpreted correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c") + 13).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The right outside of the third script was interpreted correctly.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that faulty JS inside HTML can be separated and identified correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = [
|
|
||||||
"<!doctype html>",
|
|
||||||
"<head>",
|
|
||||||
"<SCRIPT>",
|
|
||||||
"let a + 42;",
|
|
||||||
"</SCRIPT>",
|
|
||||||
"<script type='text/javascript'>",
|
|
||||||
"let b = 42;",
|
|
||||||
"</SCRIPT>",
|
|
||||||
"<script type='text/javascript'>",
|
|
||||||
"let c + 42;",
|
|
||||||
"</SCRIPT>",
|
|
||||||
"</head>"
|
|
||||||
].join("\n");
|
|
||||||
let parser = new Parser();
|
|
||||||
// Don't pollute the logs with exceptions that we are going to check anyhow.
|
|
||||||
parser.logExceptions = false;
|
|
||||||
let parsed = parser.get(source);
|
|
||||||
|
|
||||||
ok(parsed,
|
|
||||||
"HTML code should be parsed correctly.");
|
|
||||||
is(parser.errors.length, 2,
|
|
||||||
"There should be two errors logged when parsing.");
|
|
||||||
|
|
||||||
is(parser.errors[0].name, "SyntaxError",
|
|
||||||
"The correct first exception was caught.");
|
|
||||||
is(parser.errors[0].message, "unexpected token: \'+\'",
|
|
||||||
"The correct first exception was caught.");
|
|
||||||
|
|
||||||
is(parser.errors[1].name, "SyntaxError",
|
|
||||||
"The correct second exception was caught.");
|
|
||||||
is(parser.errors[1].message, "unexpected token: \'+\'",
|
|
||||||
"The correct second exception was caught.");
|
|
||||||
|
|
||||||
is(parsed.scriptCount, 1,
|
|
||||||
"There should be 1 script parsed in the parent HTML source.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The first script shouldn't be considered valid.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let b")).toSource(), "({start:85, length:13, index:0})",
|
|
||||||
"The second script was located correctly.");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let c")).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"The third script shouldn't be considered valid.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that JS code containing strings that might look like <script> tags
|
|
||||||
* inside an HTML source is parsed correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = [
|
|
||||||
"let a = [];",
|
|
||||||
"a.push('<script>');",
|
|
||||||
"a.push('var a = 42;');",
|
|
||||||
"a.push('</script>');",
|
|
||||||
"a.push('<script type=\"text/javascript\">');",
|
|
||||||
"a.push('var b = 42;');",
|
|
||||||
"a.push('</script>');",
|
|
||||||
"a.push('<script type=\"text/javascript\">');",
|
|
||||||
"a.push('var c = 42;');",
|
|
||||||
"a.push('</script>');"
|
|
||||||
].join("\n");
|
|
||||||
let parser = new Parser();
|
|
||||||
let parsed = parser.get(source);
|
|
||||||
|
|
||||||
ok(parsed,
|
|
||||||
"The javascript code should be parsed correctly.");
|
|
||||||
is(parser.errors.length, 0,
|
|
||||||
"There should be no errors logged when parsing.");
|
|
||||||
|
|
||||||
is(parsed.scriptCount, 1,
|
|
||||||
"There should be 1 script parsed in the parent source.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("let a")).toSource(), "({start:0, length:249, index:0})",
|
|
||||||
"The script location is correct (1).");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("<script>")).toSource(), "({start:0, length:249, index:0})",
|
|
||||||
"The script location is correct (2).");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("</script>")).toSource(), "({start:0, length:249, index:0})",
|
|
||||||
"The script location is correct (3).");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that some potentially problematic identifier nodes have the
|
|
||||||
* right location information attached.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, ParserHelpers, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
function verify(source, predicate, [sline, scol], [eline, ecol]) {
|
|
||||||
let ast = Parser.reflectionAPI.parse(source);
|
|
||||||
let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
|
|
||||||
let loc = ParserHelpers.getNodeLocation(node);
|
|
||||||
|
|
||||||
is(loc.start.toSource(), { line: sline, column: scol }.toSource(),
|
|
||||||
"The start location was correct for the identifier in: '" + source + "'.");
|
|
||||||
is(loc.end.toSource(), { line: eline, column: ecol }.toSource(),
|
|
||||||
"The end location was correct for the identifier in: '" + source + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// FunctionDeclarations and FunctionExpressions.
|
|
||||||
|
|
||||||
// The location is unavailable for the identifier node "foo".
|
|
||||||
verify("function foo(){}", e => e.name == "foo", [1, 9], [1, 12]);
|
|
||||||
verify("\nfunction\nfoo\n(\n)\n{\n}\n", e => e.name == "foo", [3, 0], [3, 3]);
|
|
||||||
|
|
||||||
verify("({bar:function foo(){}})", e => e.name == "foo", [1, 15], [1, 18]);
|
|
||||||
verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "foo", [6, 0], [6, 3]);
|
|
||||||
|
|
||||||
// Just to be sure, check the identifier node "bar" as well.
|
|
||||||
verify("({bar:function foo(){}})", e => e.name == "bar", [1, 2], [1, 5]);
|
|
||||||
verify("(\n{\nbar\n:\nfunction\nfoo\n(\n)\n{\n}\n}\n)", e => e.name == "bar", [3, 0], [3, 3]);
|
|
||||||
|
|
||||||
// MemberExpressions.
|
|
||||||
|
|
||||||
// The location is unavailable for the identifier node "bar".
|
|
||||||
verify("foo.bar", e => e.name == "bar", [1, 4], [1, 7]);
|
|
||||||
verify("\nfoo\n.\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
|
|
||||||
|
|
||||||
// Just to be sure, check the identifier node "foo" as well.
|
|
||||||
verify("foo.bar", e => e.name == "foo", [1, 0], [1, 3]);
|
|
||||||
verify("\nfoo\n.\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
|
|
||||||
|
|
||||||
// VariableDeclarator
|
|
||||||
|
|
||||||
// The location is incorrect for the identifier node "foo".
|
|
||||||
verify("let foo = bar", e => e.name == "foo", [1, 4], [1, 7]);
|
|
||||||
verify("\nlet\nfoo\n=\nbar\n", e => e.name == "foo", [3, 0], [3, 3]);
|
|
||||||
|
|
||||||
// Just to be sure, check the identifier node "bar" as well.
|
|
||||||
verify("let foo = bar", e => e.name == "bar", [1, 10], [1, 13]);
|
|
||||||
verify("\nlet\nfoo\n=\nbar\n", e => e.name == "bar", [5, 0], [5, 3]);
|
|
||||||
|
|
||||||
// Just to be sure, check AssignmentExpreesions as well.
|
|
||||||
verify("foo = bar", e => e.name == "foo", [1, 0], [1, 3]);
|
|
||||||
verify("\nfoo\n=\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
|
|
||||||
verify("foo = bar", e => e.name == "bar", [1, 6], [1, 9]);
|
|
||||||
verify("\nfoo\n=\nbar\n", e => e.name == "bar", [4, 0], [4, 3]);
|
|
||||||
|
|
||||||
// LabeledStatement, BreakStatement and ContinueStatement, because it's 1968 again
|
|
||||||
|
|
||||||
verify("foo: bar", e => e.name == "foo", [1, 0], [1, 3]);
|
|
||||||
verify("\nfoo\n:\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
|
|
||||||
|
|
||||||
verify("foo: for(;;) break foo", e => e.name == "foo", [1, 19], [1, 22]);
|
|
||||||
verify("\nfoo\n:\nfor(\n;\n;\n)\nbreak\nfoo\n", e => e.name == "foo", [9, 0], [9, 3]);
|
|
||||||
|
|
||||||
verify("foo: bar", e => e.name == "foo", [1, 0], [1, 3]);
|
|
||||||
verify("\nfoo\n:\nbar\n", e => e.name == "foo", [2, 0], [2, 3]);
|
|
||||||
|
|
||||||
verify("foo: for(;;) continue foo", e => e.name == "foo", [1, 22], [1, 25]);
|
|
||||||
verify("\nfoo\n:\nfor(\n;\n;\n)\ncontinue\nfoo\n", e => e.name == "foo", [9, 0], [9, 3]);
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check that nodes with locaiton information attached can be properly
|
|
||||||
* verified for containing lines and columns.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { ParserHelpers } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let node1 = { loc: {
|
|
||||||
start: { line: 1, column: 10 },
|
|
||||||
end: { line: 10, column: 1 }
|
|
||||||
}};
|
|
||||||
let node2 = { loc: {
|
|
||||||
start: { line: 1, column: 10 },
|
|
||||||
end: { line: 1, column: 20 }
|
|
||||||
}};
|
|
||||||
|
|
||||||
ok(ParserHelpers.nodeContainsLine(node1, 1), "1st check.");
|
|
||||||
ok(ParserHelpers.nodeContainsLine(node1, 5), "2nd check.");
|
|
||||||
ok(ParserHelpers.nodeContainsLine(node1, 10), "3rd check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsLine(node1, 0), "4th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsLine(node1, 11), "5th check.");
|
|
||||||
|
|
||||||
ok(ParserHelpers.nodeContainsLine(node2, 1), "6th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsLine(node2, 0), "7th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsLine(node2, 2), "8th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 1, 10), "9th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 10, 1), "10th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 0, 10), "11th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 11, 1), "12th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 1, 9), "13th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node1, 10, 2), "14th check.");
|
|
||||||
|
|
||||||
ok(ParserHelpers.nodeContainsPoint(node2, 1, 10), "15th check.");
|
|
||||||
ok(ParserHelpers.nodeContainsPoint(node2, 1, 15), "16th check.");
|
|
||||||
ok(ParserHelpers.nodeContainsPoint(node2, 1, 20), "17th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 0, 10), "18th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 2, 20), "19th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 0, 9), "20th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 2, 21), "21th check.");
|
|
||||||
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 1, 9), "22th check.");
|
|
||||||
ok(!ParserHelpers.nodeContainsPoint(node2, 1, 21), "23th check.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,291 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that inferring anonymous function information is done correctly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, ParserHelpers, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
function verify(source, predicate, details) {
|
|
||||||
let { name, chain } = details;
|
|
||||||
let [[sline, scol], [eline, ecol]] = details.loc;
|
|
||||||
let ast = Parser.reflectionAPI.parse(source);
|
|
||||||
let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
|
|
||||||
let info = ParserHelpers.inferFunctionExpressionInfo(node);
|
|
||||||
|
|
||||||
is(info.name, name,
|
|
||||||
"The function expression assignment property name is correct.");
|
|
||||||
is(chain ? info.chain.toSource() : info.chain, chain ? chain.toSource() : chain,
|
|
||||||
"The function expression assignment property chain is correct.");
|
|
||||||
is(info.loc.start.toSource(), { line: sline, column: scol }.toSource(),
|
|
||||||
"The start location was correct for the identifier in: '" + source + "'.");
|
|
||||||
is(info.loc.end.toSource(), { line: eline, column: ecol }.toSource(),
|
|
||||||
"The end location was correct for the identifier in: '" + source + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// VariableDeclarator
|
|
||||||
|
|
||||||
verify("var foo=function(){}", e => e.type == "FunctionExpression", {
|
|
||||||
name: "foo",
|
|
||||||
chain: null,
|
|
||||||
loc: [[1, 4], [1, 7]]
|
|
||||||
});
|
|
||||||
verify("\nvar\nfoo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression", {
|
|
||||||
name: "foo",
|
|
||||||
chain: null,
|
|
||||||
loc: [[3, 0], [3, 3]]
|
|
||||||
});
|
|
||||||
|
|
||||||
// AssignmentExpression
|
|
||||||
|
|
||||||
verify("foo=function(){}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[1, 0], [1, 3]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[2, 0], [2, 3]] });
|
|
||||||
|
|
||||||
verify("foo.bar=function(){}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 0], [1, 7]] });
|
|
||||||
|
|
||||||
verify("\nfoo.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[2, 0], [2, 7]] });
|
|
||||||
|
|
||||||
verify("this.foo=function(){}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: ["this"], loc: [[1, 0], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: ["this"], loc: [[2, 0], [2, 8]] });
|
|
||||||
|
|
||||||
verify("this.foo.bar=function(){}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[1, 0], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[2, 0], [2, 12]] });
|
|
||||||
|
|
||||||
verify("foo.this.bar=function(){}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo", "this"], loc: [[1, 0], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nfoo.this.bar\n=\nfunction\n(\n)\n{\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo", "this"], loc: [[2, 0], [2, 12]] });
|
|
||||||
|
|
||||||
// ObjectExpression
|
|
||||||
|
|
||||||
verify("({foo:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[1, 2], [1, 5]] });
|
|
||||||
|
|
||||||
verify("(\n{\nfoo\n:\nfunction\n(\n)\n{\n}\n}\n)", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[3, 0], [3, 3]] });
|
|
||||||
|
|
||||||
verify("({foo:{bar:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 7], [1, 10]] });
|
|
||||||
|
|
||||||
verify("(\n{\nfoo\n:\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n}\n)", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
|
|
||||||
|
|
||||||
// AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 5], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "foo"], loc: [[1, 12], [1, 15]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "foo", "bar"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "foo", "bar"], loc: [[1, 15], [1, 18]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "nested", "foo"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "nested", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "this", "foo"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "this", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
// VariableDeclarator + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("let foo={bar:function(){}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 9], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nlet\nfoo\n=\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
|
|
||||||
|
|
||||||
verify("let foo={bar:{baz:function(){}}}", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[1, 14], [1, 17]] });
|
|
||||||
|
|
||||||
verify("\nlet\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[9, 0], [9, 3]] });
|
|
||||||
|
|
||||||
// New/CallExpression + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 5], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 12], [1, 15]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 15], [1, 18]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
// New/CallExpression + VariableDeclarator + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("let target=foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 16], [1, 19]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 21], [1, 24]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 23], [1, 26]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 21], [1, 24]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 26], [1, 29]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.nested.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.nested.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.this.foo({bar:function(){}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\nfunction\n(\n)\n{\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.this.foo({bar:{baz:function(){}}})", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\nfunction\n(\n)\n{\n}\n}\n}\n)\n", e => e.type == "FunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,292 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that inferring anonymous function information is done correctly
|
|
||||||
* from arrow expressions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, ParserHelpers, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
function verify(source, predicate, details) {
|
|
||||||
let { name, chain } = details;
|
|
||||||
let [[sline, scol], [eline, ecol]] = details.loc;
|
|
||||||
let ast = Parser.reflectionAPI.parse(source);
|
|
||||||
let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
|
|
||||||
let info = ParserHelpers.inferFunctionExpressionInfo(node);
|
|
||||||
|
|
||||||
is(info.name, name,
|
|
||||||
"The function expression assignment property name is correct.");
|
|
||||||
is(chain ? info.chain.toSource() : info.chain, chain ? chain.toSource() : chain,
|
|
||||||
"The function expression assignment property chain is correct.");
|
|
||||||
is(info.loc.start.toSource(), { line: sline, column: scol }.toSource(),
|
|
||||||
"The start location was correct for the identifier in: '" + source + "'.");
|
|
||||||
is(info.loc.end.toSource(), { line: eline, column: ecol }.toSource(),
|
|
||||||
"The end location was correct for the identifier in: '" + source + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// VariableDeclarator
|
|
||||||
|
|
||||||
verify("var foo=()=>{}", e => e.type == "ArrowFunctionExpression", {
|
|
||||||
name: "foo",
|
|
||||||
chain: null,
|
|
||||||
loc: [[1, 4], [1, 7]]
|
|
||||||
});
|
|
||||||
verify("\nvar\nfoo\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression", {
|
|
||||||
name: "foo",
|
|
||||||
chain: null,
|
|
||||||
loc: [[3, 0], [3, 3]]
|
|
||||||
});
|
|
||||||
|
|
||||||
// AssignmentExpression
|
|
||||||
|
|
||||||
verify("foo=()=>{}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[1, 0], [1, 3]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[2, 0], [2, 3]] });
|
|
||||||
|
|
||||||
verify("foo.bar=()=>{}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 0], [1, 7]] });
|
|
||||||
|
|
||||||
verify("\nfoo.bar\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[2, 0], [2, 7]] });
|
|
||||||
|
|
||||||
verify("this.foo=()=>{}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: ["this"], loc: [[1, 0], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: ["this"], loc: [[2, 0], [2, 8]] });
|
|
||||||
|
|
||||||
verify("this.foo.bar=()=>{}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[1, 0], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo.bar\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[2, 0], [2, 12]] });
|
|
||||||
|
|
||||||
verify("foo.this.bar=()=>{}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo", "this"], loc: [[1, 0], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nfoo.this.bar\n=\n(\n)=>\n{\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo", "this"], loc: [[2, 0], [2, 12]] });
|
|
||||||
|
|
||||||
// ObjectExpression
|
|
||||||
|
|
||||||
verify("({foo:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[1, 2], [1, 5]] });
|
|
||||||
|
|
||||||
verify("(\n{\nfoo\n:\n(\n)=>\n{\n}\n}\n)", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "foo", chain: [], loc: [[3, 0], [3, 3]] });
|
|
||||||
|
|
||||||
verify("({foo:{bar:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 7], [1, 10]] });
|
|
||||||
|
|
||||||
verify("(\n{\nfoo\n:\n{\nbar\n:\n(\n)=>\n{\n}\n}\n}\n)", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
|
|
||||||
|
|
||||||
// AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 5], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "foo"], loc: [[1, 12], [1, 15]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "foo", "bar"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "foo", "bar"], loc: [[1, 15], [1, 18]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "nested", "foo"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["this", "nested", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["this", "nested", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "this", "foo"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["nested", "this", "foo"], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["nested", "this", "foo", "bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
// VariableDeclarator + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("let foo={bar:()=>{}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[1, 9], [1, 12]] });
|
|
||||||
|
|
||||||
verify("\nlet\nfoo\n=\n{\nbar\n:\n(\n)=>\n{\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["foo"], loc: [[6, 0], [6, 3]] });
|
|
||||||
|
|
||||||
verify("let foo={bar:{baz:()=>{}}}", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[1, 14], [1, 17]] });
|
|
||||||
|
|
||||||
verify("\nlet\nfoo\n=\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["foo", "bar"], loc: [[9, 0], [9, 3]] });
|
|
||||||
|
|
||||||
// New/CallExpression + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 5], [1, 8]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 12], [1, 15]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 10], [1, 13]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 15], [1, 18]] });
|
|
||||||
|
|
||||||
verify("\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("this.nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[1, 17], [1, 20]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: [], loc: [[5, 0], [5, 3]] });
|
|
||||||
|
|
||||||
verify("nested.this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[1, 22], [1, 25]] });
|
|
||||||
|
|
||||||
verify("\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["bar"], loc: [[8, 0], [8, 3]] });
|
|
||||||
|
|
||||||
// New/CallExpression + VariableDeclarator + AssignmentExpression + ObjectExpression
|
|
||||||
|
|
||||||
verify("let target=foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 16], [1, 19]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 21], [1, 24]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nfoo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 23], [1, 26]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 21], [1, 24]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 26], [1, 29]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.nested.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=this.nested.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nthis.nested.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.this.foo({bar:()=>{}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[1, 28], [1, 31]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n(\n)=>\n{\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "bar", chain: ["target"], loc: [[7, 0], [7, 3]] });
|
|
||||||
|
|
||||||
verify("let target=nested.this.foo({bar:{baz:()=>{}}})", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[1, 33], [1, 36]] });
|
|
||||||
|
|
||||||
verify("\nlet\ntarget=\nnested.this.foo\n(\n{\nbar\n:\n{\nbaz\n:\n(\n)=>\n{\n}\n}\n}\n)\n", e => e.type == "ArrowFunctionExpression",
|
|
||||||
{ name: "baz", chain: ["target", "bar"], loc: [[10, 0], [10, 3]] });
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that creating an evaluation string for certain nodes works properly.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, ParserHelpers, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
function verify(source, predicate, string) {
|
|
||||||
let ast = Parser.reflectionAPI.parse(source);
|
|
||||||
let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
|
|
||||||
let info = ParserHelpers.getIdentifierEvalString(node);
|
|
||||||
is(info, string, "The identifier evaluation string is correct.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indentifier or Literal
|
|
||||||
|
|
||||||
verify("foo", e => e.type == "Identifier", "foo");
|
|
||||||
verify("undefined", e => e.type == "Identifier", "undefined");
|
|
||||||
verify("null", e => e.type == "Literal", "null");
|
|
||||||
verify("42", e => e.type == "Literal", "42");
|
|
||||||
verify("true", e => e.type == "Literal", "true");
|
|
||||||
verify("\"nasu\"", e => e.type == "Literal", "\"nasu\"");
|
|
||||||
|
|
||||||
// MemberExpression or ThisExpression
|
|
||||||
|
|
||||||
verify("this", e => e.type == "ThisExpression", "this");
|
|
||||||
verify("foo.bar", e => e.name == "foo", "foo");
|
|
||||||
verify("foo.bar", e => e.name == "bar", "foo.bar");
|
|
||||||
|
|
||||||
// MemberExpression + ThisExpression
|
|
||||||
|
|
||||||
verify("this.foo.bar", e => e.type == "ThisExpression", "this");
|
|
||||||
verify("this.foo.bar", e => e.name == "foo", "this.foo");
|
|
||||||
verify("this.foo.bar", e => e.name == "bar", "this.foo.bar");
|
|
||||||
|
|
||||||
verify("foo.this.bar", e => e.name == "foo", "foo");
|
|
||||||
verify("foo.this.bar", e => e.name == "this", "foo.this");
|
|
||||||
verify("foo.this.bar", e => e.name == "bar", "foo.this.bar");
|
|
||||||
|
|
||||||
// ObjectExpression + VariableDeclarator
|
|
||||||
|
|
||||||
verify("let foo={bar:baz}", e => e.name == "baz", "baz");
|
|
||||||
verify("let foo={bar:undefined}", e => e.name == "undefined", "undefined");
|
|
||||||
verify("let foo={bar:null}", e => e.type == "Literal", "null");
|
|
||||||
verify("let foo={bar:42}", e => e.type == "Literal", "42");
|
|
||||||
verify("let foo={bar:true}", e => e.type == "Literal", "true");
|
|
||||||
verify("let foo={bar:\"nasu\"}", e => e.type == "Literal", "\"nasu\"");
|
|
||||||
verify("let foo={bar:this}", e => e.type == "ThisExpression", "this");
|
|
||||||
|
|
||||||
verify("let foo={bar:{nested:baz}}", e => e.name == "baz", "baz");
|
|
||||||
verify("let foo={bar:{nested:undefined}}", e => e.name == "undefined", "undefined");
|
|
||||||
verify("let foo={bar:{nested:null}}", e => e.type == "Literal", "null");
|
|
||||||
verify("let foo={bar:{nested:42}}", e => e.type == "Literal", "42");
|
|
||||||
verify("let foo={bar:{nested:true}}", e => e.type == "Literal", "true");
|
|
||||||
verify("let foo={bar:{nested:\"nasu\"}}", e => e.type == "Literal", "\"nasu\"");
|
|
||||||
verify("let foo={bar:{nested:this}}", e => e.type == "ThisExpression", "this");
|
|
||||||
|
|
||||||
verify("let foo={bar:baz}", e => e.name == "bar", "foo.bar");
|
|
||||||
verify("let foo={bar:baz}", e => e.name == "foo", "foo");
|
|
||||||
|
|
||||||
verify("let foo={bar:{nested:baz}}", e => e.name == "nested", "foo.bar.nested");
|
|
||||||
verify("let foo={bar:{nested:baz}}", e => e.name == "bar", "foo.bar");
|
|
||||||
verify("let foo={bar:{nested:baz}}", e => e.name == "foo", "foo");
|
|
||||||
|
|
||||||
// ObjectExpression + MemberExpression
|
|
||||||
|
|
||||||
verify("parent.foo={bar:baz}", e => e.name == "bar", "parent.foo.bar");
|
|
||||||
verify("parent.foo={bar:baz}", e => e.name == "foo", "parent.foo");
|
|
||||||
verify("parent.foo={bar:baz}", e => e.name == "parent", "parent");
|
|
||||||
|
|
||||||
verify("parent.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.foo.bar.nested");
|
|
||||||
verify("parent.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.foo.bar");
|
|
||||||
verify("parent.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.foo");
|
|
||||||
verify("parent.foo={bar:{nested:baz}}", e => e.name == "parent", "parent");
|
|
||||||
|
|
||||||
verify("this.foo={bar:{nested:baz}}", e => e.name == "nested", "this.foo.bar.nested");
|
|
||||||
verify("this.foo={bar:{nested:baz}}", e => e.name == "bar", "this.foo.bar");
|
|
||||||
verify("this.foo={bar:{nested:baz}}", e => e.name == "foo", "this.foo");
|
|
||||||
verify("this.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this");
|
|
||||||
|
|
||||||
verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "nested", "this.parent.foo.bar.nested");
|
|
||||||
verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "bar", "this.parent.foo.bar");
|
|
||||||
verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "foo", "this.parent.foo");
|
|
||||||
verify("this.parent.foo={bar:{nested:baz}}", e => e.name == "parent", "this.parent");
|
|
||||||
verify("this.parent.foo={bar:{nested:baz}}", e => e.type == "ThisExpression", "this");
|
|
||||||
|
|
||||||
verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "nested", "parent.this.foo.bar.nested");
|
|
||||||
verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "bar", "parent.this.foo.bar");
|
|
||||||
verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "foo", "parent.this.foo");
|
|
||||||
verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "this", "parent.this");
|
|
||||||
verify("parent.this.foo={bar:{nested:baz}}", e => e.name == "parent", "parent");
|
|
||||||
|
|
||||||
// FunctionExpression
|
|
||||||
|
|
||||||
verify("function foo(){}", e => e.name == "foo", "foo");
|
|
||||||
verify("var foo=function(){}", e => e.name == "foo", "foo");
|
|
||||||
verify("var foo=function bar(){}", e => e.name == "bar", "bar");
|
|
||||||
|
|
||||||
// New/CallExpression
|
|
||||||
|
|
||||||
verify("foo()", e => e.name == "foo", "foo");
|
|
||||||
verify("new foo()", e => e.name == "foo", "foo");
|
|
||||||
|
|
||||||
verify("foo(bar)", e => e.name == "bar", "bar");
|
|
||||||
verify("foo(bar, baz)", e => e.name == "baz", "baz");
|
|
||||||
verify("foo(undefined)", e => e.name == "undefined", "undefined");
|
|
||||||
verify("foo(null)", e => e.type == "Literal", "null");
|
|
||||||
verify("foo(42)", e => e.type == "Literal", "42");
|
|
||||||
verify("foo(true)", e => e.type == "Literal", "true");
|
|
||||||
verify("foo(\"nasu\")", e => e.type == "Literal", "\"nasu\"");
|
|
||||||
verify("foo(this)", e => e.type == "ThisExpression", "this");
|
|
||||||
|
|
||||||
// New/CallExpression + ObjectExpression + MemberExpression
|
|
||||||
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "nested", "this.parent.foo.bar.nested");
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "bar", "this.parent.foo.bar");
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "foo", "this.parent.foo");
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "parent", "this.parent");
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.type == "ThisExpression", "this");
|
|
||||||
verify("fun(this.parent.foo={bar:{nested:baz}})", e => e.name == "fun", "fun");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if self-closing <script/> tags are parsed by Parser.jsm
|
|
||||||
*/
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser } = ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let source = [
|
|
||||||
'<script type="text/javascript" src="chrome://foo.js"/>',
|
|
||||||
'<script type="application/javascript" src="chrome://baz.js"/>',
|
|
||||||
'<script async defer src="chrome://foobar.js"/>',
|
|
||||||
'<script type="application/javascript"/>"hello third"',
|
|
||||||
'<script type="application/javascript">"hello fourth"</script>',
|
|
||||||
].join("\n");
|
|
||||||
let parser = new Parser();
|
|
||||||
let parsed = parser.get(source);
|
|
||||||
|
|
||||||
is(parser.errors.length, 0,
|
|
||||||
"There should be no errors logged when parsing.");
|
|
||||||
is(parsed.scriptCount, 5,
|
|
||||||
"There should be 5 scripts parsed in the parent HTML source.");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("foo.js\"/>") + 1).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"the first script is empty");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("baz.js\"/>") + 1).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"the second script is empty");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("foobar.js\"/>") + 1).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"the third script is empty");
|
|
||||||
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("hello third!")).toSource(), "({start:-1, length:-1, index:-1})",
|
|
||||||
"Inline script on self-closing tag not considered a script");
|
|
||||||
is(parsed.getScriptInfo(source.indexOf("hello fourth")).toSource(), "({start:255, length:14, index:4})",
|
|
||||||
"The fourth script was located correctly.");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that template strings are correctly processed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let ast = Parser.reflectionAPI.parse("({ [i]: 1 })");
|
|
||||||
let nodes = SyntaxTreeVisitor.filter(ast, e => e.type == "ComputedName");
|
|
||||||
ok(nodes && nodes.length === 1, "Found the ComputedName node");
|
|
||||||
|
|
||||||
let name = nodes[0].name;
|
|
||||||
ok(name, "The ComputedName node has a name property");
|
|
||||||
is(name.type, "Identifier", "The name has a correct type");
|
|
||||||
is(name.name, "i", "The name has a correct name");
|
|
||||||
|
|
||||||
let identNodes = SyntaxTreeVisitor.filter(ast, e => e.type == "Identifier");
|
|
||||||
ok(identNodes && identNodes.length === 1, "Found the Identifier node");
|
|
||||||
|
|
||||||
is(identNodes[0].type, "Identifier", "The identifier has a correct type");
|
|
||||||
is(identNodes[0].name, "i", "The identifier has a correct name");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that function default arguments are correctly processed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, ParserHelpers, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
function verify(source, predicate, string) {
|
|
||||||
let ast = Parser.reflectionAPI.parse(source);
|
|
||||||
let node = SyntaxTreeVisitor.filter(ast, predicate).pop();
|
|
||||||
let info = ParserHelpers.getIdentifierEvalString(node);
|
|
||||||
is(info, string, "The identifier evaluation string is correct.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// FunctionDeclaration
|
|
||||||
verify("function foo(a, b='b') {}", e => e.type == "Literal", "\"b\"");
|
|
||||||
// FunctionExpression
|
|
||||||
verify("let foo=function(a, b='b') {}", e => e.type == "Literal", "\"b\"");
|
|
||||||
// ArrowFunctionExpression
|
|
||||||
verify("let foo=(a, b='b')=> {}", e => e.type == "Literal", "\"b\"");
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that spread expressions work both in arrays and function calls.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
const SCRIPTS = ["[...a]", "foo(...a)"];
|
|
||||||
|
|
||||||
for (let script of SCRIPTS) {
|
|
||||||
info(`Testing spread expression in '${script}'`);
|
|
||||||
let ast = Parser.reflectionAPI.parse(script);
|
|
||||||
let nodes = SyntaxTreeVisitor.filter(ast,
|
|
||||||
e => e.type == "SpreadExpression");
|
|
||||||
ok(nodes && nodes.length === 1, "Found the SpreadExpression node");
|
|
||||||
|
|
||||||
let expr = nodes[0].expression;
|
|
||||||
ok(expr, "The SpreadExpression node has the sub-expression");
|
|
||||||
is(expr.type, "Identifier", "The sub-expression is an Identifier");
|
|
||||||
is(expr.name, "a", "The sub-expression identifier has a correct name");
|
|
||||||
}
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that template strings are correctly processed.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let { Parser, SyntaxTreeVisitor } =
|
|
||||||
ChromeUtils.import("resource://devtools/shared/Parser.jsm", {});
|
|
||||||
|
|
||||||
let ast = Parser.reflectionAPI.parse("`foo${i}bar`");
|
|
||||||
let nodes = SyntaxTreeVisitor.filter(ast, e => e.type == "TemplateLiteral");
|
|
||||||
ok(nodes && nodes.length === 1, "Found the TemplateLiteral node");
|
|
||||||
|
|
||||||
let elements = nodes[0].elements;
|
|
||||||
ok(elements, "The TemplateLiteral node has elements");
|
|
||||||
is(elements.length, 3, "There are 3 elements in the literal");
|
|
||||||
|
|
||||||
["Literal", "Identifier", "Literal"].forEach((type, i) => {
|
|
||||||
is(elements[i].type, type, `Element at index ${i} is '${type}'`);
|
|
||||||
});
|
|
||||||
|
|
||||||
finish();
|
|
||||||
}
|
|
@ -1,162 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure that switching the displayed source in the UI works as advertised.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let options = {
|
|
||||||
source: EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
line: 1
|
|
||||||
};
|
|
||||||
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
|
|
||||||
const gTab = aTab;
|
|
||||||
const gPanel = aPanel;
|
|
||||||
const gDebugger = gPanel.panelWin;
|
|
||||||
const gEditor = gDebugger.DebuggerView.editor;
|
|
||||||
const gSources = gDebugger.DebuggerView.Sources;
|
|
||||||
|
|
||||||
const gLabel1 = "code_script-switching-01.js";
|
|
||||||
const gLabel2 = "code_script-switching-02.js";
|
|
||||||
|
|
||||||
function testSourcesDisplay() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
is(gSources.itemCount, 2,
|
|
||||||
"Found the expected number of sources. (1)");
|
|
||||||
|
|
||||||
is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
|
|
||||||
EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
"The correct tooltip text is displayed for the first source. (1)");
|
|
||||||
is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
|
|
||||||
EXAMPLE_URL + "code_script-switching-02.js",
|
|
||||||
"The correct tooltip text is displayed for the second source. (1)");
|
|
||||||
|
|
||||||
ok(getSourceActor(gSources, EXAMPLE_URL + gLabel1),
|
|
||||||
"First source url is incorrect. (1)");
|
|
||||||
ok(getSourceActor(gSources, EXAMPLE_URL + gLabel2),
|
|
||||||
"Second source url is incorrect. (1)");
|
|
||||||
|
|
||||||
ok(gSources.getItemForAttachment(e => e.label == gLabel1),
|
|
||||||
"First source label is incorrect. (1)");
|
|
||||||
ok(gSources.getItemForAttachment(e => e.label == gLabel2),
|
|
||||||
"Second source label is incorrect. (1)");
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (1)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2,
|
|
||||||
"The selected value is the sources pane is incorrect. (1)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), -1,
|
|
||||||
"The first source is not displayed. (1)");
|
|
||||||
is(gEditor.getText().search(/debugger/), 166,
|
|
||||||
"The second source is displayed. (1)");
|
|
||||||
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (1)");
|
|
||||||
|
|
||||||
// The editor's debug location takes a tick to update.
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (1)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately (1).");
|
|
||||||
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gSources.selectedIndex = 0;
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchPaused1() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (2)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
|
|
||||||
"The selected value is the sources pane is incorrect. (2)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), 118,
|
|
||||||
"The first source is displayed. (2)");
|
|
||||||
is(gEditor.getText().search(/debugger/), -1,
|
|
||||||
"The second source is not displayed. (2)");
|
|
||||||
|
|
||||||
// The editor's debug location takes a tick to update.
|
|
||||||
ok(isCaretPos(gPanel, 1),
|
|
||||||
"Editor caret location is correct. (2)");
|
|
||||||
is(gEditor.getDebugLocation(), null,
|
|
||||||
"Editor debugger location is correct. (2)");
|
|
||||||
ok(!gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line highlight was removed. (2)");
|
|
||||||
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gSources.selectedIndex = 1;
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchPaused2() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (3)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2,
|
|
||||||
"The selected value is the sources pane is incorrect. (3)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), -1,
|
|
||||||
"The first source is not displayed. (3)");
|
|
||||||
is(gEditor.getText().search(/debugger/), 166,
|
|
||||||
"The second source is displayed. (3)");
|
|
||||||
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (3)");
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (3)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately (3).");
|
|
||||||
|
|
||||||
// Step out twice.
|
|
||||||
waitForThreadEvents(gPanel, "paused").then(() => {
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gDebugger.gThreadClient.stepOut();
|
|
||||||
});
|
|
||||||
gDebugger.gThreadClient.stepOut();
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchRunning() {
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (4)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
|
|
||||||
"The selected value is the sources pane is incorrect. (4)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), 118,
|
|
||||||
"The first source is displayed. (4)");
|
|
||||||
is(gEditor.getText().search(/debugger/), -1,
|
|
||||||
"The second source is not displayed. (4)");
|
|
||||||
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (4)");
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (4)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately (3). (4)");
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.spawn(function* () {
|
|
||||||
const shown = waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1);
|
|
||||||
callInTab(gTab, "firstCall");
|
|
||||||
yield shown;
|
|
||||||
|
|
||||||
yield testSourcesDisplay();
|
|
||||||
yield testSwitchPaused1();
|
|
||||||
yield testSwitchPaused2();
|
|
||||||
yield testSwitchRunning();
|
|
||||||
resumeDebuggerThenCloseAndFinish(gPanel);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,163 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure that switching the displayed source in the UI works as advertised.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_script-switching-02.html";
|
|
||||||
|
|
||||||
var gLabel1 = "code_script-switching-01.js";
|
|
||||||
var gLabel2 = "code_script-switching-02.js";
|
|
||||||
var gParams = "?foo=bar,baz|lol";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let options = {
|
|
||||||
source: EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
line: 1
|
|
||||||
};
|
|
||||||
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
|
|
||||||
const gTab = aTab;
|
|
||||||
const gPanel = aPanel;
|
|
||||||
const gDebugger = gPanel.panelWin;
|
|
||||||
const gEditor = gDebugger.DebuggerView.editor;
|
|
||||||
const gSources = gDebugger.DebuggerView.Sources;
|
|
||||||
|
|
||||||
function testSourcesDisplay() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
is(gSources.itemCount, 2,
|
|
||||||
"Found the expected number of sources. (1)");
|
|
||||||
|
|
||||||
ok(getSourceActor(gSources, EXAMPLE_URL + gLabel1),
|
|
||||||
"First source url is incorrect. (1)");
|
|
||||||
ok(getSourceActor(gSources, EXAMPLE_URL + gLabel2 + gParams),
|
|
||||||
"Second source url is incorrect. (1)");
|
|
||||||
|
|
||||||
ok(gSources.getItemForAttachment(e => e.label == gLabel1),
|
|
||||||
"First source label is incorrect. (1)");
|
|
||||||
ok(gSources.getItemForAttachment(e => e.label == gLabel2),
|
|
||||||
"Second source label is incorrect. (1)");
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (1)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2 + gParams,
|
|
||||||
"The selected value is the sources pane is incorrect. (1)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), -1,
|
|
||||||
"The first source is not displayed. (1)");
|
|
||||||
is(gEditor.getText().search(/debugger/), 166,
|
|
||||||
"The second source is displayed. (1)");
|
|
||||||
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (1)");
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (1)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately. (1)");
|
|
||||||
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gSources.selectedItem = e => e.attachment.label == gLabel1;
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchPaused1() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (2)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
|
|
||||||
"The selected value is the sources pane is incorrect. (2)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), 118,
|
|
||||||
"The first source is displayed. (2)");
|
|
||||||
is(gEditor.getText().search(/debugger/), -1,
|
|
||||||
"The second source is not displayed. (2)");
|
|
||||||
|
|
||||||
// The editor's debug location takes a tick to update.
|
|
||||||
ok(isCaretPos(gPanel, 1),
|
|
||||||
"Editor caret location is correct. (2)");
|
|
||||||
|
|
||||||
is(gEditor.getDebugLocation(), null,
|
|
||||||
"Editor debugger location is correct. (2)");
|
|
||||||
ok(!gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line highlight was removed. (2)");
|
|
||||||
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gSources.selectedItem = e => e.attachment.label == gLabel2;
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchPaused2() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (3)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel2 + gParams,
|
|
||||||
"The selected value is the sources pane is incorrect. (3)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), -1,
|
|
||||||
"The first source is not displayed. (3)");
|
|
||||||
is(gEditor.getText().search(/debugger/), 166,
|
|
||||||
"The second source is displayed. (3)");
|
|
||||||
|
|
||||||
// The editor's debug location takes a tick to update.
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (3)");
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (3)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately. (3)");
|
|
||||||
|
|
||||||
// Step out three times.
|
|
||||||
waitForThreadEvents(gPanel, "paused").then(() => {
|
|
||||||
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
|
|
||||||
gDebugger.gThreadClient.stepOut();
|
|
||||||
});
|
|
||||||
gDebugger.gThreadClient.stepOut();
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSwitchRunning() {
|
|
||||||
let deferred = promise.defer();
|
|
||||||
|
|
||||||
ok(gSources.selectedItem,
|
|
||||||
"There should be a selected item in the sources pane. (4)");
|
|
||||||
is(getSelectedSourceURL(gSources), EXAMPLE_URL + gLabel1,
|
|
||||||
"The selected value is the sources pane is incorrect. (4)");
|
|
||||||
|
|
||||||
is(gEditor.getText().search(/firstCall/), 118,
|
|
||||||
"The first source is displayed. (4)");
|
|
||||||
is(gEditor.getText().search(/debugger/), -1,
|
|
||||||
"The second source is not displayed. (4)");
|
|
||||||
|
|
||||||
// The editor's debug location takes a tick to update.
|
|
||||||
ok(isCaretPos(gPanel, 6),
|
|
||||||
"Editor caret location is correct. (4)");
|
|
||||||
is(gEditor.getDebugLocation(), 5,
|
|
||||||
"Editor debugger location is correct. (4)");
|
|
||||||
ok(gEditor.hasLineClass(5, "debug-line"),
|
|
||||||
"The debugged line is highlighted appropriately. (4)");
|
|
||||||
|
|
||||||
deferred.resolve();
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.spawn(function* () {
|
|
||||||
yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1);
|
|
||||||
yield testSourcesDisplay();
|
|
||||||
yield testSwitchPaused1();
|
|
||||||
yield testSwitchPaused2();
|
|
||||||
yield testSwitchRunning();
|
|
||||||
resumeDebuggerThenCloseAndFinish(gPanel);
|
|
||||||
});
|
|
||||||
|
|
||||||
callInTab(gTab, "firstCall");
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
||||||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
||||||
/* Any copyright is dedicated to the Public Domain.
|
|
||||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure that the DebuggerView error loading source text is correct.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
let options = {
|
|
||||||
source: EXAMPLE_URL + "code_script-switching-01.js",
|
|
||||||
line: 1
|
|
||||||
};
|
|
||||||
initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
|
|
||||||
const gTab = aTab;
|
|
||||||
const gPanel = aPanel;
|
|
||||||
const gDebugger = gPanel.panelWin;
|
|
||||||
const gView = gDebugger.DebuggerView;
|
|
||||||
const gEditor = gDebugger.DebuggerView.editor;
|
|
||||||
const gL10N = gDebugger.L10N;
|
|
||||||
const require = gDebugger.require;
|
|
||||||
const actions = bindActionCreators(gPanel);
|
|
||||||
const constants = require("./content/constants");
|
|
||||||
const controller = gDebugger.DebuggerController;
|
|
||||||
|
|
||||||
function showBogusSource() {
|
|
||||||
const source = { actor: "fake.actor", url: "http://fake.url/" };
|
|
||||||
actions.newSource(source);
|
|
||||||
|
|
||||||
controller.dispatch({
|
|
||||||
type: constants.LOAD_SOURCE_TEXT,
|
|
||||||
source: source,
|
|
||||||
status: "start"
|
|
||||||
});
|
|
||||||
|
|
||||||
controller.dispatch({
|
|
||||||
type: constants.SELECT_SOURCE,
|
|
||||||
source: source
|
|
||||||
});
|
|
||||||
|
|
||||||
controller.dispatch({
|
|
||||||
type: constants.LOAD_SOURCE_TEXT,
|
|
||||||
source: source,
|
|
||||||
status: "error",
|
|
||||||
error: "bogus actor"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function testDebuggerLoadingError() {
|
|
||||||
ok(gEditor.getText().includes(gL10N.getFormatStr("errorLoadingText3", "")),
|
|
||||||
"The valid error loading message is displayed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Task.spawn(function* () {
|
|
||||||
showBogusSource();
|
|
||||||
testDebuggerLoadingError();
|
|
||||||
closeDebuggerAndFinish(gPanel);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user