Bug 1362403 - update source coordinates after emitting loop bodies; r=jimb
authorTom Tromey <tom@tromey.com>
Fri, 05 May 2017 11:50:56 -0600
changeset 356798 3e44cbaec84b4412136e9b36a8403a88cc6b7742
parent 356797 ed74f44b40c1cc58bfe3cd628fc5834336be6081
child 356850 3633cb2d5260126d77c82fb61bc9e8548032ee38
push id42155
push userttromey@mozilla.com
push dateFri, 05 May 2017 20:22:56 +0000
treeherderautoland@3e44cbaec84b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1362403
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -7275,16 +7275,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
 
@@ -7483,16 +7487,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");