diff --git a/devtools/client/shared/view-source.js b/devtools/client/shared/view-source.js index 7a94f9ac6690..415a2b34cf17 100644 --- a/devtools/client/shared/view-source.js +++ b/devtools/client/shared/view-source.js @@ -55,23 +55,29 @@ exports.viewSourceInDebugger = Task.async(function* (toolbox, sourceURL, sourceL // source immediately. Otherwise, initialize it and wait for the sources // to be added first. let debuggerAlreadyOpen = toolbox.getPanel("jsdebugger"); - let { panelWin: dbg } = yield toolbox.loadTool("jsdebugger"); + let dbg = yield toolbox.loadTool("jsdebugger"); // New debugger frontend if (Services.prefs.getBoolPref("devtools.debugger.new-debugger-frontend")) { yield toolbox.selectTool("jsdebugger"); - // TODO: Properly handle case where source will never exist in the - // debugger - dbg.actions.selectSourceURL(sourceURL, { line: sourceLine }); - return true; + const source = dbg._selectors().getSourceByURL(dbg._getState(), sourceURL); + if (source) { + dbg._actions().selectSourceByURL(sourceURL, { line: sourceLine }); + return true; + } + + exports.viewSource(toolbox, sourceURL, sourceLine); + return false; } + const win = dbg.panelWin; + // Old debugger frontend if (!debuggerAlreadyOpen) { - yield dbg.DebuggerController.waitForSourcesLoaded(); + yield win.DebuggerController.waitForSourcesLoaded(); } - let { DebuggerView } = dbg; + let { DebuggerView } = win; let { Sources } = DebuggerView; let item = Sources.getItemForAttachment(a => a.source.url === sourceURL); @@ -84,7 +90,7 @@ exports.viewSourceInDebugger = Task.async(function* (toolbox, sourceURL, sourceL // selected and loaded // 2) The requested source is selected BUT the source text is still loading. const { actor } = item.attachment.source; - const state = dbg.DebuggerController.getState(); + const state = win.DebuggerController.getState(); // (1) Is the source selected? const selected = state.sources.selectedSource; @@ -106,7 +112,7 @@ exports.viewSourceInDebugger = Task.async(function* (toolbox, sourceURL, sourceL // Wait for it to load if (!isSelected || isLoading) { - yield dbg.DebuggerController.waitForSourceShown(sourceURL); + yield win.DebuggerController.waitForSourceShown(sourceURL); } return true; } diff --git a/devtools/client/webconsole/test/browser_webconsole_view_source.js b/devtools/client/webconsole/test/browser_webconsole_view_source.js index b59b76162e32..a81b58acc182 100644 --- a/devtools/client/webconsole/test/browser_webconsole_view_source.js +++ b/devtools/client/webconsole/test/browser_webconsole_view_source.js @@ -13,13 +13,17 @@ const TEST_URI = "https://example.com/browser/devtools/client/webconsole/" + "test/test-mixedcontent-securityerrors.html"; -// Force the old debugger UI since it's directly used (see Bug 1301705) -Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false); -registerCleanupFunction(function* () { - Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend"); +add_task(function* () { + yield actuallyTest(); }); add_task(function* () { + Services.prefs.setBoolPref("devtools.debugger.new-debugger-frontend", false); + yield actuallyTest(); + Services.prefs.clearUserPref("devtools.debugger.new-debugger-frontend"); +}); + +var actuallyTest = Task.async(function*() { yield loadTab(TEST_URI); let hud = yield openConsole(null); info("console opened");