summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2018-04-16 23:41:46 +0200
committerMilian Wolff <milian.wolff@kdab.com>2019-03-25 20:30:09 +0000
commit984c4e6b4dd05561bb39f6daf305e520dfa9f0e6 (patch)
treec061038b12c5e3e7c4b2034c27cbde09362dd206
parent7a673eb1a6902ef6f2eb03d6beab139282b1e4a5 (diff)
downloadqtwebchannel-984c4e6b4dd05561bb39f6daf305e520dfa9f0e6.tar.gz
Always rebuild the class info for wrapped objects
When a new transport is accessing a previously wrapped object, we used to send potentially outdated property values. [ChangeLog][QWebChannel][General] Send current property values when another transport is accessing a previously wrapped object. Fixes: QTBUG-62388 Change-Id: I5cd5772b42c3cb9860e945bb85f77f0e3b6d6ea0 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp6
-rw-r--r--src/webchannel/qmetaobjectpublisher_p.h7
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp33
3 files changed, 30 insertions, 16 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index 3c1d030..b0581c4 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -492,7 +492,7 @@ QObject *QMetaObjectPublisher::unwrapObject(const QString &objectId) const
{
if (!objectId.isEmpty()) {
ObjectInfo objectInfo = wrappedObjects.value(objectId);
- if (objectInfo.object && !objectInfo.classinfo.isEmpty())
+ if (objectInfo.object)
return objectInfo.object;
QObject *object = registeredObjects.value(objectId);
if (object)
@@ -577,7 +577,7 @@ QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result, QWebChannelA
classInfo = classInfoForObject(object, transport);
- ObjectInfo oi(object, classInfo);
+ ObjectInfo oi(object);
if (transport) {
oi.transports.append(transport);
} else {
@@ -598,7 +598,7 @@ QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result, QWebChannelA
wrappedObjects[id].transports.append(transport);
transportedWrappedObjects.insert(transport, id);
}
- classInfo = wrappedObjects.value(id).classinfo;
+ classInfo = classInfoForObject(object, transport);
}
QJsonObject objectInfo;
diff --git a/src/webchannel/qmetaobjectpublisher_p.h b/src/webchannel/qmetaobjectpublisher_p.h
index 1535a70..23a9b96 100644
--- a/src/webchannel/qmetaobjectpublisher_p.h
+++ b/src/webchannel/qmetaobjectpublisher_p.h
@@ -256,15 +256,10 @@ private:
// Groups individually wrapped objects with their class information and the transports that have access to it.
struct ObjectInfo
{
- ObjectInfo()
- : object(Q_NULLPTR)
- {}
- ObjectInfo(QObject *o, const QJsonObject &i)
+ ObjectInfo(QObject *o = nullptr)
: object(o)
- , classinfo(i)
{}
QObject *object;
- QJsonObject classinfo;
QVector<QWebChannelAbstractTransport*> transports;
};
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index 790e5ac..24778c7 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -1127,13 +1127,22 @@ void TestWebChannel::qtbug62388_wrapObjectMultipleTransports()
auto queryObjectInfo = [&channel](QObject *obj, QWebChannelAbstractTransport *transport) {
return channel.d_func()->publisher->wrapResult(QVariant::fromValue(obj), transport).toObject();
};
- const auto objectInfo = queryObjectInfo(&obj, m_dummyTransport);
- QCOMPARE(objectInfo.length(), 3);
- QVERIFY(objectInfo.contains("id"));
- QVERIFY(objectInfo.contains("__QObject*__"));
- QVERIFY(objectInfo.contains("data"));
- QVERIFY(objectInfo.value("__QObject*__").isBool() && objectInfo.value("__QObject*__").toBool());
+ auto verifyObjectInfo = [&obj](const QJsonObject &objectInfo) {
+
+ QCOMPARE(objectInfo.length(), 3);
+ QVERIFY(objectInfo.contains("id"));
+ QVERIFY(objectInfo.contains("__QObject*__"));
+ QVERIFY(objectInfo.contains("data"));
+ QVERIFY(objectInfo.value("__QObject*__").isBool() && objectInfo.value("__QObject*__").toBool());
+
+ const auto propIndex = obj.metaObject()->indexOfProperty("prop");
+ const auto prop = objectInfo["data"].toObject()["properties"].toArray()[propIndex].toArray()[3].toString();
+ QCOMPARE(prop, obj.prop());
+ };
+
+ const auto objectInfo = queryObjectInfo(&obj, m_dummyTransport);
+ verifyObjectInfo(objectInfo);
const auto id = objectInfo.value("id").toString();
@@ -1143,7 +1152,17 @@ void TestWebChannel::qtbug62388_wrapObjectMultipleTransports()
initTransport(&transport);
QCOMPARE(queryObjectInfo(&obj, &transport), objectInfo);
- // don't crash when the transport is destroyed
+ obj.setProp("asdf");
+
+ const auto objectInfo2 = queryObjectInfo(&obj, m_dummyTransport);
+ QVERIFY(objectInfo2 != objectInfo);
+ verifyObjectInfo(objectInfo2);
+
+ DummyTransport transport2;
+ initTransport(&transport2);
+ QCOMPARE(queryObjectInfo(&obj, &transport2), objectInfo2);
+
+ // don't crash when the transports are destroyed
}
QTEST_MAIN(TestWebChannel)