Bug 911065 - Fix source notes for for/of loops. r=jorendorff

This commit is contained in:
Nick Fitzgerald 2014-11-13 13:58:00 -05:00
parent 37012e9ef6
commit 1193ea6fba
2 changed files with 37 additions and 2 deletions

View File

@ -4828,6 +4828,7 @@ EmitForOf(ExclusiveContext *cx, BytecodeEmitter *bce, StmtType type, ParseNode *
MOZ_ASSERT_IF(type == STMT_SPREAD, !pn);
ParseNode *forHead = pn ? pn->pn_left : nullptr;
ParseNode *forHeadExpr = forHead ? forHead->pn_kid3 : nullptr;
ParseNode *forBody = pn ? pn->pn_right : nullptr;
ParseNode *pn1 = forHead ? forHead->pn_kid1 : nullptr;
@ -4840,7 +4841,7 @@ EmitForOf(ExclusiveContext *cx, BytecodeEmitter *bce, StmtType type, ParseNode *
// current result object.
// Compile the object expression to the right of 'of'.
if (!EmitTree(cx, bce, forHead->pn_kid3))
if (!EmitTree(cx, bce, forHeadExpr))
return false;
if (!EmitIterator(cx, bce))
return false;
@ -4920,7 +4921,7 @@ EmitForOf(ExclusiveContext *cx, BytecodeEmitter *bce, StmtType type, ParseNode *
// COME FROM the beginning of the loop to here.
SetJumpOffsetAt(bce, jmp);
if (!EmitLoopEntry(cx, bce, nullptr))
if (!EmitLoopEntry(cx, bce, forHeadExpr))
return false;
if (type == STMT_FOR_OF_LOOP) {

View File

@ -0,0 +1,34 @@
var g = newGlobal();
var dbg = new Debugger;
var gw = dbg.addDebuggee(g);
g.eval(` // 1
var line0 = Error().lineNumber; // 2
function f() { // 3
for (var x of [0]) { // 4
if (true == false) // 5
return false; // 6, aka line0 + 4
} // 7
return true; // 8
} // 9
`); // 10
if (g.dis)
g.dis(g.f);
var script = gw.getOwnPropertyDescriptor("f").value.script;
print("Debugger's view:");
print("----------------");
for (var i = script.startLine; i <= script.startLine + script.lineCount; i++) {
print("Line " + i + ": " + JSON.stringify(script.getLineOffsets(i)));
}
var hits = 0;
var handler = {hit: function () { hits++; }};
var offs = script.getLineOffsets(g.line0 + 4);
for (var i = 0; i < offs.length; i++)
script.setBreakpoint(offs[i], handler);
assertEq(g.f(), true);
assertEq(hits, 0);