Bug 1362403 - update source coordinates after emitting loop bodies; r?jimb
MozReview-Commit-ID: CEJV2nSvg24
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -7138,16 +7138,20 @@ BytecodeEmitter::emitForOf(ParseNode* fo
JumpList beq;
JumpTarget breakTarget{ -1 };
{
#ifdef DEBUG
auto loopDepth = this->stackDepth;
#endif
+ // Make sure this code is attributed to the "for".
+ if (!updateSourceCoordNotes(forOfHead->pn_pos.begin))
+ return false;
+
if (!emit1(JSOP_POP)) // ITER
return false;
if (!emit1(JSOP_DUP)) // ITER ITER
return false;
if (!emitIteratorNext(forOfHead, iterKind, allowSelfHostedIter))
return false; // ITER RESULT
@@ -7346,16 +7350,20 @@ BytecodeEmitter::emitForIn(ParseNode* fo
// Perform the loop body.
ParseNode* forBody = forInLoop->pn_right;
if (!emitTree(forBody)) // ITER ITERVAL
return false;
// Set offset for continues.
loopInfo.continueTarget = { offset() };
+ // Make sure this code is attributed to the "for".
+ if (!updateSourceCoordNotes(forInHead->pn_pos.begin))
+ return false;
+
if (!emitLoopEntry(nullptr, initialJump)) // ITER ITERVAL
return false;
if (!emit1(JSOP_POP)) // ITER
return false;
if (!emit1(JSOP_MOREITER)) // ITER NEXTITERVAL?
return false;
if (!emit1(JSOP_ISNOITER)) // ITER NEXTITERVAL? ISNOITER
return false;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Frame-onStep-17.js
@@ -0,0 +1,31 @@
+var g = newGlobal();
+var dbg = new Debugger;
+var gw = dbg.addDebuggee(g);
+var log;
+var previous;
+
+dbg.onDebuggerStatement = function (frame) {
+ let debugLine = frame.script.getOffsetLocation(frame.offset).lineNumber;
+ log = '';
+ previous = '';
+ frame.onStep = function() {
+ let foundLine = this.script.getOffsetLocation(this.offset).lineNumber;
+ if (this.script.getLineOffsets(foundLine).indexOf(this.offset) >= 0) {
+ let thisline = (foundLine - debugLine).toString(16);
+ if (thisline !== previous) {
+ log += thisline;
+ previous = thisline;
+ }
+ }
+ };
+};
+
+function testOne(loopKind) {
+ let body = "var array = [2, 4, 6];\ndebugger;\nfor (let iter " +
+ loopKind + " array) {\n print(iter);\n}\n";
+ g.eval(body);
+ assertEq(log, "12121212");
+}
+
+testOne("in");
+testOne("of");