V4 Debugger: Properly set up context object for expressions
We need to use the object in question as context object in order to access its properties. Otherwise we can only access the context properties and, incidentally, the root scope's properties. The latter is why the test didn't fail. Fixes: QTBUG-82150 Change-Id: I1f18f9e78dd61786310fd75e0695929522a4c90c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
dd6ffbec24
commit
751e92d50a
|
@ -66,7 +66,6 @@ void JavaScriptJob::run()
|
|||
|
||||
QV4::ScopedContext ctx(scope, engine->currentStackFrame ? engine->currentContext()
|
||||
: engine->scriptContext());
|
||||
QObject scopeObject;
|
||||
|
||||
QV4::CppStackFrame *frame = engine->currentStackFrame;
|
||||
|
||||
|
@ -76,9 +75,10 @@ void JavaScriptJob::run()
|
|||
ctx = static_cast<QV4::ExecutionContext *>(&frame->jsFrame->context);
|
||||
|
||||
if (context >= 0) {
|
||||
QQmlContext *extraContext = qmlContext(QQmlDebugService::objectForId(context));
|
||||
QObject *forId = QQmlDebugService::objectForId(context);
|
||||
QQmlContext *extraContext = qmlContext(forId);
|
||||
if (extraContext)
|
||||
ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), &scopeObject);
|
||||
ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), forId);
|
||||
} else if (frameNr < 0) { // Use QML context if available
|
||||
QQmlEngine *qmlEngine = engine->qmlEngine();
|
||||
if (qmlEngine) {
|
||||
|
@ -99,7 +99,7 @@ void JavaScriptJob::run()
|
|||
}
|
||||
}
|
||||
if (!engine->qmlContext())
|
||||
ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext), &scopeObject);
|
||||
ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,5 +36,9 @@ Item {
|
|||
}
|
||||
id: root
|
||||
property int a: 10
|
||||
|
||||
Item {
|
||||
property int b: 11
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -896,6 +896,16 @@ void tst_QQmlDebugJS::evaluateInContext()
|
|||
QVERIFY(waitForClientSignal(SIGNAL(result())));
|
||||
|
||||
QTRY_COMPARE(responseBody(m_client).value("value").toInt(), 20);
|
||||
|
||||
auto childObjects = object.children;
|
||||
QVERIFY(childObjects.count() > 0); // QQmlComponentAttached is also in there
|
||||
QCOMPARE(childObjects[0].className, QString::fromLatin1("Item"));
|
||||
|
||||
// "b" accessible in context of surrounding (child) object
|
||||
m_client->evaluate(QLatin1String("b"), -1, childObjects[0].debugId);
|
||||
QVERIFY(waitForClientSignal(SIGNAL(result())));
|
||||
|
||||
QTRY_COMPARE(responseBody(m_client).value("value").toInt(), 11);
|
||||
}
|
||||
|
||||
void tst_QQmlDebugJS::getScripts()
|
||||
|
|
Loading…
Reference in New Issue