Add a source location to the final Jump in a for loop

Otherwise it will assume the last statement as the location of the
jump, and that might be a statement that is never hit.

Task-number: QTBUG-59204
Change-Id: I66019a284b061358939b23e649ca0832b5442388
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Ulf Hermann 2017-02-28 15:07:42 +01:00
parent 5a9fd4f49e
commit c67d33db5b
2 changed files with 27 additions and 1 deletions

View File

@ -2499,7 +2499,7 @@ bool Codegen::visit(LocalForStatement *ast)
_block = forbody;
statement(ast->statement);
_block->JUMP(forstep);
setLocation(_block->JUMP(forstep), ast->lastSourceLocation());
_block = forstep;
statement(ast->expression);

View File

@ -327,6 +327,7 @@ private slots:
void evaluateExpression();
void stepToEndOfScript();
void lastLineOfLoop();
private:
QV4Debugger *debugger() const
@ -786,6 +787,31 @@ void tst_qv4debugger::stepToEndOfScript()
QCOMPARE(state.lineNumber, -4); // A return instruction without proper line number.
}
void tst_qv4debugger::lastLineOfLoop()
{
QString script =
"var ret = 0;\n"
"for (var i = 0; i < 10; ++i) {\n"
" if (i == 2)\n"
" ret += 4;\n" // breakpoint, then step over
" else \n"
" ret += 1;\n"
"}\n"; // after step over
debugger()->addBreakPoint("trueBranch", 4);
m_debuggerAgent->m_resumeSpeed = QV4Debugger::StepOver;
evaluateJavaScript(script, "trueBranch");
QVERIFY(m_debuggerAgent->m_wasPaused);
QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::Step);
QVERIFY(m_debuggerAgent->m_statesWhenPaused.count() > 1);
QV4Debugger::ExecutionState firstState = m_debuggerAgent->m_statesWhenPaused.first();
QCOMPARE(firstState.fileName, QString("trueBranch"));
QCOMPARE(firstState.lineNumber, 4);
QV4Debugger::ExecutionState secondState = m_debuggerAgent->m_statesWhenPaused.at(1);
QCOMPARE(secondState.fileName, QString("trueBranch"));
QCOMPARE(secondState.lineNumber, 7);
}
QTEST_MAIN(tst_qv4debugger)
#include "tst_qv4debugger.moc"