diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-07-31 08:46:15 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-07-31 08:46:15 (GMT) |
commit | b2fc6a9406f3b59f9e800e9d2d567d0dabde6cef (patch) | |
tree | 7370cd06f0cccec5bc636b7984218527e4613ded /src/script/api | |
parent | 06f033bc8446d6b82bf68a2a0766b75836e005db (diff) | |
download | Qt-b2fc6a9406f3b59f9e800e9d2d567d0dabde6cef.zip Qt-b2fc6a9406f3b59f9e800e9d2d567d0dabde6cef.tar.gz Qt-b2fc6a9406f3b59f9e800e9d2d567d0dabde6cef.tar.bz2 |
Basic implementation of QScriptValueIterator with JSC
Implement the methods to move forward and backward in the list of
property.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptvalueiterator.cpp | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/src/script/api/qscriptvalueiterator.cpp b/src/script/api/qscriptvalueiterator.cpp index dbf290b..45486ff 100644 --- a/src/script/api/qscriptvalueiterator.cpp +++ b/src/script/api/qscriptvalueiterator.cpp @@ -103,7 +103,7 @@ class QScriptValueIteratorPrivate { public: QScriptValueIteratorPrivate() - : propertyNames(0), it(0) + : propertyNames(0), it(0), current(0) {} ~QScriptValueIteratorPrivate() { @@ -117,11 +117,13 @@ public: JSC::ExecState *exec = eng_p->globalExec(); propertyNames = new JSC::PropertyNameArray(exec); JSC::asObject(QScriptValuePrivate::get(object)->jscValue)->getPropertyNames(exec, *propertyNames); + it = propertyNames->begin(); } QScriptValue object; JSC::PropertyNameArray *propertyNames; JSC::PropertyNameArray::const_iterator it; + const JSC::Identifier *current; }; /*! @@ -162,10 +164,9 @@ bool QScriptValueIterator::hasNext() const Q_D(const QScriptValueIterator); if (!d) return false; + const_cast<QScriptValueIteratorPrivate*>(d)->ensureInitialized(); - if (!d->it) - return (d->propertyNames->size() != 0); - return ((d->it+1) != d->propertyNames->end()); + return d->it != d->propertyNames->end(); } /*! @@ -182,10 +183,9 @@ void QScriptValueIterator::next() if (!d) return; d->ensureInitialized(); - if (!d->it) - d->it = d->propertyNames->begin(); - else - ++d->it; + + d->current = d->it; + ++(d->it); } /*! @@ -197,8 +197,12 @@ void QScriptValueIterator::next() */ bool QScriptValueIterator::hasPrevious() const { - // ### implement me - return false; + Q_D(const QScriptValueIterator); + if (!d) + return false; + + const_cast<QScriptValueIteratorPrivate*>(d)->ensureInitialized(); + return d->it != d->propertyNames->begin(); } /*! @@ -211,7 +215,12 @@ bool QScriptValueIterator::hasPrevious() const */ void QScriptValueIterator::previous() { - Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + Q_D(QScriptValueIterator); + if (!d) + return; + d->ensureInitialized(); + --(d->it); + d->current = d->it; } /*! @@ -223,9 +232,10 @@ void QScriptValueIterator::previous() void QScriptValueIterator::toFront() { Q_D(QScriptValueIterator); - if (!d || !d->propertyNames) + if (!d) return; - d->it = 0; + d->ensureInitialized(); + d->it = d->propertyNames->begin(); } /*! @@ -236,7 +246,11 @@ void QScriptValueIterator::toFront() */ void QScriptValueIterator::toBack() { - Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); + Q_D(QScriptValueIterator); + if (!d) + return; + d->ensureInitialized(); + d->it = d->propertyNames->end(); } /*! @@ -250,7 +264,7 @@ QString QScriptValueIterator::name() const Q_D(const QScriptValueIterator); if (!d || !d->it) return QString(); - return QScript::qtStringFromJSCUString(d->it->ustring()); + return QScript::qtStringFromJSCUString(d->current->ustring()); } /*! @@ -321,6 +335,7 @@ void QScriptValueIterator::remove() if (!d || !d->it) return; d->object.setProperty(name(), QScriptValue()); + d->current = 0; } /*! |