Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4arrayiterator.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2017 Crimson AS <info@crimson.no> | - | ||||||
4 | ** Copyright (C) 2018 The Qt Company Ltd. | - | ||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
6 | ** | - | ||||||
7 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||
8 | ** | - | ||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
10 | ** Commercial License Usage | - | ||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
17 | ** | - | ||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
25 | ** | - | ||||||
26 | ** GNU General Public License Usage | - | ||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
36 | ** | - | ||||||
37 | ** $QT_END_LICENSE$ | - | ||||||
38 | ** | - | ||||||
39 | ****************************************************************************/ | - | ||||||
40 | - | |||||||
41 | #include <private/qv4iterator_p.h> | - | ||||||
42 | #include <private/qv4arrayiterator_p.h> | - | ||||||
43 | #include <private/qv4typedarray_p.h> | - | ||||||
44 | #include <private/qv4symbol_p.h> | - | ||||||
45 | - | |||||||
46 | using namespace QV4; | - | ||||||
47 | - | |||||||
48 | DEFINE_OBJECT_VTABLE(ArrayIteratorObject); | - | ||||||
49 | - | |||||||
50 | void ArrayIteratorPrototype::init(ExecutionEngine *e) | - | ||||||
51 | { | - | ||||||
52 | defineDefaultProperty(QStringLiteral("next"), method_next, 0); executed 98252 times by 153 tests: return qstring_literal_temp; Executed by:
| 98252 | ||||||
53 | - | |||||||
54 | Scope scope(e); | - | ||||||
55 | ScopedString val(scope, e->newString(QLatin1String("Array Iterator"))); | - | ||||||
56 | defineReadonlyConfigurableProperty(e->symbol_toStringTag(), val); | - | ||||||
57 | } executed 99009 times by 153 tests: end of block Executed by:
| 99009 | ||||||
58 | - | |||||||
59 | ReturnedValue ArrayIteratorPrototype::method_next(const FunctionObject *b, const Value *that, const Value *, int) | - | ||||||
60 | { | - | ||||||
61 | Scope scope(b); | - | ||||||
62 | const ArrayIteratorObject *thisObject = that->as<ArrayIteratorObject>(); | - | ||||||
63 | if (!thisObject)
| 4-22863 | ||||||
64 | return scope.engine->throwTypeError(QLatin1String("Not an Array Iterator instance")); executed 4 times by 1 test: return scope.engine->throwTypeError(QLatin1String("Not an Array Iterator instance")); Executed by:
| 4 | ||||||
65 | - | |||||||
66 | ScopedObject a(scope, thisObject->d()->iteratedObject); | - | ||||||
67 | if (!a) {
| 1067-21799 | ||||||
68 | QV4::Value undefined = Primitive::undefinedValue(); | - | ||||||
69 | return IteratorPrototype::createIterResultObject(scope.engine, undefined, true); executed 1067 times by 1 test: return IteratorPrototype::createIterResultObject(scope.engine, undefined, true); Executed by:
| 1067 | ||||||
70 | } | - | ||||||
71 | - | |||||||
72 | quint32 index = thisObject->d()->nextIndex; | - | ||||||
73 | IteratorKind itemKind = thisObject->d()->iterationKind; | - | ||||||
74 | - | |||||||
75 | Scoped<TypedArray> ta(scope, a->as<TypedArray>()); | - | ||||||
76 | quint32 len = a->getLength(); | - | ||||||
77 | - | |||||||
78 | if (index >= len) {
| 6738-15155 | ||||||
79 | thisObject->d()->iteratedObject.set(scope.engine, nullptr); | - | ||||||
80 | QV4::Value undefined = Primitive::undefinedValue(); | - | ||||||
81 | return IteratorPrototype::createIterResultObject(scope.engine, undefined, true); executed 6733 times by 1 test: return IteratorPrototype::createIterResultObject(scope.engine, undefined, true); Executed by:
| 6733 | ||||||
82 | } | - | ||||||
83 | - | |||||||
84 | thisObject->d()->nextIndex = index + 1; | - | ||||||
85 | if (itemKind == KeyIteratorKind) {
| 160-15005 | ||||||
86 | return IteratorPrototype::createIterResultObject(scope.engine, Primitive::fromInt32(index), false); executed 160 times by 1 test: return IteratorPrototype::createIterResultObject(scope.engine, Primitive::fromInt32(index), false); Executed by:
| 160 | ||||||
87 | } | - | ||||||
88 | - | |||||||
89 | ReturnedValue elementValue = a->get(index); | - | ||||||
90 | CHECK_EXCEPTION(); executed 4 times by 1 test: return QV4::Encode::undefined(); Executed by:
| 4-14970 | ||||||
91 | - | |||||||
92 | if (itemKind == ValueIteratorKind) {
| 156-14843 | ||||||
93 | return IteratorPrototype::createIterResultObject(scope.engine, Value::fromReturnedValue(elementValue), false); executed 14853 times by 1 test: return IteratorPrototype::createIterResultObject(scope.engine, Value::fromReturnedValue(elementValue), false); Executed by:
| 14853 | ||||||
94 | } else { | - | ||||||
95 | Q_ASSERT(itemKind == KeyValueIteratorKind); | - | ||||||
96 | - | |||||||
97 | ScopedArrayObject resultArray(scope, scope.engine->newArrayObject()); | - | ||||||
98 | resultArray->arrayReserve(2); | - | ||||||
99 | resultArray->arrayPut(0, Primitive::fromInt32(index)); | - | ||||||
100 | resultArray->arrayPut(1, Value::fromReturnedValue(elementValue)); | - | ||||||
101 | resultArray->setArrayLengthUnchecked(2); | - | ||||||
102 | - | |||||||
103 | return IteratorPrototype::createIterResultObject(scope.engine, resultArray, false); executed 156 times by 1 test: return IteratorPrototype::createIterResultObject(scope.engine, resultArray, false); Executed by:
| 156 | ||||||
104 | } | - | ||||||
105 | } | - | ||||||
106 | - | |||||||
Source code | Switch to Preprocessed file |