Bug 1432885 - Step in to the first valid step target, r=loganfsmyth.

--HG--
extra : rebase_source : 63a7f8f5f1bc4f416e9a330576dc25ccd57222fc
extra : histedit_source : 71d4d3c9374a1a85c343a7126a10a869cebca11d
This commit is contained in:
Brian Hackett 2019-05-14 07:11:04 -10:00
parent 3221e13d38
commit 3a6942403b
4 changed files with 74 additions and 9 deletions

View File

@ -666,6 +666,7 @@ support-files =
examples/doc-event-handler.html
examples/doc-eval-throw.html
examples/doc-sourceURL-breakpoint.html
examples/doc-step-in-uninitialized.html
[browser_dbg-asm.js]
[browser_dbg-audiocontext.js]
@ -779,6 +780,7 @@ skip-if = os == 'linux' && !asan # bug 1447118
skip-if = true
[browser_dbg-stepping.js]
skip-if = debug || (verify && (os == 'win')) || (os == "win" && os_version == "6.1")
[browser_dbg-step-in-uninitialized.js]
[browser_dbg-tabs.js]
[browser_dbg-tabs-keyboard.js]
skip-if = os == "win"

View File

@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// When stepping into a function, 'let' variables should show as uninitialized
// instead of undefined.
function findNodeValue(dbg, text) {
for (let index = 0;; index++) {
var elem = findElement(dbg, "scopeNode", index);
if (elem && elem.innerText == text) {
return findElement(dbg, "scopeValue", index).innerText;
}
}
}
add_task(async function test() {
const dbg = await initDebugger("doc-step-in-uninitialized.html");
invokeInTab("main");
await waitForPaused(dbg, "doc-step-in-uninitialized.html");
await stepOver(dbg);
await stepIn(dbg);
assertDebugLine(dbg, 8);
assertPausedLocation(dbg);
// We step past the 'let x' at the start of the function because it is not
// a breakpoint position.
ok(findNodeValue(dbg, "x") == "undefined", "x undefined");
ok(findNodeValue(dbg, "y") == "(uninitialized)", "y uninitialized");
await stepOver(dbg);
assertDebugLine(dbg, 9);
ok(findNodeValue(dbg, "y") == "3", "y initialized");
});

View File

@ -0,0 +1,11 @@
<script>
function main() {
debugger;
foo();
}
function foo() {
let x;
let y = 3;
return 0;
}
</script>

View File

@ -557,7 +557,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
return this._parentClosed ? null : undefined;
},
_makeOnEnterFrame: function({ pauseAndRespond }) {
_makeOnEnterFrame: function({ thread, pauseAndRespond }) {
return frame => {
const { generatedSourceActor } = this.sources.getFrameLocation(frame);
@ -566,7 +566,27 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
return undefined;
}
return pauseAndRespond(frame);
// If the initial frame offset is a step target, we are done.
if (frame.script.getOffsetMetadata(frame.offset).isStepStart) {
return pauseAndRespond(frame);
}
// Continue forward until we get to a valid step target.
const { onStep, onPop } = thread._makeSteppingHooks(
null, "next", false, null
);
if (thread.dbg.replaying) {
const offsets =
thread._findReplayingStepOffsets(null, frame,
/* rewinding = */ false);
frame.setReplayingOnStep(onStep, offsets);
} else {
frame.onStep = onStep;
}
frame.onPop = onPop;
return undefined;
};
},
@ -646,7 +666,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
const generatedLocation = this.sources.getScriptOffsetLocation(script, offset);
if (startLocation.generatedUrl !== generatedLocation.generatedUrl) {
if (!startLocation || startLocation.generatedUrl !== generatedLocation.generatedUrl) {
return true;
}
@ -675,12 +695,6 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
_makeOnStep: function({ thread, pauseAndRespond, startFrame,
startLocation, steppingType, completion, rewinding }) {
// Breaking in place: we should always pause.
if (steppingType === "break") {
return () => pauseAndRespond(this);
}
// Otherwise take what a "step" means into consideration.
return function() {
// onStep is called with 'this' set to the current frame.