From ae49af00b59628623bc15e19974ee5af5f0121ba Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 29 Sep 2022 13:30:42 +0200 Subject: QML: Track the statement indices together with line numbers We will need the statement indices when tracking value type references. New value type references shall only be written back in the same statement they were created in. Task-number: QTBUG-99766 Change-Id: I83f908df034e7da8ba46ccacaa29bd9d78020d20 Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4stackframe.cpp | 36 ++++++++++++++++++++++++++---------- src/qml/jsruntime/qv4stackframe_p.h | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4stackframe.cpp b/src/qml/jsruntime/qv4stackframe.cpp index a02ce0edc5..e8ff9a89bc 100644 --- a/src/qml/jsruntime/qv4stackframe.cpp +++ b/src/qml/jsruntime/qv4stackframe.cpp @@ -17,21 +17,37 @@ QString CppStackFrame::function() const return v4Function ? v4Function->name()->toQString() : QString(); } -int CppStackFrame::lineNumber() const +static const CompiledData::CodeOffsetToLineAndStatement *lineAndStatement(const CppStackFrame *frame) { - if (!v4Function || instructionPointer <= 0) - return -1; + if (!frame->v4Function || frame->instructionPointer <= 0) + return nullptr; - auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) { + auto findLine = [](const CompiledData::CodeOffsetToLineAndStatement &entry, uint offset) { return entry.codeOffset < offset; }; - const QV4::CompiledData::Function *cf = v4Function->compiledFunction; - const uint offset = instructionPointer; - const CompiledData::CodeOffsetToLine *lineNumbers = cf->lineNumberTable(); - const uint nLineNumbers = cf->nLineNumbers; - const CompiledData::CodeOffsetToLine *line = std::lower_bound(lineNumbers, lineNumbers + nLineNumbers, offset, findLine) - 1; - return line->line; + const QV4::CompiledData::Function *cf = frame->v4Function->compiledFunction; + const uint offset = frame->instructionPointer; + const CompiledData::CodeOffsetToLineAndStatement *lineAndStatementNumbers + = cf->lineAndStatementNumberTable(); + const uint nLineAndStatementNumbers = cf->nLineAndStatementNumbers; + return std::lower_bound( + lineAndStatementNumbers, lineAndStatementNumbers + nLineAndStatementNumbers, + offset, findLine) - 1; +} + +int CppStackFrame::lineNumber() const +{ + if (auto *line = lineAndStatement(this)) + return line->line; + return -1; +} + +int CppStackFrame::statementNumber() const +{ + if (auto *statement = lineAndStatement(this)) + return statement->statement; + return -1; } ReturnedValue QV4::CppStackFrame::thisObject() const diff --git a/src/qml/jsruntime/qv4stackframe_p.h b/src/qml/jsruntime/qv4stackframe_p.h index b9d57d5f54..2777d79c31 100644 --- a/src/qml/jsruntime/qv4stackframe_p.h +++ b/src/qml/jsruntime/qv4stackframe_p.h @@ -81,6 +81,7 @@ struct Q_QML_PRIVATE_EXPORT CppStackFrame : protected CppStackFrameBase QString source() const; QString function() const; int lineNumber() const; + int statementNumber() const; CppStackFrame *parentFrame() const { return parent; } void setParentFrame(CppStackFrame *parentFrame) { parent = parentFrame; } -- cgit v1.2.3