Bug 1362403 - update source coordinates after emitting loop bodies; r?jimb draft
authorTom Tromey <tom@tromey.com>
Fri, 05 May 2017 11:50:56 -0600
changeset 573381 1cffc14bb5f8d26f36036945d44734cd1a5ae8b1
parent 572050 1d48480b558a32e8b4f9ada8c9e0bc143e200ca4
child 573475 f64ce4a0b92fea4c1a6a56ac7c24b6fed723c554
push id57375
push userbmo:ttromey@mozilla.com
push dateFri, 05 May 2017 17:51:08 +0000
reviewersjimb
bugs1362403
milestone55.0a1
Bug 1362403 - update source coordinates after emitting loop bodies; r?jimb MozReview-Commit-ID: CEJV2nSvg24
js/src/frontend/BytecodeEmitter.cpp
js/src/jit-test/tests/debug/Frame-onStep-17.js
--- 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");