2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef qscriptvalueiterator_p_h
21 #define qscriptvalueiterator_p_h
23 #include "qscriptvalue_p.h"
24 #include <JavaScriptCore/JavaScript.h>
25 #include <JavaScriptCore/JSRetainPtr.h>
26 #include <QtCore/qshareddata.h>
27 #include <QtCore/qvector.h>
29 class QScriptValueIteratorPrivate
: public QSharedData
{
31 inline QScriptValueIteratorPrivate(const QScriptValuePrivate
* value
);
32 inline ~QScriptValueIteratorPrivate();
34 inline bool hasNext();
37 inline bool hasPrevious();
38 inline void previous();
40 inline QString
name() const;
41 inline QScriptStringPrivate
* scriptName() const;
43 inline QScriptValuePrivate
* value() const;
44 inline void setValue(const QScriptValuePrivate
* value
);
48 inline void toFront();
51 QScriptValue::PropertyFlags
flags() const;
53 inline bool isValid() const;
55 inline QScriptEnginePrivate
* engine() const;
57 QExplicitlySharedDataPointer
<QScriptValuePrivate
> m_object
;
58 QVector
<JSStringRef
> m_names
;
59 QMutableVectorIterator
<JSStringRef
> m_idx
;
62 inline QScriptValueIteratorPrivate::QScriptValueIteratorPrivate(const QScriptValuePrivate
* value
)
63 : m_object(const_cast<QScriptValuePrivate
*>(value
))
66 if (m_object
->isObject()) {
67 m_names
= engine()->objectGetOwnPropertyNames(*m_object
);
73 inline QScriptValueIteratorPrivate::~QScriptValueIteratorPrivate()
75 QVector
<JSStringRef
>::const_iterator i
= m_names
.constBegin();
76 for (; i
!= m_names
.constEnd(); ++i
)
80 inline bool QScriptValueIteratorPrivate::hasNext()
82 return m_idx
.hasNext();
85 inline void QScriptValueIteratorPrivate::next()
87 // FIXME (Qt5) This method should return a value (QTBUG-11226).
91 inline bool QScriptValueIteratorPrivate::hasPrevious()
93 return m_idx
.hasPrevious();
96 inline void QScriptValueIteratorPrivate::previous()
101 inline QString
QScriptValueIteratorPrivate::name() const
105 return QScriptConverter::toString(m_idx
.value());
108 inline QScriptStringPrivate
* QScriptValueIteratorPrivate::scriptName() const
111 return new QScriptStringPrivate();
112 return new QScriptStringPrivate(QScriptConverter::toString(m_idx
.value()));
115 inline QScriptValuePrivate
* QScriptValueIteratorPrivate::value() const
118 return new QScriptValuePrivate();
119 JSValueRef exception
= 0;
120 JSValueRef value
= m_object
->property(m_idx
.value(), &exception
);
121 engine()->setException(exception
);
122 return new QScriptValuePrivate(engine(), value
);
125 inline void QScriptValueIteratorPrivate::setValue(const QScriptValuePrivate
* value
)
129 JSValueRef exception
= 0;
130 m_object
->setProperty(m_idx
.value(), *value
, /* flags */ 0, &exception
);
131 engine()->setException(exception
);
134 inline void QScriptValueIteratorPrivate::remove()
138 JSValueRef exception
= 0;
139 m_object
->deleteProperty(m_idx
.value(), &exception
);
140 engine()->setException(exception
);
144 inline void QScriptValueIteratorPrivate::toFront()
149 inline void QScriptValueIteratorPrivate::toBack()
154 QScriptValue::PropertyFlags
QScriptValueIteratorPrivate::flags() const
157 return QScriptValue::PropertyFlags(0);
158 return m_object
->propertyFlags(m_idx
.value(), QScriptValue::ResolveLocal
);
161 inline bool QScriptValueIteratorPrivate::isValid() const
166 inline QScriptEnginePrivate
* QScriptValueIteratorPrivate::engine() const
169 return m_object
->engine();
172 #endif // qscriptvalueiterator_p_h