From 93f017401ce8bb73415f88955e928a90c6759fc0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 17 Aug 2009 09:19:02 +0200 Subject: Fix the line numbers on the backtrace The returnPC points to the opcode after the call, but we want the opcode right before to compute the line number. Reviewed-by: Kent Hansen --- src/script/api/qscriptcontextinfo.cpp | 2 +- tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/script/api/qscriptcontextinfo.cpp b/src/script/api/qscriptcontextinfo.cpp index a305116..04c26e2 100644 --- a/src/script/api/qscriptcontextinfo.cpp +++ b/src/script/api/qscriptcontextinfo.cpp @@ -172,7 +172,7 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte JSC::CodeBlock *codeBlock = frame->codeBlock(); if (returnPC && codeBlock) { lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast(frame), - returnPC - codeBlock->instructions().begin()); + returnPC - codeBlock->instructions().begin() -1); } } } diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index c09ebdb..e5d26a3 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -574,7 +574,8 @@ void tst_QScriptContext::backtrace_data() "function foo() {\n" " return bt(123);\n" "}\n" - "foo('hello', { })" ); + "foo('hello', { })\n" + "var r = 0;"); QTest::newRow("simple") << source << expected; } @@ -585,12 +586,14 @@ void tst_QScriptContext::backtrace_data() "function foo(arg1 , arg2) {\n" " return eval(\"%1\");\n" "}\n" - "foo('hello', 456)" + "foo('hello', 456)\n" + "var a = 0;" ).arg("\\n \\n bt('hey'); \\n"); expected << "('hey') at -1" << "() at 3" - << "foo(arg1 = 'hello', arg2 = 456) at testfile:-1" //### line number should be 2 + //### line number should be 2 but the line number information is not kept for eval call + << "foo(arg1 = 'hello', arg2 = 456) at testfile:-1" << "() at testfile:4"; QTest::newRow("eval") << source << expected; -- cgit v0.12