From 089f2bed9ba92f688709d89e65273309a07cfef9 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 28 Aug 2009 12:04:01 +0200 Subject: QScriptContextInfo: fix the line numbers with JIT It even works better than with the interpreter --- src/script/api/qscriptcontextinfo.cpp | 14 +++++++++++--- tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 10 ++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/script/api/qscriptcontextinfo.cpp b/src/script/api/qscriptcontextinfo.cpp index e59b773..890ed9d 100644 --- a/src/script/api/qscriptcontextinfo.cpp +++ b/src/script/api/qscriptcontextinfo.cpp @@ -50,6 +50,9 @@ #include #include "CodeBlock.h" #include "JSFunction.h" +#if ENABLE(JIT) +#include "MacroAssemblerCodeRef.h" +#endif QT_BEGIN_NAMESPACE @@ -154,7 +157,7 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte lineNumber = -1; columnNumber = -1; - const JSC::ExecState *frame = QScriptEnginePrivate::frameForContext(context); + JSC::CallFrame *frame = const_cast(QScriptEnginePrivate::frameForContext(context)); // Get the line number: @@ -171,8 +174,13 @@ QScriptContextInfoPrivate::QScriptContextInfoPrivate(const QScriptContext *conte JSC::Instruction *returnPC = aboveFrame->returnPC(); JSC::CodeBlock *codeBlock = frame->codeBlock(); if (returnPC && codeBlock) { - lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast(frame), - returnPC - codeBlock->instructions().begin() -1); +#if ENABLE(JIT) + unsigned bytecodeOffset = codeBlock->getBytecodeIndex(frame, JSC::ReturnAddressPtr(returnPC)); +#else + unsigned bytecodeOffset = returnPC - codeBlock->instructions().begin(); +#endif + bytecodeOffset--; //because returnPC is on the next instruction. We want the current one + lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast(frame), bytecodeOffset); } } } else { diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index ef609e0..a85c0bd 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -598,8 +598,11 @@ void tst_QScriptContext::backtrace_data() expected << "('hey') at -1" << "() at 3" - //### line number should be 2 but the line number information is not kept for eval call +#ifdef ENABLE_JIT + << "foo(arg1 = 'hello', arg2 = 456) at testfile:2" +#else //### interpreter unfortunately does store information about line number for eval() << "foo(arg1 = 'hello', arg2 = 456) at testfile:-1" +#endif << "() at testfile:4"; QTest::newRow("eval") << source << expected; @@ -658,8 +661,11 @@ void tst_QScriptContext::backtrace_data() expected << "('hey') at -1" << "() at 3" - //### line number should be 3 but the line number information is not kept for eval call +#ifdef ENABLE_JIT + << "plop('hello', 456) at testfile:3" +#else //### interpreter unfortunately does store information about line number for eval() << "plop('hello', 456) at testfile:-1" +#endif << "() at testfile:5"; QTest::newRow("eval in member") << source << expected; -- cgit v0.12