summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/global/qglobal.h4
-rw-r--r--src/corelib/kernel/qobject.cpp22
-rw-r--r--src/script/api/qscriptvalueiterator.cpp4
-rw-r--r--tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp46
4 files changed, 61 insertions, 15 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 945e45c..2a41b9e 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -1123,14 +1123,14 @@ template <typename T>
inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
inline int qRound(qreal d)
-{ return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }
+{ return d >= qreal(0.0) ? int(d + qreal(0.5)) : int(d - int(d-1) + qreal(0.5)) + int(d-1); }
#if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
inline qint64 qRound64(double d)
{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); }
#else
inline qint64 qRound64(qreal d)
-{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qreal(qint64(d-1)) + 0.5) + qint64(d-1); }
+{ return d >= qreal(0.0) ? qint64(d + qreal(0.5)) : qint64(d - qreal(qint64(d-1)) + qreal(0.5)) + qint64(d-1); }
#endif
template <typename T>
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 2e9d003..c6153cb 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -161,6 +161,17 @@ QObjectPrivate::QObjectPrivate(int version)
QObjectPrivate::~QObjectPrivate()
{
+ if (pendTimer) {
+ // unregister pending timers
+ if (threadData->eventDispatcher)
+ threadData->eventDispatcher->unregisterTimers(q_ptr);
+ }
+
+ if (postedEvents)
+ QCoreApplication::removePostedEvents(q_ptr, 0);
+
+ threadData->deref();
+
delete static_cast<QAbstractDynamicMetaObject*>(metaObject);
#ifdef QT_JAMBI_BUILD
if (deleteWatch)
@@ -911,25 +922,14 @@ QObject::~QObject()
}
}
- if (d->pendTimer) {
- // unregister pending timers
- if (d->threadData->eventDispatcher)
- d->threadData->eventDispatcher->unregisterTimers(this);
- }
-
if (!d->children.isEmpty())
d->deleteChildren();
qt_removeObject(this);
- if (d->postedEvents)
- QCoreApplication::removePostedEvents(this, 0);
-
if (d->parent) // remove it from parent object
d->setParent_helper(0);
- d->threadData->deref();
-
#ifdef QT_JAMBI_BUILD
if (d->inEventHandler) {
qWarning("QObject: Do not delete object, '%s', during its event handler!",
diff --git a/src/script/api/qscriptvalueiterator.cpp b/src/script/api/qscriptvalueiterator.cpp
index c188945..5f53b46 100644
--- a/src/script/api/qscriptvalueiterator.cpp
+++ b/src/script/api/qscriptvalueiterator.cpp
@@ -162,7 +162,7 @@ QScriptValueIterator::~QScriptValueIterator()
bool QScriptValueIterator::hasNext() const
{
Q_D(const QScriptValueIterator);
- if (!d)
+ if (!d || !d->engine())
return false;
const_cast<QScriptValueIteratorPrivate*>(d)->ensureInitialized();
@@ -198,7 +198,7 @@ void QScriptValueIterator::next()
bool QScriptValueIterator::hasPrevious() const
{
Q_D(const QScriptValueIterator);
- if (!d)
+ if (!d || !d->engine())
return false;
const_cast<QScriptValueIteratorPrivate*>(d)->ensureInitialized();
diff --git a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
index 666eb21..eb7f94f 100644
--- a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
+++ b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
@@ -72,6 +72,7 @@ private slots:
void iterateGetterSetter();
void assignObjectToIterator();
void iterateNonObject();
+ void iterateOverObjectFromDeletedEngine();
};
tst_QScriptValueIterator::tst_QScriptValueIterator()
@@ -604,5 +605,50 @@ void tst_QScriptValueIterator::iterateNonObject()
QVERIFY(!it.hasNext());
}
+void tst_QScriptValueIterator::iterateOverObjectFromDeletedEngine()
+{
+ QScriptEngine *engine = new QScriptEngine;
+ QScriptValue objet = engine->newObject();
+
+ // populate object with properties
+ QHash<QString, int> properties;
+ properties.insert("foo",1235);
+ properties.insert("oof",5321);
+ properties.insert("ofo",3521);
+ QHash<QString, int>::const_iterator i = properties.constBegin();
+ for(; i != properties.constEnd(); ++i) {
+ objet.setProperty(i.key(), i.value());
+ }
+
+ // start iterating
+ QScriptValueIterator it(objet);
+ it.next();
+ QVERIFY(properties.contains(it.name()));
+
+ delete engine;
+
+ QVERIFY(!objet.isValid());
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.value().isValid());
+
+ QVERIFY(!it.hasNext());
+ it.next();
+
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.scriptName().isValid());
+ QVERIFY(!it.value().isValid());
+ it.setValue("1234567");
+ it.remove();
+
+ QVERIFY(!it.hasPrevious());
+ it.previous();
+
+ QVERIFY(it.name().isEmpty());
+ QVERIFY(!it.scriptName().isValid());
+ QVERIFY(!it.value().isValid());
+ it.setValue("1234567");
+ it.remove();
+}
+
QTEST_MAIN(tst_QScriptValueIterator)
#include "tst_qscriptvalueiterator.moc"