From 1a700a9baaed3af149f1a86ae259428e930c37da Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Wed, 3 Oct 2012 22:57:01 +0300 Subject: [PATCH] Bug 797404 - Sources which take too long to fetch incorrectly show up after a page refresh, r=past --- .../devtools/debugger/debugger-controller.js | 31 +++++++++++++------ .../test/browser_dbg_location-changes-new.js | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/browser/devtools/debugger/debugger-controller.js b/browser/devtools/debugger/debugger-controller.js index 59785898b08..57d770deb6a 100644 --- a/browser/devtools/debugger/debugger-controller.js +++ b/browser/devtools/debugger/debugger-controller.js @@ -9,6 +9,7 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; +const NEW_SCRIPT_DISPLAY_DELAY = 100; // ms const FRAME_STEP_CACHE_DURATION = 100; // ms const DBG_STRINGS_URI = "chrome://browser/locale/devtools/debugger.properties"; const SCRIPTS_URL_MAX_LENGTH = 64; // chars @@ -941,15 +942,21 @@ SourceScripts.prototype = { if (aPacket.url === DebuggerView.Scripts.preferredScriptUrl) { DebuggerView.Scripts.selectScript(aPacket.url); } - // ..or the first entry if there's not one selected yet. - else if (!DebuggerView.Scripts.selected) { - DebuggerView.Scripts.selectIndex(0); - // Selecting a script would make it "preferred", which is a lie here, - // because we're only displaying a script to make sure there's always - // something available in the SourceEditor and the scripts menulist. - // Hence the need revert back to the initial preferred script, just - // in case it will be available soon. - DebuggerView.Scripts.preferredScriptUrl = preferredScriptUrl; + // ..or the first entry if there's none selected yet after a while + else { + window.setTimeout(function() { + // If after a certain delay the preferred script still wasn't received, + // just give up on waiting and display the first entry. + if (!DebuggerView.Scripts.selected) { + DebuggerView.Scripts.selectIndex(0); + // Selecting a script would make it "preferred", which is a lie here, + // because we're only displaying a script to make sure there's always + // something available in the SourceEditor and the scripts menulist. + // Hence the need revert back to the initial preferred script, just + // in case it will be available soon. + DebuggerView.Scripts.preferredScriptUrl = preferredScriptUrl; + } + }, NEW_SCRIPT_DISPLAY_DELAY); } // If there are any stored breakpoints for this script, display them again, @@ -1210,7 +1217,11 @@ SourceScripts.prototype = { */ showScript: function SS_showScript(aScript, aOptions = {}) { if (aScript.loaded) { - this._onShowScript(aScript, aOptions); + // Scripts may take a longer time to load than expected, therefore the + // required one may change at any time after a previous request was made. + if (aScript.url === DebuggerView.Scripts.selected) { + this._onShowScript(aScript, aOptions); + } return; } diff --git a/browser/devtools/debugger/test/browser_dbg_location-changes-new.js b/browser/devtools/debugger/test/browser_dbg_location-changes-new.js index 28040421b4b..d5dbc9575aa 100644 --- a/browser/devtools/debugger/test/browser_dbg_location-changes-new.js +++ b/browser/devtools/debugger/test/browser_dbg_location-changes-new.js @@ -59,7 +59,7 @@ function testLocationChange() ok(true, "tabNavigated event was fired."); info("Still attached to the tab."); - gDebugger.addEventListener("Debugger:AfterNewScript", function _onEvent(aEvent) { + gDebugger.addEventListener("Debugger:ScriptShown", function _onEvent(aEvent) { gDebugger.removeEventListener(aEvent.type, _onEvent); isnot(gDebugger.DebuggerView.Scripts.selected, null,