Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmllistwrapper.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 "qqmllistwrapper_p.h" | - | ||||||||||||
41 | #include <private/qv8engine_p.h> | - | ||||||||||||
42 | #include <private/qqmllist_p.h> | - | ||||||||||||
43 | #include <private/qv4objectproto_p.h> | - | ||||||||||||
44 | #include <qv4objectiterator_p.h> | - | ||||||||||||
45 | - | |||||||||||||
46 | #include <private/qv4functionobject_p.h> | - | ||||||||||||
47 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||
48 | - | |||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
50 | - | |||||||||||||
51 | using namespace QV4; | - | ||||||||||||
52 | - | |||||||||||||
53 | DEFINE_OBJECT_VTABLE(QmlListWrapper); | - | ||||||||||||
54 | - | |||||||||||||
55 | void Heap::QmlListWrapper::init() | - | ||||||||||||
56 | { | - | ||||||||||||
57 | Object::init(); | - | ||||||||||||
58 | object.init(); | - | ||||||||||||
59 | QV4::Scope scope(internalClass->engine); | - | ||||||||||||
60 | QV4::ScopedObject o(scope, this); | - | ||||||||||||
61 | o->setArrayType(Heap::ArrayData::Custom); | - | ||||||||||||
62 | } executed 15812 times by 22 tests: end of block Executed by:
| 15812 | ||||||||||||
63 | - | |||||||||||||
64 | void Heap::QmlListWrapper::destroy() | - | ||||||||||||
65 | { | - | ||||||||||||
66 | object.destroy(); | - | ||||||||||||
67 | Object::destroy(); | - | ||||||||||||
68 | } executed 15812 times by 22 tests: end of block Executed by:
| 15812 | ||||||||||||
69 | - | |||||||||||||
70 | ReturnedValue QmlListWrapper::create(ExecutionEngine *engine, QObject *object, int propId, int propType) | - | ||||||||||||
71 | { | - | ||||||||||||
72 | if (!object || propId == -1)
| 0-15802 | ||||||||||||
73 | return Encode::null(); never executed: return Encode::null(); | 0 | ||||||||||||
74 | - | |||||||||||||
75 | Scope scope(engine); | - | ||||||||||||
76 | - | |||||||||||||
77 | Scoped<QmlListWrapper> r(scope, engine->memoryManager->allocate<QmlListWrapper>()); | - | ||||||||||||
78 | r->d()->object = object; | - | ||||||||||||
79 | r->d()->propertyType = propType; | - | ||||||||||||
80 | void *args[] = { &r->d()->property(), nullptr }; | - | ||||||||||||
81 | QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); | - | ||||||||||||
82 | return r.asReturnedValue(); executed 15802 times by 22 tests: return r.asReturnedValue(); Executed by:
| 15802 | ||||||||||||
83 | } | - | ||||||||||||
84 | - | |||||||||||||
85 | ReturnedValue QmlListWrapper::create(ExecutionEngine *engine, const QQmlListProperty<QObject> &prop, int propType) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | Scope scope(engine); | - | ||||||||||||
88 | - | |||||||||||||
89 | Scoped<QmlListWrapper> r(scope, engine->memoryManager->allocate<QmlListWrapper>()); | - | ||||||||||||
90 | r->d()->object = prop.object; | - | ||||||||||||
91 | r->d()->property() = prop; | - | ||||||||||||
92 | r->d()->propertyType = propType; | - | ||||||||||||
93 | return r.asReturnedValue(); executed 10 times by 3 tests: return r.asReturnedValue(); Executed by:
| 10 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | QVariant QmlListWrapper::toVariant() const | - | ||||||||||||
97 | { | - | ||||||||||||
98 | if (!d()->object)
| 0-44 | ||||||||||||
99 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
100 | - | |||||||||||||
101 | return QVariant::fromValue(QQmlListReferencePrivate::init(d()->property(), d()->propertyType, engine()->qmlEngine())); executed 44 times by 7 tests: return QVariant::fromValue(QQmlListReferencePrivate::init(d()->property(), d()->propertyType, engine()->qmlEngine())); Executed by:
| 44 | ||||||||||||
102 | } | - | ||||||||||||
103 | - | |||||||||||||
104 | - | |||||||||||||
105 | ReturnedValue QmlListWrapper::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) | - | ||||||||||||
106 | { | - | ||||||||||||
107 | Q_ASSERT(m->as<QmlListWrapper>()); | - | ||||||||||||
108 | const QmlListWrapper *w = static_cast<const QmlListWrapper *>(m); | - | ||||||||||||
109 | QV4::ExecutionEngine *v4 = w->engine(); | - | ||||||||||||
110 | - | |||||||||||||
111 | if (id.isArrayIndex()) {
| 65642-78574 | ||||||||||||
112 | uint index = id.asArrayIndex(); | - | ||||||||||||
113 | quint32 count = w->d()->property().count ? w->d()->property().count(&w->d()->property()) : 0;
| 0-65642 | ||||||||||||
114 | if (index < count && w->d()->property().at) {
| 0-65630 | ||||||||||||
115 | if (hasProperty)
| 0-65630 | ||||||||||||
116 | *hasProperty = true; never executed: *hasProperty = true; | 0 | ||||||||||||
117 | return QV4::QObjectWrapper::wrap(v4, w->d()->property().at(&w->d()->property(), index)); executed 65630 times by 13 tests: return QV4::QObjectWrapper::wrap(v4, w->d()->property().at(&w->d()->property(), index)); Executed by:
| 65630 | ||||||||||||
118 | } | - | ||||||||||||
119 | - | |||||||||||||
120 | if (hasProperty)
| 0-12 | ||||||||||||
121 | *hasProperty = false; never executed: *hasProperty = false; | 0 | ||||||||||||
122 | return Primitive::undefinedValue().asReturnedValue(); executed 12 times by 2 tests: return Primitive::undefinedValue().asReturnedValue(); Executed by:
| 12 | ||||||||||||
123 | } else if (id.isString()) {
| 0-78574 | ||||||||||||
124 | if (id == v4->id_length()->propertyKey() && !w->d()->object.isNull()) {
| 0-78568 | ||||||||||||
125 | quint32 count = w->d()->property().count ? w->d()->property().count(&w->d()->property()) : 0;
| 0-78568 | ||||||||||||
126 | return Primitive::fromUInt32(count).asReturnedValue(); executed 78568 times by 16 tests: return Primitive::fromUInt32(count).asReturnedValue(); Executed by:
| 78568 | ||||||||||||
127 | } | - | ||||||||||||
128 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||
129 | - | |||||||||||||
130 | return Object::virtualGet(m, id, receiver, hasProperty); executed 6 times by 2 tests: return Object::virtualGet(m, id, receiver, hasProperty); Executed by:
| 6 | ||||||||||||
131 | } | - | ||||||||||||
132 | - | |||||||||||||
133 | bool QmlListWrapper::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) | - | ||||||||||||
134 | { | - | ||||||||||||
135 | // doesn't do anything. Should we throw? | - | ||||||||||||
136 | Q_UNUSED(m); | - | ||||||||||||
137 | Q_UNUSED(id); | - | ||||||||||||
138 | Q_UNUSED(value); | - | ||||||||||||
139 | Q_UNUSED(receiver); | - | ||||||||||||
140 | return false; never executed: return false; | 0 | ||||||||||||
141 | } | - | ||||||||||||
142 | - | |||||||||||||
143 | void QmlListWrapper::virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attrs) | - | ||||||||||||
144 | { | - | ||||||||||||
145 | name->setM(nullptr); | - | ||||||||||||
146 | *index = UINT_MAX; | - | ||||||||||||
147 | Q_ASSERT(m->as<QmlListWrapper>()); | - | ||||||||||||
148 | QmlListWrapper *w = static_cast<QmlListWrapper *>(m); | - | ||||||||||||
149 | quint32 count = w->d()->property().count ? w->d()->property().count(&w->d()->property()) : 0;
| 0-26 | ||||||||||||
150 | if (it->arrayIndex < count) {
| 4-22 | ||||||||||||
151 | *index = it->arrayIndex; | - | ||||||||||||
152 | ++it->arrayIndex; | - | ||||||||||||
153 | *attrs = QV4::Attr_Data; | - | ||||||||||||
154 | p->value = QV4::QObjectWrapper::wrap(w->engine(), w->d()->property().at(&w->d()->property(), *index)); | - | ||||||||||||
155 | return; executed 22 times by 2 tests: return; Executed by:
| 22 | ||||||||||||
156 | } | - | ||||||||||||
157 | return QV4::Object::virtualAdvanceIterator(m, it, name, index, p, attrs); executed 4 times by 2 tests: return QV4::Object::virtualAdvanceIterator(m, it, name, index, p, attrs); Executed by:
| 4 | ||||||||||||
158 | } | - | ||||||||||||
159 | - | |||||||||||||
160 | void PropertyListPrototype::init(ExecutionEngine *) | - | ||||||||||||
161 | { | - | ||||||||||||
162 | defineDefaultProperty(QStringLiteral("push"), method_push, 1); executed 98034 times by 153 tests: return qstring_literal_temp; Executed by:
| 98034 | ||||||||||||
163 | } executed 98435 times by 153 tests: end of block Executed by:
| 98435 | ||||||||||||
164 | - | |||||||||||||
165 | ReturnedValue PropertyListPrototype::method_push(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) | - | ||||||||||||
166 | { | - | ||||||||||||
167 | Scope scope(b); | - | ||||||||||||
168 | ScopedObject instance(scope, thisObject->toObject(scope.engine)); | - | ||||||||||||
169 | if (!instance)
| 0-2 | ||||||||||||
170 | RETURN_UNDEFINED(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
171 | QmlListWrapper *w = instance->as<QmlListWrapper>(); | - | ||||||||||||
172 | if (!w)
| 0-2 | ||||||||||||
173 | RETURN_UNDEFINED(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
174 | if (!w->d()->property().append)
| 0-2 | ||||||||||||
175 | THROW_GENERIC_ERROR("List doesn't define an Append function"); never executed: return scope.engine->throwError(QString::fromUtf8("List doesn't define an Append function")); | 0 | ||||||||||||
176 | - | |||||||||||||
177 | QV4::ScopedObject so(scope); | - | ||||||||||||
178 | for (int i = 0, ei = argc; i < ei; ++i)
| 2-4 | ||||||||||||
179 | { | - | ||||||||||||
180 | so = argv[i].toObject(scope.engine); | - | ||||||||||||
181 | if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>())
| 0-4 | ||||||||||||
182 | w->d()->property().append(&w->d()->property(), wrapper->object() ); executed 4 times by 1 test: w->d()->property().append(&w->d()->property(), wrapper->object() ); Executed by:
| 4 | ||||||||||||
183 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
184 | return Encode::undefined(); executed 2 times by 1 test: return Encode::undefined(); Executed by:
| 2 | ||||||||||||
185 | } | - | ||||||||||||
186 | - | |||||||||||||
187 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |