aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp4
-rw-r--r--src/webchannel/qwebchannel.cpp10
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp33
-rw-r--r--tests/auto/webchannel/tst_webchannel.h3
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 6ea3480..cd2d940 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -588,8 +588,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 6764204..13d1567 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -1080,6 +1080,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 386f314..c4fee23 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -45,7 +45,7 @@ class DummyTransport : public QWebChannelAbstractTransport
{
Q_OBJECT
public:
- explicit DummyTransport(QObject *parent)
+ explicit DummyTransport(QObject *parent = nullptr)
: QWebChannelAbstractTransport(parent)
{}
~DummyTransport() {};
@@ -327,6 +327,7 @@ private slots:
void benchRemoveTransport();
void qtbug46548_overriddenProperties();
+ void qtbug62388_wrapObjectMultipleTransports();
private:
DummyTransport *m_dummyTransport;