diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2011-01-17 14:38:40 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2011-01-17 14:38:40 (GMT) |
commit | 90272f30899bafcf30aa649e44804fcd12bb7fbd (patch) | |
tree | 0e55c64668c4cc51c8c31ea99e0f2f5da5a6277d | |
parent | 77c4df1325c4bae10c99978a325febada9fd82d0 (diff) | |
parent | ae0455673c4d9721d8a26a3a01a1b56c7e5fac8f (diff) | |
download | Qt-90272f30899bafcf30aa649e44804fcd12bb7fbd.zip Qt-90272f30899bafcf30aa649e44804fcd12bb7fbd.tar.gz Qt-90272f30899bafcf30aa649e44804fcd12bb7fbd.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-air-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-air-staging:
Fix QScriptValueIterator::hasNext and QScriptValueIterator::hasPrevious
-rw-r--r-- | src/script/api/qscriptvalueiterator.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp | 46 |
2 files changed, 48 insertions, 2 deletions
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" |