diff options
-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 ecda5fc..d8c7b64 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 df11537..07b1cc7 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" |