diff options
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | src/webchannel/qmetaobjectpublisher.cpp | 4 | ||||
-rw-r--r-- | src/webchannel/qwebchannel.cpp | 10 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 33 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.h | 3 |
5 files changed, 45 insertions, 7 deletions
diff --git a/.qmake.conf b/.qmake.conf index b0541fe..7b49e2c 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,4 +1,4 @@ load(qt_build_config) CONFIG += warning_clean -MODULE_VERSION = 5.12.2 +MODULE_VERSION = 5.13.0 diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index 8e83237..d107848 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -563,8 +563,10 @@ QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result, QWebChannelA } else if (wrappedObjects.contains(id)) { Q_ASSERT(object == wrappedObjects.value(id).object); // check if this transport is already assigned to the object - if (transport && !wrappedObjects.value(id).transports.contains(transport)) + if (transport && !wrappedObjects.value(id).transports.contains(transport)) { wrappedObjects[id].transports.append(transport); + transportedWrappedObjects.insert(transport, id); + } classInfo = wrappedObjects.value(id).classinfo; } diff --git a/src/webchannel/qwebchannel.cpp b/src/webchannel/qwebchannel.cpp index 0e9a4c5..050d04e 100644 --- a/src/webchannel/qwebchannel.cpp +++ b/src/webchannel/qwebchannel.cpp @@ -46,6 +46,8 @@ #include <QJsonDocument> #include <QJsonObject> +#include <algorithm> + QT_BEGIN_NAMESPACE /*! @@ -81,10 +83,10 @@ QT_BEGIN_NAMESPACE */ void QWebChannelPrivate::_q_transportDestroyed(QObject *object) { - QWebChannelAbstractTransport *transport = static_cast<QWebChannelAbstractTransport*>(object); - const int idx = transports.indexOf(transport); - if (idx != -1) { - transports.remove(idx); + auto it = std::find(transports.begin(), transports.end(), object); + if (it != transports.end()) { + auto *transport = *it; + transports.erase(it); publisher->transportRemoved(transport); } } diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index b62a596..8efd2fb 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -1037,6 +1037,39 @@ void TestWebChannel::qtbug46548_overriddenProperties() #endif // WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE } +void TestWebChannel::qtbug62388_wrapObjectMultipleTransports() +{ + QWebChannel channel; + TestObject obj; + + auto initTransport = [&channel](QWebChannelAbstractTransport *transport) { + channel.connectTo(transport); + channel.d_func()->publisher->initializeClient(transport); + }; + initTransport(m_dummyTransport); + + 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()); + + const auto id = objectInfo.value("id").toString(); + + QCOMPARE(channel.d_func()->publisher->unwrapObject(id), &obj); + + DummyTransport transport; + initTransport(&transport); + QCOMPARE(queryObjectInfo(&obj, &transport), objectInfo); + + // don't crash when the transport is destroyed +} + QTEST_MAIN(TestWebChannel) #include "tst_webchannel.moc" diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index 85846e7..a9f66f9 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -44,7 +44,7 @@ class DummyTransport : public QWebChannelAbstractTransport { Q_OBJECT public: - explicit DummyTransport(QObject *parent) + explicit DummyTransport(QObject *parent = nullptr) : QWebChannelAbstractTransport(parent) {} ~DummyTransport() {}; @@ -315,6 +315,7 @@ private slots: void benchRemoveTransport(); void qtbug46548_overriddenProperties(); + void qtbug62388_wrapObjectMultipleTransports(); private: DummyTransport *m_dummyTransport; |