QtQml: Check CU for null on isBound()

If the component has an error or was clear()'d its CU will be null.
Since isBound() is a public method, it should take that into account
rather than just crash.

Pick-to: 6.5
Change-Id: I4a3e7417da3c87f6ce7dbb615f984815bc2b0b0b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Ulf Hermann 2023-03-16 13:35:59 +01:00
parent e936e466a5
commit 51c6db3f3d
2 changed files with 16 additions and 1 deletions

View File

@ -164,7 +164,8 @@ public:
QQmlContext *context, CreateBehavior behavior = CreateDefault);
bool isBound() const {
return compilationUnit->unitData()->flags & QV4::CompiledData::Unit::ComponentsBound;
return compilationUnit
&& (compilationUnit->unitData()->flags & QV4::CompiledData::Unit::ComponentsBound);
}
};

View File

@ -1245,12 +1245,14 @@ void tst_qqmlcomponent::boundComponent()
{
QQmlComponent component(&engine, testFileUrl("nestedBoundComponent.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QVERIFY(component.isBound());
QScopedPointer<QObject> o(component.create());
QVERIFY(!o.isNull());
QQmlComponent *nestedComponent = o->property("c").value<QQmlComponent *>();
QVERIFY(nestedComponent != nullptr);
QVERIFY(nestedComponent->isBound());
QObject *nestedObject = o->property("o").value<QObject *>();
QVERIFY(nestedObject != nullptr);
@ -1269,6 +1271,7 @@ void tst_qqmlcomponent::boundComponent()
{
QQmlComponent component(&engine, testFileUrl("BoundInlineComponent.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QVERIFY(component.isBound());
QScopedPointer<QObject> o(component.create());
QVERIFY2(!o.isNull(), qPrintable(component.errorString()));
@ -1282,11 +1285,22 @@ void tst_qqmlcomponent::boundComponent()
{
QQmlComponent component(&engine, testFileUrl("boundInlineComponentUser.qml"));
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QVERIFY(!component.isBound());
QScopedPointer<QObject> o(component.create());
QVERIFY(o.isNull());
QVERIFY(component.errorString().contains(
QLatin1String("Cannot instantiate bound inline component in different file")));
}
{
QQmlComponent component(&engine);
QVERIFY(!component.isBound());
component.setData("pragma ComponentBehavior: Bound\nsyntax error", QUrl());
QCOMPARE(component.errorString(), ":2 Syntax error\n"_L1);
QVERIFY(!component.isBound());
}
}