Bug 876277 - Fix webconsole and profiler accessing and relying on old debugger DOM event APIs, r=past

This commit is contained in:
Victor Porof 2013-09-13 16:23:14 +03:00
Родитель 7324c03364
Коммит 65f00c1176
5 изменённых файлов: 52 добавлений и 81 удалений

Просмотреть файл

@ -456,39 +456,37 @@ ProfilerPanel.prototype = {
* - line
* - isChrome (chrome files are opened via view-source)
*/
displaySource: function PP_displaySource(data, onOpen=function() {}) {
let win = this.window;
let panelWin;
displaySource: function PP_displaySource(data) {
let { browserWindow: win, document: doc } = this;
let { uri, line, isChrome } = data;
let deferred = promise.defer();
function onSourceShown(event) {
if (event.detail.url !== data.uri) {
return;
}
panelWin.removeEventListener("Debugger:SourceShown", onSourceShown, false);
panelWin.editor.setCaretPosition(data.line - 1);
onOpen();
if (isChrome) {
return void win.gViewSourceUtils.viewSource(uri, null, doc, line);
}
if (data.isChrome) {
return void this.browserWindow.gViewSourceUtils.
viewSource(data.uri, null, this.document, data.line);
let showSource = ({ DebuggerView }) => {
if (DebuggerView.Sources.containsValue(uri)) {
DebuggerView.setEditorLocation(uri, line).then(deferred.resolve);
}
// XXX: What to do if the source isn't present in the Debugger?
// Switch back to the Profiler panel and viewSource()?
}
gDevTools.showToolbox(this.target, "jsdebugger").then(function (toolbox) {
let dbg = toolbox.getCurrentPanel();
panelWin = dbg.panelWin;
let view = dbg.panelWin.DebuggerView;
if (view.Sources.selectedValue === data.uri) {
view.editor.setCaretPosition(data.line - 1);
onOpen();
return;
// If the Debugger was already open, switch to it and try to show the
// source immediately. Otherwise, initialize it and wait for the sources
// to be added first.
let toolbox = gDevTools.getToolbox(this.target);
let debuggerAlreadyOpen = toolbox.getPanel("jsdebugger");
toolbox.selectTool("jsdebugger").then(({ panelWin: dbg }) => {
if (debuggerAlreadyOpen) {
showSource(dbg);
} else {
dbg.once(dbg.EVENTS.SOURCES_ADDED, () => showSource(dbg));
}
});
panelWin.addEventListener("Debugger:SourceShown", onSourceShown, false);
panelWin.DebuggerView.Sources.preferredSource = data.uri;
}.bind(this));
return deferred.promise;
},
/**

Просмотреть файл

@ -11,7 +11,7 @@ function test() {
setUp(URL, function onSetUp(tab, browser, panel) {
let data = { uri: SCRIPT, line: 5, isChrome: false };
panel.displaySource(data, function onOpen() {
panel.displaySource(data).then(function onOpen() {
let target = TargetFactory.forTab(tab);
let dbg = gDevTools.getToolbox(target).getPanel("jsdebugger");
let view = dbg.panelWin.DebuggerView;
@ -23,7 +23,7 @@ function test() {
// Test the case where script is already loaded.
view.editor.setCaretPosition(1);
gDevTools.showToolbox(target, "jsprofiler").then(function () {
panel.displaySource(data, function onOpenAgain() {
panel.displaySource(data).then(function onOpenAgain() {
is(view.editor.getCaretPosition().line, data.line - 1,
"Line is different");
tearDown(tab);

Просмотреть файл

@ -474,56 +474,32 @@ WebConsole.prototype = {
viewSourceInDebugger:
function WC_viewSourceInDebugger(aSourceURL, aSourceLine)
{
let self = this;
let panelWin = null;
let debuggerWasOpen = true;
let toolbox = gDevTools.getToolbox(this.target);
if (!toolbox) {
self.viewSource(aSourceURL, aSourceLine);
this.viewSource(aSourceURL, aSourceLine);
return;
}
if (!toolbox.getPanel("jsdebugger")) {
debuggerWasOpen = false;
let toolboxWin = toolbox.doc.defaultView;
toolboxWin.addEventListener("Debugger:AfterSourcesAdded",
function afterSourcesAdded() {
toolboxWin.removeEventListener("Debugger:AfterSourcesAdded",
afterSourcesAdded);
loadScript();
});
let showSource = ({ DebuggerView }) => {
if (DebuggerView.Sources.containsValue(aSourceURL)) {
DebuggerView.setEditorLocation(aSourceURL, aSourceLine);
return;
}
toolbox.selectTool("webconsole");
this.viewSource(aSourceURL, aSourceLine);
}
toolbox.selectTool("jsdebugger").then(function onDebuggerOpen(dbg) {
panelWin = dbg.panelWin;
if (debuggerWasOpen) {
loadScript();
// If the Debugger was already open, switch to it and try to show the
// source immediately. Otherwise, initialize it and wait for the sources
// to be added first.
let debuggerAlreadyOpen = toolbox.getPanel("jsdebugger");
toolbox.selectTool("jsdebugger").then(({ panelWin: dbg }) => {
if (debuggerAlreadyOpen) {
showSource(dbg);
} else {
dbg.once(dbg.EVENTS.SOURCES_ADDED, () => showSource(dbg));
}
});
function loadScript() {
let debuggerView = panelWin.DebuggerView;
if (!debuggerView.Sources.containsValue(aSourceURL)) {
toolbox.selectTool("webconsole");
self.viewSource(aSourceURL, aSourceLine);
return;
}
if (debuggerWasOpen && debuggerView.Sources.selectedValue == aSourceURL) {
debuggerView.editor.setCaretPosition(aSourceLine - 1);
return;
}
panelWin.addEventListener("Debugger:SourceShown", onSource, false);
debuggerView.Sources.preferredSource = aSourceURL;
}
function onSource(aEvent) {
if (aEvent.detail.url != aSourceURL) {
return;
}
panelWin.removeEventListener("Debugger:SourceShown", onSource, false);
panelWin.DebuggerView.editor.setCaretPosition(aSourceLine - 1);
}
},
/**
@ -549,12 +525,12 @@ WebConsole.prototype = {
if (!panel) {
return null;
}
let framesController = panel.panelWin.gStackFrames;
let framesController = panel.panelWin.DebuggerController.StackFrames;
let thread = framesController.activeThread;
if (thread && thread.paused) {
return {
frames: thread.cachedFrames,
selected: framesController.currentFrame,
selected: framesController.currentFrameDepth,
};
}
return null;

Просмотреть файл

@ -70,14 +70,14 @@ function checkLineAndClickNext(aEvent, aPanel)
ok(line, "found source line for index " + index);
info("Waiting for the correct script to be selected for index " + index);
dbg.panelWin.addEventListener("Debugger:SourceShown", onSource, false);
dbg.panelWin.on(dbg.panelWin.EVENTS.SOURCE_SHOWN, onSource);
}
function onSource(aEvent) {
if (aEvent.detail.url != src) {
function onSource(aEvent, aSource) {
if (aSource.url != src) {
return;
}
dbg.panelWin.removeEventListener("Debugger:SourceShown", onSource, false);
dbg.panelWin.off(dbg.panelWin.EVENTS.SOURCE_SHOWN, onSource);
ok(true, "Correct script is selected for index " + index);

Просмотреть файл

@ -809,12 +809,9 @@ function openDebugger(aOptions = {})
deferred.resolve(resolveObject);
}
else {
panelWin.addEventListener("Debugger:AfterSourcesAdded",
function onAfterSourcesAdded() {
panelWin.removeEventListener("Debugger:AfterSourcesAdded",
onAfterSourcesAdded);
deferred.resolve(resolveObject);
});
panelWin.once(panelWin.EVENTS.SOURCES_ADDED, () => {
deferred.resolve(resolveObject);
});
}
}, function onFailure(aReason) {
console.debug("failed to open the toolbox for 'jsdebugger'", aReason);