From 878f6df1978a7edc87a616ba8029cf3b993d6653 Mon Sep 17 00:00:00 2001 From: wartmanm Date: Tue, 3 Mar 2020 18:44:43 +0000 Subject: [PATCH] Bug 1548469 - Step in to the next script r=jlast Depends on D65008 Differential Revision: https://phabricator.services.mozilla.com/D65009 --HG-- extra : moz-landing-system : lando --- devtools/server/actors/thread.js | 17 +++-- .../server/tests/xpcshell/test_stepping-17.js | 75 +++++++++++++++++++ devtools/server/tests/xpcshell/xpcshell.ini | 1 + 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 devtools/server/tests/xpcshell/test_stepping-17.js diff --git a/devtools/server/actors/thread.js b/devtools/server/actors/thread.js index 433471a4821b..e82c06775543 100644 --- a/devtools/server/actors/thread.js +++ b/devtools/server/actors/thread.js @@ -840,6 +840,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { frame.onStep = onStep; frame.onPop = onPop; + frame.waitingOnStep = true; return undefined; }; }, @@ -1025,19 +1026,25 @@ const ThreadActor = ActorClassWithSpec(threadSpec, { steppingType = "next"; } + // If there are no more frames on the stack, use "step" mode so that we will + // pause on the next script to execute. + const stepFrame = this._getNextStepFrame(frame); + if (!stepFrame) { + steppingType = "step"; + } + const { onEnterFrame, onPop, onStep } = this._makeSteppingHooks({ steppingType, completion, }); - // Make sure there is still a frame on the stack if we are to continue - // stepping. - const stepFrame = this._getNextStepFrame(frame); + if (steppingType === "step") { + this.dbg.onEnterFrame = onEnterFrame; + } + if (stepFrame) { switch (steppingType) { case "step": - this.dbg.onEnterFrame = onEnterFrame; - // Fall through. case "break": case "next": if (stepFrame.script) { diff --git a/devtools/server/tests/xpcshell/test_stepping-17.js b/devtools/server/tests/xpcshell/test_stepping-17.js new file mode 100644 index 000000000000..364070431e82 --- /dev/null +++ b/devtools/server/tests/xpcshell/test_stepping-17.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* + * Check that you can step from one script or event to another + */ + +add_task( + threadFrontTest(async ({ threadFront, targetFront, debuggee }) => { + const consoleFront = await targetFront.getFront("console"); + + Cu.evalInSandbox( + `function blackboxed(callback) { return () => callback(); }`, + debuggee, + "1.8", + "http://example.com/blackboxed.js", + 1 + ); + + const { sources } = await getSources(threadFront); + const blackboxedSourceFront = threadFront.source( + sources.find(source => source.url == "http://example.com/blackboxed.js") + ); + blackBox(blackboxedSourceFront); + + const testStepping = async function(wrapperName, stepHandler, message) { + consoleFront.evaluateJSAsync( + `(function () { + const p = Promise.resolve(); + p.then(${wrapperName}(() => { debugger; })) + .then(${wrapperName}(() => { })); + })();` + ); + + await waitForEvent(threadFront, "paused"); + const step = await stepHandler(threadFront); + Assert.equal(step.frame.where.line, 4, message); + await resume(threadFront); + }; + + const stepTwice = async function() { + await stepOver(threadFront); + return stepOver(threadFront); + }; + + await testStepping("", stepTwice, "Step over on the outermost frame"); + await testStepping("blackboxed", stepTwice, "Step over with blackboxing"); + await testStepping("", stepOut, "Step out on the outermost frame"); + await testStepping("blackboxed", stepOut, "Step out with blackboxing"); + + consoleFront.evaluateJSAsync( + `(async function () { + const p = Promise.resolve(); + const p2 = p.then(() => { + debugger; + return "async stepping!"; + }); + debugger; + await p; + const result = await p2; + return result; + })(); + ` + ); + + await waitForEvent(threadFront, "paused"); + await stepOver(threadFront); + await stepOver(threadFront); + const step = await stepOut(threadFront); + await resume(threadFront); + Assert.equal(step.frame.where.line, 9, "Step out of promise into async fn"); + }) +); diff --git a/devtools/server/tests/xpcshell/xpcshell.ini b/devtools/server/tests/xpcshell/xpcshell.ini index e5a650a39647..e6ffbec107c8 100644 --- a/devtools/server/tests/xpcshell/xpcshell.ini +++ b/devtools/server/tests/xpcshell/xpcshell.ini @@ -183,6 +183,7 @@ skip-if = true # breakpoint sliding is not supported bug 1525685 [test_stepping-14.js] [test_stepping-15.js] [test_stepping-16.js] +[test_stepping-17.js] [test_stepping-with-skip-breakpoints.js] [test_framebindings-01.js] [test_framebindings-02.js]