diff --git a/browser/devtools/profiler/panel.js b/browser/devtools/profiler/panel.js index 84688f261682..fd7a38346774 100644 --- a/browser/devtools/profiler/panel.js +++ b/browser/devtools/profiler/panel.js @@ -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; }, /** diff --git a/browser/devtools/profiler/test/browser_profiler_bug_834878_source_buttons.js b/browser/devtools/profiler/test/browser_profiler_bug_834878_source_buttons.js index bd84b2751d1c..6f80a45e9b49 100644 --- a/browser/devtools/profiler/test/browser_profiler_bug_834878_source_buttons.js +++ b/browser/devtools/profiler/test/browser_profiler_bug_834878_source_buttons.js @@ -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); diff --git a/browser/devtools/webconsole/hudservice.js b/browser/devtools/webconsole/hudservice.js index 3b5f129133f3..fb99ac96584d 100644 --- a/browser/devtools/webconsole/hudservice.js +++ b/browser/devtools/webconsole/hudservice.js @@ -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; diff --git a/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js b/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js index 30e560bfbff7..86cc613939f6 100644 --- a/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_766001_JS_Console_in_Debugger.js @@ -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); diff --git a/browser/devtools/webconsole/test/head.js b/browser/devtools/webconsole/test/head.js index 6819927249fa..526d8a3c02df 100644 --- a/browser/devtools/webconsole/test/head.js +++ b/browser/devtools/webconsole/test/head.js @@ -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);