Fix conditional breakpoints in QML

We need to set "inheritContext" to true for the QV4::Script that's used during
conditional break point evaluation, because that will also disable fast
property lookups, which is still required for QML lookups to work.

Change-Id: I8976df1c827b5058eae9bdce6e86e5ea856cbfe1
Task-number: QTBUG-43018
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Simon Hausmann 2014-12-01 15:51:05 +01:00 committed by Simon Hausmann
parent cfdcc65cc5
commit a6fbea98ed
2 changed files with 42 additions and 1 deletions

View File

@ -74,7 +74,9 @@ public:
ExecutionContext *ctx = engine->currentContext();
QV4::Script script(ctx, this->script);
script.strictMode = ctx->d()->strictMode;
script.inheritContext = false;
// In order for property lookups in QML to work, we need to disable fast v4 lookups. That
// is a side-effect of inheritContext.
script.inheritContext = true;
script.parse();
QV4::ScopedValue result(scope);
if (!scope.engine->hasException)

View File

@ -33,6 +33,8 @@
#include <QtTest/QtTest>
#include <QJSEngine>
#include <QQmlEngine>
#include <QQmlComponent>
#include <private/qv4engine_p.h>
#include <private/qv4debugging_p.h>
#include <private/qv8engine_p.h>
@ -274,6 +276,7 @@ private slots:
void addBreakPointWhilePaused();
void removeBreakPointForNextInstruction();
void conditionalBreakPoint();
void conditionalBreakPointInQml();
// context access:
void readArguments();
@ -445,6 +448,42 @@ void tst_qv4debugger::conditionalBreakPoint()
QCOMPARE(m_debuggerAgent->m_capturedLocals[0]["i"].toInt(), 11);
}
void tst_qv4debugger::conditionalBreakPointInQml()
{
QQmlEngine engine;
QV4::ExecutionEngine *v4 = QV8Engine::getV4(&engine);
v4->enableDebugger();
QScopedPointer<QThread> debugThread(new QThread);
debugThread->start();
QScopedPointer<TestAgent> debuggerAgent(new TestAgent);
debuggerAgent->addDebugger(v4->debugger);
debuggerAgent->moveToThread(debugThread.data());
QQmlComponent component(&engine);
component.setData("import QtQml 2.0\n"
"QtObject {\n"
" id: root\n"
" property int foo: 42\n"
" property bool success: false\n"
" Component.onCompleted: {\n"
" success = true;\n" // breakpoint here
" }\n"
"}\n", QUrl("test.qml"));
debuggerAgent->addBreakPoint("test.qml", 7, /*enabled*/true, "root.foo == 42");
QScopedPointer<QObject> obj(component.create());
QCOMPARE(obj->property("success").toBool(), true);
QCOMPARE(debuggerAgent->m_statesWhenPaused.count(), 1);
QCOMPARE(debuggerAgent->m_statesWhenPaused.at(0).fileName, QStringLiteral("test.qml"));
QCOMPARE(debuggerAgent->m_statesWhenPaused.at(0).lineNumber, 7);
debugThread->quit();
debugThread->wait();
}
void tst_qv4debugger::readArguments()
{
m_debuggerAgent->m_captureContextInfo = true;