From f4757d7c63e86d6485092ca7a08f04e1edc18db3 Mon Sep 17 00:00:00 2001 From: wartmanm Date: Tue, 4 Aug 2020 18:41:53 +0000 Subject: [PATCH] Bug 1656726 - Pause On Exceptions, DOM mutation breakpoints, debugger statements pause in blackboxed original sources r=davidwalsh Differential Revision: https://phabricator.services.mozilla.com/D85718 --- .../browser_dbg-dom-mutation-breakpoints.js | 21 ++++++++++++++++ .../mochitest/examples/doc-dom-mutation.html | 11 ++------- .../test/mochitest/examples/dom-mutation.js | 9 +++++++ .../mochitest/examples/dom-mutation.js.map | 1 + devtools/server/actors/thread.js | 23 ++++-------------- .../tests/xpcshell/test_blackboxing-03.js | 23 ++++++++++++++++++ .../tests/xpcshell/test_blackboxing-05.js | 24 +++++++++++++++++++ 7 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 devtools/client/debugger/test/mochitest/examples/dom-mutation.js create mode 100644 devtools/client/debugger/test/mochitest/examples/dom-mutation.js.map diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js b/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js index 2fc90d9d3822..8ab7a1d08003 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js @@ -73,7 +73,28 @@ add_task(async function() { await waitForPaused(dbg); await resume(dbg); + info("Blackboxing the source prevents debugger pause"); + await waitForSource(dbg, "dom-mutation.original.js"); + + const source = findSource(dbg, "dom-mutation.original.js"); + + await selectSource(dbg, source); + await clickElement(dbg, "blackbox"); + await waitForDispatch(dbg, "BLACKBOX"); + + SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() { + content.document.querySelector("#blackbox").click(); + }); + + await waitForPaused(dbg, "click.js"); + await resume(dbg); + + await selectSource(dbg, source); + await clickElement(dbg, "blackbox"); + await waitForDispatch(dbg, "BLACKBOX"); + info("Removing breakpoints works"); dbg.win.document.querySelector(".dom-mutation-list .close-btn").click(); await waitForAllElements(dbg, "domMutationItem", 1, true); + }); diff --git a/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html b/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html index c7833d618df6..5ad60f4c6439 100644 --- a/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html +++ b/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html @@ -11,14 +11,7 @@ - + + diff --git a/devtools/client/debugger/test/mochitest/examples/dom-mutation.js b/devtools/client/debugger/test/mochitest/examples/dom-mutation.js new file mode 100644 index 000000000000..3d3f5c75d8eb --- /dev/null +++ b/devtools/client/debugger/test/mochitest/examples/dom-mutation.js @@ -0,0 +1,9 @@ +function changeAttribute() { + const title = document.body.title === "Goodbye" ? "Hello" : "Goodbye"; + document.body.setAttribute("title", title); +} + +function changeSubtree() { + document.body.appendChild(document.createElement("div")); +} +//# sourceMappingURL=dom-mutation.js.map diff --git a/devtools/client/debugger/test/mochitest/examples/dom-mutation.js.map b/devtools/client/debugger/test/mochitest/examples/dom-mutation.js.map new file mode 100644 index 000000000000..5e1e252b4653 --- /dev/null +++ b/devtools/client/debugger/test/mochitest/examples/dom-mutation.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["dom-mutation.original.js"],"names":[],"mappings":"AAAA,QAAQ,CAAC,eAAe,IAAI;EAC1B,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,MAAM,OAAO,KAAK,KAAK,KAAK,OAAO,EAAE;EACtE,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,GAAG,KAAK,EAAE;CAC5C;AACD;AACA,QAAQ,CAAC,aAAa,IAAI;EACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,GAAG,IAAI;CAC1D;IACG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG;AACxC","file":"dom-mutation.js","sourcesContent":["function changeAttribute() {\n const title = document.body.title === \"Goodbye\" ? \"Hello\" : \"Goodbye\";\n document.body.setAttribute(\"title\", title);\n}\n\nfunction changeSubtree() {\n document.body.appendChild(document.createElement(\"div\"));\n}\n"]} \ No newline at end of file diff --git a/devtools/server/actors/thread.js b/devtools/server/actors/thread.js index 951de9bb452e..dd9ffe628e2b 100644 --- a/devtools/server/actors/thread.js +++ b/devtools/server/actors/thread.js @@ -765,9 +765,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { } else if (!notification.phase && !this._activeEventPause) { const frame = this.dbg.getNewestFrame(); if (frame) { - const { sourceActor } = this.sources.getFrameLocation(frame); - const { url } = sourceActor; - if (this.sources.isBlackBoxed(url)) { + if (this.sources.isFrameBlackBoxed(frame)) { return; } @@ -778,11 +776,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { _makeEventBreakpointEnterFrame(eventBreakpoint) { return frame => { - const location = this.sources.getFrameLocation(frame); - const { sourceActor, line, column } = location; - const { url } = sourceActor; - - if (this.sources.isBlackBoxed(url, line, column)) { + if (this.sources.isFrameBlackBoxed(frame)) { return undefined; } @@ -1805,9 +1799,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { return undefined; } - const location = this.sources.getFrameLocation(frame); - - if (this.skipBreakpoints || this.sources.isBlackBoxed(location.sourceUrl)) { + if (this.skipBreakpoints || this.sources.isFrameBlackBoxed(frame)) { return undefined; } @@ -1852,8 +1844,6 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { * The stack frame that contained the debugger statement. */ onDebuggerStatement: function(frame) { - const location = this.sources.getFrameLocation(frame); - // Don't pause if // 1. we have not moved since the last pause // 2. breakpoints are disabled @@ -1862,7 +1852,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { if ( !this.hasMoved(frame, "debuggerStatement") || this.skipBreakpoints || - this.sources.isBlackBoxed(location.sourceUrl) || + this.sources.isFrameBlackBoxed(frame) || this.atBreakpointLocation(frame) ) { return undefined; @@ -1922,16 +1912,13 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { return undefined; } - const { sourceActor } = this.sources.getFrameLocation(youngestFrame); - const url = sourceActor ? sourceActor.url : null; - // Don't pause on exceptions thrown while inside an evaluation being done on // behalf of the client. if (this.insideClientEvaluation) { return undefined; } - if (this.skipBreakpoints || this.sources.isBlackBoxed(url)) { + if (this.skipBreakpoints || this.sources.isFrameBlackBoxed(youngestFrame)) { return undefined; } diff --git a/devtools/server/tests/xpcshell/test_blackboxing-03.js b/devtools/server/tests/xpcshell/test_blackboxing-03.js index a3b276fd66c5..c3feccddc12d 100644 --- a/devtools/server/tests/xpcshell/test_blackboxing-03.js +++ b/devtools/server/tests/xpcshell/test_blackboxing-03.js @@ -55,6 +55,29 @@ add_task( "We should stop at the debugger statement again" ); await threadFront.resume(); + + // Test the debugger statement in the black boxed range + threadFront.setBreakpoint({ sourceUrl: source.url, line: 4 }, {}); + + await blackBox(sourceFront, { + start: { line: 1, column: 0 }, + end: { line: 9, column: 0 }, + }); + + const packet4 = await executeOnNextTickAndWaitForPause( + debuggee.runTest, + threadFront + ); + + Assert.equal( + packet4.why.type, + "breakpoint", + "We should pass over the debugger statement." + ); + + threadFront.removeBreakpoint({ sourceUrl: source.url, line: 4 }, {}); + await unBlackBox(sourceFront); + await threadFront.resume(); }) ); diff --git a/devtools/server/tests/xpcshell/test_blackboxing-05.js b/devtools/server/tests/xpcshell/test_blackboxing-05.js index 55fad7213b24..59acbc353047 100644 --- a/devtools/server/tests/xpcshell/test_blackboxing-05.js +++ b/devtools/server/tests/xpcshell/test_blackboxing-05.js @@ -31,6 +31,30 @@ add_task( SOURCE_URL, "We shouldn't pause while in the black boxed source." ); + + await unBlackBox(sourceFront); + await blackBox(sourceFront, { + start: { line: 1, column: 0 }, + end: { line: 4, column: 0 }, + }); + + await threadFront.resume(); + + await executeOnNextTickAndWaitForPause( + () => evalCode(debuggee), + threadFront + ); + + threadFront.resume(); + const packet2 = await waitForPause(threadFront); + const source2 = await getSourceById(threadFront, packet2.frame.where.actor); + + Assert.equal( + source2.url, + SOURCE_URL, + "We shouldn't pause while in the black boxed source." + ); + await threadFront.resume(); }) );