From 4800135eba64b8b3963f97dec9a6d6268d5fc248 Mon Sep 17 00:00:00 2001 From: Panos Astithas Date: Wed, 28 Mar 2012 17:47:33 +0300 Subject: [PATCH] Backout changeset 794ff67c7a9a (bug 723563) due to suspected randomorange (bug 739995) --- browser/devtools/debugger/debugger.js | 20 ++++--- ...rowser_dbg_bug723069_editor-breakpoints.js | 2 +- ...rowser_dbg_bug731394_editor-contextmenu.js | 2 +- .../test/browser_dbg_debuggerstatement.js | 3 +- .../debugger/test/browser_dbg_listtabs.js | 2 +- .../test/browser_dbg_propertyview-01.js | 1 - .../test/browser_dbg_propertyview-07.js | 7 ++- .../test/browser_dbg_propertyview-08.js | 7 ++- .../test/browser_dbg_script-switching.js | 2 +- .../debugger/test/browser_dbg_stack-05.js | 2 +- .../test/browser_dbg_update-editor-mode.js | 2 +- .../webconsole/test/browser_gcli_break.js | 2 +- .../browser/devtools/debugger.properties | 2 +- .../debugger/server/dbg-browser-actors.js | 59 +++++++++++++++++-- .../debugger/server/dbg-script-actors.js | 46 +++++++-------- 15 files changed, 105 insertions(+), 54 deletions(-) diff --git a/browser/devtools/debugger/debugger.js b/browser/devtools/debugger/debugger.js index ad56f14302f..0a93b3e5fc4 100644 --- a/browser/devtools/debugger/debugger.js +++ b/browser/devtools/debugger/debugger.js @@ -311,10 +311,6 @@ var StackFrames = { paramVar.setGrip(paramVal); this._addExpander(paramVar, paramVal); } - // Signal that call parameters have been fetched. - let evt = document.createEvent("Event"); - evt.initEvent("Debugger:FetchedParameters", true, false); - document.documentElement.dispatchEvent(evt); }.bind(this)); } }, @@ -473,13 +469,11 @@ var SourceScripts = { DebuggerView.Scripts.addChangeListener(this.onChange); this.activeThread = aThreadClient; + aThreadClient.addListener("paused", this.onPaused); aThreadClient.addListener("scriptsadded", this.onScripts); aThreadClient.addListener("scriptscleared", this.onScriptsCleared); this.clearLabelsCache(); this.onScriptsCleared(); - // Retrieve the list of scripts known to the server from before the client - // was ready to handle new script notifications. - this.activeThread.fillScripts(); aCallback && aCallback(); }, @@ -487,10 +481,21 @@ var SourceScripts = { * Disconnect from the client. */ disconnect: function TS_disconnect() { + this.activeThread.removeListener("paused", this.onPaused); this.activeThread.removeListener("scriptsadded", this.onScripts); this.activeThread.removeListener("scriptscleared", this.onScriptsCleared); }, + /** + * Handler for the thread client's paused notification. This is triggered only + * once, to retrieve the list of scripts known to the server from before the + * client was ready to handle new script notifications. + */ + onPaused: function SS_onPaused() { + this.activeThread.removeListener("paused", this.onPaused); + this.activeThread.fillScripts(); + }, + /** * Handler for the debugger client's unsolicited newScript notification. */ @@ -652,6 +657,7 @@ var SourceScripts = { } }; +SourceScripts.onPaused = SourceScripts.onPaused.bind(SourceScripts); SourceScripts.onScripts = SourceScripts.onScripts.bind(SourceScripts); SourceScripts.onNewScript = SourceScripts.onNewScript.bind(SourceScripts); SourceScripts.onScriptsCleared = SourceScripts.onScriptsCleared.bind(SourceScripts); diff --git a/browser/devtools/debugger/test/browser_dbg_bug723069_editor-breakpoints.js b/browser/devtools/debugger/test/browser_dbg_bug723069_editor-breakpoints.js index 7376ec5dece..f2066d16226 100644 --- a/browser/devtools/debugger/test/browser_dbg_bug723069_editor-breakpoints.js +++ b/browser/devtools/debugger/test/browser_dbg_bug723069_editor-breakpoints.js @@ -28,7 +28,7 @@ function test() gPane = aPane; gDebugger = gPane.debuggerWindow; - gPane.activeThread.addOneTimeListener("framesadded", function() { + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: onScriptsAdded }, 0); }); gDebuggee.firstCall(); diff --git a/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js b/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js index f3a166d40c4..e4be65aac2c 100644 --- a/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js +++ b/browser/devtools/debugger/test/browser_dbg_bug731394_editor-contextmenu.js @@ -26,7 +26,7 @@ function test() gPane = aPane; gDebugger = gPane.debuggerWindow; - gPane.activeThread.addOneTimeListener("framesadded", function() { + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: onScriptsAdded }, 0); }); gDebuggee.firstCall(); diff --git a/browser/devtools/debugger/test/browser_dbg_debuggerstatement.js b/browser/devtools/debugger/test/browser_dbg_debuggerstatement.js index de18429f086..d6e87d15167 100644 --- a/browser/devtools/debugger/test/browser_dbg_debuggerstatement.js +++ b/browser/devtools/debugger/test/browser_dbg_debuggerstatement.js @@ -32,7 +32,8 @@ function test_early_debugger_statement(aActor) gClient.addListener("paused", paused); // This should continue without nesting an event loop and calling // the onPaused hook, because we haven't attached yet. - gTab.linkedBrowser.contentWindow.wrappedJSObject.runDebuggerStatement(); + // TODO: uncomment this when bug 723563 is fixed. + //gTab.linkedBrowser.contentWindow.wrappedJSObject.runDebuggerStatement(); gClient.removeListener("paused", paused); diff --git a/browser/devtools/debugger/test/browser_dbg_listtabs.js b/browser/devtools/debugger/test/browser_dbg_listtabs.js index 8cca2953590..9c48ad8c66b 100644 --- a/browser/devtools/debugger/test/browser_dbg_listtabs.js +++ b/browser/devtools/debugger/test/browser_dbg_listtabs.js @@ -87,7 +87,7 @@ function test_attach_removed_tab() }); gClient.request({ to: gTab2Actor, type: "attach" }, function(aResponse) { - is(aResponse.type, "exited", "Tab should consider itself exited."); + is(aResponse.error, "noSuchActor", "Tab should be gone."); finish_test(); }); } diff --git a/browser/devtools/debugger/test/browser_dbg_propertyview-01.js b/browser/devtools/debugger/test/browser_dbg_propertyview-01.js index d974981f7d7..f1923f7a8cc 100644 --- a/browser/devtools/debugger/test/browser_dbg_propertyview-01.js +++ b/browser/devtools/debugger/test/browser_dbg_propertyview-01.js @@ -85,7 +85,6 @@ function resumeAndFinish() { gDebugger.StackFrames.activeThread.resume(function() { let vs = gDebugger.DebuggerView.Scripts; let ss = gDebugger.SourceScripts; - ss.onScriptsCleared(); is(ss._trimUrlQuery("a/b/c.d?test=1&random=4"), "a/b/c.d", "Trimming the url query isn't done properly."); diff --git a/browser/devtools/debugger/test/browser_dbg_propertyview-07.js b/browser/devtools/debugger/test/browser_dbg_propertyview-07.js index 3ae2055cfa2..4c1b9f1e3a2 100644 --- a/browser/devtools/debugger/test/browser_dbg_propertyview-07.js +++ b/browser/devtools/debugger/test/browser_dbg_propertyview-07.js @@ -25,8 +25,9 @@ function test() function testFrameParameters() { - gDebugger.addEventListener("Debugger:FetchedParameters", function test() { - gDebugger.removeEventListener("Debugger:FetchedParameters", test, false); + // scriptsadded is fired last when switching to a paused state, so the + // property view will have had a chance to fetch the call parameters. + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: function() { var frames = gDebugger.DebuggerView.Stackframes._frames, @@ -69,7 +70,7 @@ function testFrameParameters() resumeAndFinish(); }}, 0); - }, false); + }); EventUtils.sendMouseEvent({ type: "click" }, content.document.querySelector("button"), diff --git a/browser/devtools/debugger/test/browser_dbg_propertyview-08.js b/browser/devtools/debugger/test/browser_dbg_propertyview-08.js index 04434445081..59765da70fc 100644 --- a/browser/devtools/debugger/test/browser_dbg_propertyview-08.js +++ b/browser/devtools/debugger/test/browser_dbg_propertyview-08.js @@ -25,8 +25,9 @@ function test() function testFrameParameters() { - gDebugger.addEventListener("Debugger:FetchedParameters", function test() { - gDebugger.removeEventListener("Debugger:FetchedParameters", test, false); + // scriptsadded is fired last when switching to a paused state, so the + // property view will have had a chance to fetch the call parameters. + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: function() { var frames = gDebugger.DebuggerView.Stackframes._frames, @@ -85,7 +86,7 @@ function testFrameParameters() resumeAndFinish(); }, 100); }}, 0); - }, false); + }); EventUtils.synthesizeMouseAtCenter(content.document.querySelector("button"), {}, diff --git a/browser/devtools/debugger/test/browser_dbg_script-switching.js b/browser/devtools/debugger/test/browser_dbg_script-switching.js index 9bdb87fded5..1a08ff7f2b6 100644 --- a/browser/devtools/debugger/test/browser_dbg_script-switching.js +++ b/browser/devtools/debugger/test/browser_dbg_script-switching.js @@ -31,7 +31,7 @@ function test() } function testScriptsDisplay() { - gPane.activeThread.addOneTimeListener("framesadded", function() { + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: function() { gScripts = gDebugger.DebuggerView.Scripts._scripts; diff --git a/browser/devtools/debugger/test/browser_dbg_stack-05.js b/browser/devtools/debugger/test/browser_dbg_stack-05.js index 9731a9230f8..d5884d15e7d 100644 --- a/browser/devtools/debugger/test/browser_dbg_stack-05.js +++ b/browser/devtools/debugger/test/browser_dbg_stack-05.js @@ -26,7 +26,7 @@ function test() { } function testRecurse() { - gPane.activeThread.addOneTimeListener("framesadded", function() { + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: function() { let frames = gDebugger.DebuggerView.Stackframes._frames; let childNodes = frames.childNodes; diff --git a/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js b/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js index 717d2cb2323..7a1a44400a1 100644 --- a/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js +++ b/browser/devtools/debugger/test/browser_dbg_update-editor-mode.js @@ -31,7 +31,7 @@ function test() } function testScriptsDisplay() { - gPane.activeThread.addOneTimeListener("framesadded", function() { + gPane.activeThread.addOneTimeListener("scriptsadded", function() { Services.tm.currentThread.dispatch({ run: function() { gScripts = gDebugger.DebuggerView.Scripts._scripts; diff --git a/browser/devtools/webconsole/test/browser_gcli_break.js b/browser/devtools/webconsole/test/browser_gcli_break.js index da33681d323..c1192a2674f 100644 --- a/browser/devtools/webconsole/test/browser_gcli_break.js +++ b/browser/devtools/webconsole/test/browser_gcli_break.js @@ -73,7 +73,7 @@ function testCreateCommands() { // Wait for the initial resume. aPane.debuggerWindow.gClient.addOneTimeListener("resumed", function() { delete aPane.onConnected; - aPane.debuggerWindow.gClient.activeThread.addOneTimeListener("framesadded", function() { + aPane.debuggerWindow.gClient.activeThread.addOneTimeListener("scriptsadded", function() { type("break add line " + TEST_URI + " " + content.wrappedJSObject.line0); is(requisition.getStatus().toString(), "VALID", "break add line is VALID"); requisition.exec(); diff --git a/browser/locales/en-US/chrome/browser/devtools/debugger.properties b/browser/locales/en-US/chrome/browser/devtools/debugger.properties index 90642b1581c..6652f8f5467 100644 --- a/browser/locales/en-US/chrome/browser/devtools/debugger.properties +++ b/browser/locales/en-US/chrome/browser/devtools/debugger.properties @@ -30,7 +30,7 @@ localScope=Local # pane as a header on the globel scope container. globalScope=Global -# LOCALIZATION NOTE (withScope): The label that is displayed in the variables +# LOCALIZATION NOTE (localScope): The label that is displayed in the variables # pane as a header on the container for identifiers in a with block. withScope=With block diff --git a/toolkit/devtools/debugger/server/dbg-browser-actors.js b/toolkit/devtools/debugger/server/dbg-browser-actors.js index 97c9dbb8f7d..02e95c21ef3 100644 --- a/toolkit/devtools/debugger/server/dbg-browser-actors.js +++ b/toolkit/devtools/debugger/server/dbg-browser-actors.js @@ -67,6 +67,7 @@ function BrowserRootActor(aConnection) this._actorFactories = null; this.onTabClosed = this.onTabClosed.bind(this); + this._onWindowCreated = this.onWindowCreated.bind(this); windowMediator.addListener(this); } @@ -75,6 +76,10 @@ BrowserRootActor.prototype = { * Return a 'hello' packet as specified by the Remote Debugging Protocol. */ sayHello: function BRA_sayHello() { + // Create the tab actor for the selected tab right away so that it gets a + // chance to listen to onNewScript notifications. + this._preInitTabActor(); + return { from: "root", applicationType: "browser", traits: [] }; @@ -118,10 +123,6 @@ BrowserRootActor.prototype = { while (e.hasMoreElements()) { let win = e.getNext(); - // Watch the window for tab closes so we can invalidate - // actors as needed. - this.watchWindow(win); - // List the tabs in this browser. let selectedBrowser = win.getBrowser().selectedBrowser; let browsers = win.getBrowser().browsers; @@ -182,16 +183,61 @@ BrowserRootActor.prototype = { this.exitTabActor(aEvent.target.linkedBrowser); }, + /** + * Handle location changes, by preinitializing a tab actor. + */ + onWindowCreated: function BRA_onWindowCreated(evt) { + if (evt.target === this.browser.contentDocument) { + this._preInitTabActor(); + } + }, + /** * Exit the tab actor of the specified tab. */ exitTabActor: function BRA_exitTabActor(aWindow) { + this.browser.removeEventListener("DOMWindowCreated", this._onWindowCreated, true); let actor = this._tabActors.get(aWindow); if (actor) { actor.exit(); } }, + /** + * Create the tab actor in the selected tab right away so that it gets a + * chance to listen to onNewScript notifications. + */ + _preInitTabActor: function BRA__preInitTabActor() { + let actorPool = new ActorPool(this.conn); + + // Walk over open browser windows. + let e = windowMediator.getEnumerator("navigator:browser"); + while (e.hasMoreElements()) { + let win = e.getNext(); + + // Watch the window for tab closes so we can invalidate + // actors as needed. + this.watchWindow(win); + + this.browser = win.getBrowser().selectedBrowser; + let actor = this._tabActors.get(this.browser); + if (actor) { + actor._detach(); + } + actor = new BrowserTabActor(this.conn, this.browser); + actor.parentID = this.actorID; + this._tabActors.set(this.browser, actor); + + actorPool.addActor(actor); + } + + this._tabActorPool = actorPool; + this.conn.addActorPool(this._tabActorPool); + + // Watch for globals being created in this tab. + this.browser.addEventListener("DOMWindowCreated", this._onWindowCreated, true); + }, + // nsIWindowMediatorListener onWindowTitleChange: function BRA_onWindowTitleChange(aWindow, aTitle) { }, onOpenWindow: function BRA_onOpenWindow(aWindow) { }, @@ -224,6 +270,7 @@ function BrowserTabActor(aConnection, aBrowser) this._browser = aBrowser; this._onWindowCreated = this.onWindowCreated.bind(this); + this._attach(); } // XXX (bug 710213): BrowserTabActor attach/detach/exit/disconnect is a @@ -294,7 +341,7 @@ BrowserTabActor.prototype = { this._pushContext(); // Watch for globals being created in this tab. - this.browser.addEventListener("DOMWindowCreated", this._onWindowCreated, true); + this.browser.addEventListener("DOMWindowCreated", this._onWindowCreated, false); this._attached = true; }, @@ -335,7 +382,7 @@ BrowserTabActor.prototype = { return; } - this.browser.removeEventListener("DOMWindowCreated", this._onWindowCreated, true); + this.browser.removeEventListener("DOMWindowCreated", this._onWindowCreated, false); this._popContext(); diff --git a/toolkit/devtools/debugger/server/dbg-script-actors.js b/toolkit/devtools/debugger/server/dbg-script-actors.js index 135cedfd0f8..2274aec94c0 100644 --- a/toolkit/devtools/debugger/server/dbg-script-actors.js +++ b/toolkit/devtools/debugger/server/dbg-script-actors.js @@ -99,12 +99,19 @@ ThreadActor.prototype = { this._dbg = new Debugger(); } + // TODO: Remove this horrible hack when bug 723563 is fixed. + // Make sure that a chrome window is not added as a debuggee when opening + // the debugger in an empty tab or during tests. + if (aGlobal.location && + (aGlobal.location.protocol == "about:" || + aGlobal.location.protocol == "chrome:")) { + return; + } + this.dbg.addDebuggee(aGlobal); this.dbg.uncaughtExceptionHook = this.uncaughtExceptionHook.bind(this); this.dbg.onDebuggerStatement = this.onDebuggerStatement.bind(this); this.dbg.onNewScript = this.onNewScript.bind(this); - // Keep the debugger disabled until a client attaches. - this.dbg.enabled = false; }, /** @@ -496,11 +503,6 @@ ThreadActor.prototype = { * Handle a protocol request to return the list of loaded scripts. */ onScripts: function TA_onScripts(aRequest) { - // Get the script list from the debugger. - for (let s of this.dbg.findScripts()) { - this._addScript(s); - } - // Build the cache. let scripts = []; for (let url in this._scripts) { for (let i = 0; i < this._scripts[url].length; i++) { @@ -857,34 +859,28 @@ ThreadActor.prototype = { }, /** - * A function that the engine calls when a new script has been loaded into the - * scope of the specified debuggee global. + * A function that the engine calls when a new script has been loaded into a + * debuggee compartment. If the new code is part of a function, aFunction is + * a Debugger.Object reference to the function object. (Not all code is part + * of a function; for example, the code appearing in a