summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-01-18 17:04:08 (GMT)
committerLiang Qi <liang.qi@qt.io>2018-01-18 17:11:34 (GMT)
commita2b88f9ba0ce2e03ffa73ba26e910e988db5d6c1 (patch)
treea0c539d40f2f165cefb07e231e9763cc795e8c01
parentee70a3dc1dff15f6fc00ea979ae0c169e201acab (diff)
parent97d2deb55b854fd2b97efc0a5b41da28444c6e78 (diff)
downloadqtwebchannel-5.10.tar.gz
Merge remote-tracking branch 'origin/5.9' into 5.105.10
Conflicts: .qmake.conf Change-Id: Id5d79a1cd456c79ef35a323d1a8713facde2ef91
-rw-r--r--dist/changes-5.9.425
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp12
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp52
-rw-r--r--tests/auto/webchannel/tst_webchannel.h13
4 files changed, 98 insertions, 4 deletions
diff --git a/dist/changes-5.9.4 b/dist/changes-5.9.4
new file mode 100644
index 0000000..d49a42f
--- /dev/null
+++ b/dist/changes-5.9.4
@@ -0,0 +1,25 @@
+Qt 5.9.4 is a bug-fix release. It maintains both forward and backward
+compatibility (source and binary) with Qt 5.9.0.
+
+For more details, refer to the online documentation included in this
+distribution. The documentation is also available online:
+
+http://doc.qt.io/qt-5/index.html
+
+The Qt version 5.9 series is binary compatible with the 5.8.x series.
+Applications compiled for 5.8 will continue to run with 5.9.
+
+Some of the changes listed in this file include issue tracking numbers
+corresponding to tasks in the Qt Bug Tracker:
+
+https://bugreports.qt.io/
+
+Each of these identifiers can be entered in the bug tracker to obtain more
+information about a particular change.
+
+****************************************************************************
+* Qt 5.9.4 Changes *
+****************************************************************************
+
+ - This release contains only minor code improvements.
+
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index cfc6ad2..8e83237 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -664,9 +664,15 @@ void QMetaObjectPublisher::handleMessage(const QJsonObject &message, QWebChannel
return;
}
- transport->sendMessage(createResponse(message.value(KEY_ID),
- wrapResult(invokeMethod(object, message.value(KEY_METHOD).toInt(-1),
- message.value(KEY_ARGS).toArray()), transport)));
+ QPointer<QMetaObjectPublisher> publisherExists(this);
+ QPointer<QWebChannelAbstractTransport> transportExists(transport);
+ QVariant result =
+ invokeMethod(object,
+ message.value(KEY_METHOD).toInt(-1),
+ message.value(KEY_ARGS).toArray());
+ if (!publisherExists || !transportExists)
+ return;
+ transport->sendMessage(createResponse(message.value(KEY_ID), wrapResult(result, transport)));
} else if (type == TypeConnectToSignal) {
signalHandler.connectTo(object, message.value(KEY_SIGNAL).toInt(-1));
} else if (type == TypeDisconnectFromSignal) {
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index a44220f..436a38e 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -814,6 +814,58 @@ void TestWebChannel::testAsyncObject()
thread.wait();
}
+class FunctionWrapper : public QObject
+{
+ Q_OBJECT
+ std::function<void()> m_fun;
+public:
+ FunctionWrapper(std::function<void()> fun) : m_fun(std::move(fun)) {}
+public slots:
+ void invoke()
+ {
+ m_fun();
+ }
+};
+
+void TestWebChannel::testDeletionDuringMethodInvocation_data()
+{
+ QTest::addColumn<bool>("deleteChannel");
+ QTest::addColumn<bool>("deleteTransport");
+ QTest::newRow("delete neither") << false << false;
+ QTest::newRow("delete channel") << true << false;
+ QTest::newRow("delete transport") << false << true;
+ QTest::newRow("delete both") << true << true;
+}
+
+void TestWebChannel::testDeletionDuringMethodInvocation()
+{
+ QFETCH(bool, deleteChannel);
+ QFETCH(bool, deleteTransport);
+
+ QScopedPointer<QWebChannel> channel(new QWebChannel);
+ QScopedPointer<DummyTransport> transport(new DummyTransport(nullptr));
+ FunctionWrapper deleter([&](){
+ if (deleteChannel)
+ channel.reset();
+ if (deleteTransport)
+ transport.reset();
+ });
+ channel->registerObject("deleter", &deleter);
+ channel->connectTo(transport.data());
+
+ transport->emitMessageReceived({
+ {"type", TypeInvokeMethod},
+ {"object", "deleter"},
+ {"method", deleter.metaObject()->indexOfMethod("invoke()")},
+ {"id", 42}
+ });
+
+ QCOMPARE(deleteChannel, !channel);
+ QCOMPARE(deleteTransport, !transport);
+ if (!deleteTransport)
+ QCOMPARE(transport->messagesSent().size(), deleteChannel ? 0 : 1);
+}
+
static QHash<QString, QObject*> createObjects(QObject *parent)
{
const int num = 100;
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index d2597e5..85a9f39 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -31,6 +31,7 @@
#include <QObject>
#include <QVariant>
+#include <QVector>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonArray>
@@ -53,10 +54,18 @@ public:
emit messageReceived(message, this);
}
+ QVector<QJsonObject> messagesSent() const
+ {
+ return mMessagesSent;
+ }
+
public slots:
- void sendMessage(const QJsonObject &/*message*/) Q_DECL_OVERRIDE
+ void sendMessage(const QJsonObject &message) Q_DECL_OVERRIDE
{
+ mMessagesSent.push_back(message);
}
+private:
+ QVector<QJsonObject> mMessagesSent;
};
class TestObject : public QObject
@@ -296,6 +305,8 @@ private slots:
void testPassWrappedObjectBack();
void testInfiniteRecursion();
void testAsyncObject();
+ void testDeletionDuringMethodInvocation_data();
+ void testDeletionDuringMethodInvocation();
void benchClassInfo();
void benchInitializeClients();