diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-04-23 16:37:05 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-02 09:43:36 +0200 |
commit | fdeee38b781376012c4f086276c3c376726c8839 (patch) | |
tree | e35e5f02ec00a1750854bb81c7e4d5d85a4dd8ae /tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp | |
parent | 4c02780738241d784849f423944a8a4852022967 (diff) |
Fix crash in QQmlXmlHttpRequest
If an onreadystatechange handler of a QQmlXmlHttpRequest uses code
which requires the engine->callingContext() to be valid, a crash
could previously occur (since the callingContext() would be null
if the handler was called due to a network request finishing.
This commit saves the calling context on send, so that on dispatch
we can create an activation scope from that context and use it.
Note that even in this case, if the original context had previously
been deleted (e.g., by a loader deleting the item context on source
change) the saved context could be invalid by the time the dispatch
function was invoked. In that case, we simply do nothing as the
function call cannot succeed (invalid context).
Change-Id: Iba357829a69433c11cc279e6cc9fdc0bedaa31fb
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp')
-rw-r--r-- | tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp index 7a65308b6e..8f57594e5b 100644 --- a/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp +++ b/tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp @@ -117,6 +117,8 @@ private slots: // void network_errors() // void readyState() + void stateChangeCallingContext(); + private: QQmlEngine engine; }; @@ -165,7 +167,7 @@ void tst_qqmlxmlhttprequest::callbackException() QFETCH(QString, which); QFETCH(int, line); - + QString expect = testFileUrl("callbackException.qml").toString() + ":"+QString::number(line)+": Error: Exception from Callback"; QTest::ignoreMessage(QtWarningMsg, expect.toLatin1()); @@ -1155,6 +1157,22 @@ void tst_qqmlxmlhttprequest::cdata() delete object; } +void tst_qqmlxmlhttprequest::stateChangeCallingContext() +{ + // ensure that we don't crash by attempting to evaluate + // without a valid calling context. + + TestHTTPServer server(SERVER_PORT); + QVERIFY(server.isValid()); + server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); + + QQmlComponent component(&engine, testFileUrl("stateChangeCallingContext.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QTRY_VERIFY(object->property("success").toBool() == true); + delete object; +} + QTEST_MAIN(tst_qqmlxmlhttprequest) #include "tst_qqmlxmlhttprequest.moc" |