OpenCoverage

qjsvalueiterator.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsapi/qjsvalueiterator.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQml module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qjsvalueiterator.h"-
41#include "qjsvalueiterator_p.h"-
42#include "qjsvalue_p.h"-
43#include "private/qv4string_p.h"-
44#include "private/qv4object_p.h"-
45#include "private/qv4context_p.h"-
46-
47QT_BEGIN_NAMESPACE-
48-
49QJSValueIteratorPrivate::QJSValueIteratorPrivate(const QJSValue &v)-
50 : value(v)-
51 , currentIndex(UINT_MAX)-
52 , nextIndex(UINT_MAX)-
53{-
54 QV4::ExecutionEngine *e = QJSValuePrivate::engine(&v);-
55 if (!e)
!eDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 30 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
2-30
56 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qjsvalueiterator
2
57-
58 QV4::Scope scope(e);-
59 QV4::ScopedObject o(scope, QJSValuePrivate::getValue(&v));-
60 iterator.set(e, e->newForInIteratorObject(o));-
61}
executed 30 times by 3 tests: end of block
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
30
62-
63-
64/*!-
65 \class QJSValueIterator-
66-
67 \brief The QJSValueIterator class provides a Java-style iterator for QJSValue.-
68-
69 \ingroup qtjavascript-
70 \inmodule QtQml-
71-
72-
73 The QJSValueIterator constructor takes a QJSValue as-
74 argument. After construction, the iterator is located at the very-
75 beginning of the sequence of properties. Here's how to iterate over-
76 all the properties of a QJSValue:-
77-
78 \snippet code/src_script_qjsvalueiterator.cpp 0-
79-
80 The next() advances the iterator. The name() and value()-
81 functions return the name and value of the last item that was-
82 jumped over.-
83-
84 Note that QJSValueIterator only iterates over the QJSValue's-
85 own properties; i.e. it does not follow the prototype chain. You can-
86 use a loop like this to follow the prototype chain:-
87-
88 \snippet code/src_script_qjsvalueiterator.cpp 1-
89-
90 \sa QJSValue::property()-
91*/-
92-
93/*!-
94 Constructs an iterator for traversing \a object. The iterator is-
95 set to be at the front of the sequence of properties (before the-
96 first property).-
97*/-
98QJSValueIterator::QJSValueIterator(const QJSValue& object)-
99 : d_ptr(new QJSValueIteratorPrivate(object))-
100{-
101 QV4::ExecutionEngine *v4 = d_ptr->iterator.engine();-
102 if (!v4)
!v4Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 30 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
2-30
103 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_qjsvalueiterator
2
104 QV4::Scope scope(v4);-
105 QV4::Scoped<QV4::ForInIteratorObject> it(scope, d_ptr->iterator.value());-
106 it->d()->it().flags = QV4::ObjectIterator::NoFlags;-
107 QV4::ScopedString nm(scope);-
108 QV4::Property nextProperty;-
109 QV4::PropertyAttributes nextAttributes;-
110 it->d()->it().next(nm.getRef(), &d_ptr->nextIndex, &nextProperty, &nextAttributes);-
111 d_ptr->nextName.set(v4, nm.asReturnedValue());-
112}
executed 30 times by 3 tests: end of block
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
30
113-
114/*!-
115 Destroys the iterator.-
116*/-
117QJSValueIterator::~QJSValueIterator()-
118{-
119}-
120-
121/*!-
122 Returns true if there is at least one item ahead of the iterator-
123 (i.e. the iterator is \e not at the back of the property sequence);-
124 otherwise returns false.-
125-
126 \sa next()-
127*/-
128bool QJSValueIterator::hasNext() const-
129{-
130 QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value);-
131 if (!val || !val->isObject())
!valDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 210 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
!val->isObject()Description
TRUEevaluated 4 times by 2 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
FALSEevaluated 206 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
4-210
132 return false;
executed 8 times by 2 tests: return false;
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
8
133 return d_ptr->nextName.as<QV4::String>() || d_ptr->nextIndex != UINT_MAX;
executed 206 times by 3 tests: return d_ptr->nextName.as<QV4::String>() || d_ptr->nextIndex != (0x7fffffff * 2U + 1U) ;
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
206
134}-
135-
136/*!-
137 Advances the iterator by one position.-
138 Returns true if there was at least one item ahead of the iterator-
139 (i.e. the iterator was \e not already at the back of the property sequence);-
140 otherwise returns false.-
141-
142 \sa hasNext(), name()-
143*/-
144bool QJSValueIterator::next()-
145{-
146 QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value);-
147 if (!val || !val->isObject())
!valDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 176 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
!val->isObject()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 174 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
2-176
148 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_qjsvalueiterator
4
149 d_ptr->currentName = d_ptr->nextName;-
150 d_ptr->currentIndex = d_ptr->nextIndex;-
151-
152 QV4::ExecutionEngine *v4 = d_ptr->iterator.engine();-
153 if (!v4)
!v4Description
TRUEnever evaluated
FALSEevaluated 174 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
0-174
154 return false;
never executed: return false;
0
155 QV4::Scope scope(v4);-
156 QV4::Scoped<QV4::ForInIteratorObject> it(scope, d_ptr->iterator.value());-
157 QV4::ScopedString nm(scope);-
158 QV4::Property nextProperty;-
159 QV4::PropertyAttributes nextAttributes;-
160 it->d()->it().next(nm.getRef(), &d_ptr->nextIndex, &nextProperty, &nextAttributes);-
161 d_ptr->nextName.set(v4, nm.asReturnedValue());-
162 return d_ptr->currentName.as<QV4::String>() || d_ptr->currentIndex != UINT_MAX;
executed 174 times by 3 tests: return d_ptr->currentName.as<QV4::String>() || d_ptr->currentIndex != (0x7fffffff * 2U + 1U) ;
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
174
163}-
164-
165/*!-
166 Returns the name of the last property that was jumped over using-
167 next().-
168-
169 \sa value()-
170*/-
171QString QJSValueIterator::name() const-
172{-
173 QV4::Value *val = QJSValuePrivate::getValue(&d_ptr->value);-
174 if (!val || !val->isObject())
!valDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 186 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
!val->isObject()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 182 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
2-186
175 return QString();
executed 6 times by 1 test: return QString();
Executed by:
  • tst_qjsvalueiterator
6
176 if (QV4::String *s = d_ptr->currentName.as<QV4::String>())
QV4::String *s...QV4::String>()Description
TRUEevaluated 162 times by 3 tests
Evaluated by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
20-162
177 return s->toQString();
executed 162 times by 3 tests: return s->toQString();
Executed by:
  • tst_qjsengine
  • tst_qjsvalueiterator
  • tst_qqmlvaluetypes
162
178 if (d_ptr->currentIndex < UINT_MAX)
d_ptr->current...fff * 2U + 1U)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEnever evaluated
0-20
179 return QString::number(d_ptr->currentIndex);
executed 20 times by 1 test: return QString::number(d_ptr->currentIndex);
Executed by:
  • tst_qjsvalueiterator
20
180 return QString();
never executed: return QString();
0
181}-
182-
183-
184/*!-
185 Returns the value of the last property that was jumped over using-
186 next().-
187-
188 \sa name()-
189*/-
190QJSValue QJSValueIterator::value() const-
191{-
192 QV4::ExecutionEngine *engine = d_ptr->iterator.engine();-
193 if (!engine)
!engineDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 68 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
6-68
194 return QJSValue();
executed 6 times by 1 test: return QJSValue();
Executed by:
  • tst_qjsvalueiterator
6
195 QV4::Scope scope(engine);-
196 QV4::ScopedObject obj(scope, QJSValuePrivate::getValue(&d_ptr->value));-
197 if (!obj)
!objDescription
TRUEnever evaluated
FALSEevaluated 68 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
0-68
198 return QJSValue();
never executed: return QJSValue();
0
199-
200 if (!d_ptr->currentName.as<QV4::String>() && d_ptr->currentIndex == UINT_MAX)
!d_ptr->curren...QV4::String>()Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 28 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
d_ptr->current...fff * 2U + 1U)Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
0-40
201 return QJSValue();
never executed: return QJSValue();
0
202-
203 QV4::ScopedValue v(scope, d_ptr->currentIndex == UINT_MAX ? obj->get(d_ptr->currentName.as<QV4::String>()) : obj->get(d_ptr->currentIndex));-
204 if (scope.hasException()) {
scope.hasException()Description
TRUEnever evaluated
FALSEevaluated 68 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
0-68
205 engine->catchException();-
206 return QJSValue();
never executed: return QJSValue();
0
207 }-
208 return QJSValue(engine, v->asReturnedValue());
executed 68 times by 1 test: return QJSValue(engine, v->asReturnedValue());
Executed by:
  • tst_qjsvalueiterator
68
209}-
210-
211-
212/*!-
213 Makes the iterator operate on \a object. The iterator is set to be-
214 at the front of the sequence of properties (before the first-
215 property).-
216*/-
217QJSValueIterator& QJSValueIterator::operator=(QJSValue& object)-
218{-
219 d_ptr->value = object;-
220 d_ptr->currentIndex = UINT_MAX;-
221 d_ptr->nextIndex = UINT_MAX;-
222 d_ptr->currentName.clear();-
223 d_ptr->nextName.clear();-
224 QV4::ExecutionEngine *v4 = d_ptr->iterator.engine();-
225 if (!v4) {
!v4Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_qjsvalueiterator
2-16
226 d_ptr->iterator.clear();-
227 return *this;
executed 2 times by 1 test: return *this;
Executed by:
  • tst_qjsvalueiterator
2
228 }-
229-
230 QV4::Scope scope(v4);-
231 QV4::ScopedObject o(scope, QJSValuePrivate::getValue(&object));-
232 d_ptr->iterator.set(v4, v4->newForInIteratorObject(o));-
233 QV4::Scoped<QV4::ForInIteratorObject> it(scope, d_ptr->iterator.value());-
234 it->d()->it().flags = QV4::ObjectIterator::NoFlags;-
235 QV4::ScopedString nm(scope);-
236 QV4::Property nextProperty;-
237 QV4::PropertyAttributes nextAttributes;-
238 it->d()->it().next(nm.getRef(), &d_ptr->nextIndex, &nextProperty, &nextAttributes);-
239 d_ptr->nextName.set(v4, nm.asReturnedValue());-
240 return *this;
executed 16 times by 1 test: return *this;
Executed by:
  • tst_qjsvalueiterator
16
241}-
242-
243QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0