diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-06-25 13:46:36 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-03 09:44:17 (GMT) |
commit | e92293cf46337e8f533908846b9e80b9ae286d6a (patch) | |
tree | 46f0e33b8a688ecde73a2a8cbf8ceefb14ef0e85 | |
parent | c7d269eab57982517d6fcebea051ad3d8ec955a3 (diff) | |
download | Qt-e92293cf46337e8f533908846b9e80b9ae286d6a.zip Qt-e92293cf46337e8f533908846b9e80b9ae286d6a.tar.gz Qt-e92293cf46337e8f533908846b9e80b9ae286d6a.tar.bz2 |
Don't crash if queued signal handler no longer exists
Cherry-picked from qt5/script commit
c89315da2e836fe67c4228cfb73c25a68b0a3a95
Task-number: QTBUG-26261
Change-Id: I24544e2f8c36eaf19c65d9a30affd1f3e05b52bb
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
-rw-r--r-- | src/script/bridge/qscriptqobject.cpp | 8 | ||||
-rw-r--r-- | tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp | 33 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index fe89f3d..e8c017d 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -2089,7 +2089,13 @@ void QObjectConnectionManager::execute(int slotIndex, void **argv) } } } - Q_ASSERT(slot && slot.isObject()); + if (!slot) { + // This connection no longer exists (can happen if the signal is + // emitted from another thread and the call gets queued, but the + // connection is removed before the QMetaCallEvent gets processed). + return; + } + Q_ASSERT(slot.isObject()); if (engine->isCollecting()) { qWarning("QtScript: can't execute signal handler during GC"); diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp index cb27878..11468f3 100644 --- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp +++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp @@ -585,6 +585,7 @@ private slots: void nestedObjectAsSlotArgument_data(); void nestedObjectAsSlotArgument(); void propertyAccessThroughActivationObject(); + void connectionRemovedAfterQueuedCall(); private: QScriptEngine *m_engine; @@ -3643,5 +3644,37 @@ void tst_QScriptExtQObject::propertyAccessThroughActivationObject() m_engine->popContext(); } +class SignalEmitterThread : public QThread +{ +public: + SignalEmitterThread(MyQObject *sender) + : m_sender(sender) + { } + + void run() + { m_sender->emitMySignal(); } + +private: + MyQObject *m_sender; +}; + +// QTBUG-26261 +void tst_QScriptExtQObject::connectionRemovedAfterQueuedCall() +{ + QVERIFY(m_engine->evaluate("var pass = true; function onMySignal() { pass = false; }").isUndefined()); + QVERIFY(m_engine->evaluate("myObject.mySignal.connect(onMySignal)").isUndefined()); + + SignalEmitterThread thread(m_myObject); + QVERIFY(m_myObject->thread() != &thread); // Premise for queued call + thread.start(); + QVERIFY(thread.wait()); + + QVERIFY(m_engine->evaluate("myObject.mySignal.disconnect(onMySignal)").isUndefined()); + // Should not crash + QCoreApplication::processEvents(); + + QVERIFY(m_engine->evaluate("pass").toBool()); +} + QTEST_MAIN(tst_QScriptExtQObject) #include "tst_qscriptextqobject.moc" |