Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmlvaluetypewrapper.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 "qqmlvaluetypewrapper_p.h" | - | ||||||||||||
41 | #include <private/qv8engine_p.h> | - | ||||||||||||
42 | #include <private/qqmlvaluetype_p.h> | - | ||||||||||||
43 | #include <private/qqmlbinding_p.h> | - | ||||||||||||
44 | #include <private/qqmlglobal_p.h> | - | ||||||||||||
45 | #include <private/qqmlbuiltinfunctions_p.h> | - | ||||||||||||
46 | - | |||||||||||||
47 | #include <private/qv4engine_p.h> | - | ||||||||||||
48 | #include <private/qv4functionobject_p.h> | - | ||||||||||||
49 | #include <private/qv4variantobject_p.h> | - | ||||||||||||
50 | #include <private/qv4alloca_p.h> | - | ||||||||||||
51 | #include <private/qv4stackframe_p.h> | - | ||||||||||||
52 | #include <private/qv4objectiterator_p.h> | - | ||||||||||||
53 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||
54 | #include <QtCore/qloggingcategory.h> | - | ||||||||||||
55 | - | |||||||||||||
56 | QT_BEGIN_NAMESPACE | - | ||||||||||||
57 | - | |||||||||||||
58 | Q_DECLARE_LOGGING_CATEGORY(lcBindingRemoval) | - | ||||||||||||
59 | - | |||||||||||||
60 | DEFINE_OBJECT_VTABLE(QV4::QQmlValueTypeWrapper); | - | ||||||||||||
61 | - | |||||||||||||
62 | namespace QV4 { | - | ||||||||||||
63 | namespace Heap { | - | ||||||||||||
64 | - | |||||||||||||
65 | struct QQmlValueTypeReference : QQmlValueTypeWrapper | - | ||||||||||||
66 | { | - | ||||||||||||
67 | void init() { | - | ||||||||||||
68 | QQmlValueTypeWrapper::init(); | - | ||||||||||||
69 | object.init(); | - | ||||||||||||
70 | } executed 5148 times by 32 tests: end of block Executed by:
| 5148 | ||||||||||||
71 | void destroy() { | - | ||||||||||||
72 | object.destroy(); | - | ||||||||||||
73 | QQmlValueTypeWrapper::destroy(); | - | ||||||||||||
74 | } executed 5144 times by 31 tests: end of block Executed by:
| 5144 | ||||||||||||
75 | QQmlQPointer<QObject> object; | - | ||||||||||||
76 | int property; | - | ||||||||||||
77 | }; | - | ||||||||||||
78 | - | |||||||||||||
79 | } | - | ||||||||||||
80 | - | |||||||||||||
81 | struct QQmlValueTypeReference : public QQmlValueTypeWrapper | - | ||||||||||||
82 | { | - | ||||||||||||
83 | V4_OBJECT2(QQmlValueTypeReference, QQmlValueTypeWrapper) executed 369666 times by 41 tests: end of block Executed by:
never executed: end of block executed 385110 times by 44 tests: return &static_vtbl; Executed by:
executed 91094 times by 32 tests: return static_cast<QV4::Heap::QQmlValueTypeReference *>(m()); Executed by:
executed 85946 times by 32 tests: return dptr; Executed by:
| 0-385110 | ||||||||||||
84 | V4_NEEDS_DESTROY executed 5144 times by 31 tests: end of block Executed by:
| 5144 | ||||||||||||
85 | - | |||||||||||||
86 | bool readReferenceValue() const; | - | ||||||||||||
87 | }; | - | ||||||||||||
88 | - | |||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | DEFINE_OBJECT_VTABLE(QV4::QQmlValueTypeReference); | - | ||||||||||||
92 | - | |||||||||||||
93 | using namespace QV4; | - | ||||||||||||
94 | - | |||||||||||||
95 | void Heap::QQmlValueTypeWrapper::destroy() | - | ||||||||||||
96 | { | - | ||||||||||||
97 | if (gadgetPtr) {
| 422-368572 | ||||||||||||
98 | valueType->metaType.destruct(gadgetPtr); | - | ||||||||||||
99 | ::operator delete(gadgetPtr); | - | ||||||||||||
100 | } executed 368572 times by 37 tests: end of block Executed by:
| 368572 | ||||||||||||
101 | if (_propertyCache)
| 2-368992 | ||||||||||||
102 | _propertyCache->release(); executed 368992 times by 43 tests: _propertyCache->release(); Executed by:
| 368992 | ||||||||||||
103 | Object::destroy(); | - | ||||||||||||
104 | } executed 368994 times by 43 tests: end of block Executed by:
| 368994 | ||||||||||||
105 | - | |||||||||||||
106 | void Heap::QQmlValueTypeWrapper::setValue(const QVariant &value) const | - | ||||||||||||
107 | { | - | ||||||||||||
108 | Q_ASSERT(valueType->typeId == value.userType()); | - | ||||||||||||
109 | if (gadgetPtr)
| 88-364080 | ||||||||||||
110 | valueType->metaType.destruct(gadgetPtr); executed 88 times by 3 tests: valueType->metaType.destruct(gadgetPtr); Executed by:
| 88 | ||||||||||||
111 | if (!gadgetPtr)
| 88-364080 | ||||||||||||
112 | gadgetPtr = ::operator new(valueType->metaType.sizeOf()); executed 364080 times by 29 tests: gadgetPtr = ::operator new(valueType->metaType.sizeOf()); Executed by:
| 364080 | ||||||||||||
113 | valueType->metaType.construct(gadgetPtr, value.constData()); | - | ||||||||||||
114 | } executed 364168 times by 29 tests: end of block Executed by:
| 364168 | ||||||||||||
115 | - | |||||||||||||
116 | QVariant Heap::QQmlValueTypeWrapper::toVariant() const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | Q_ASSERT(gadgetPtr); | - | ||||||||||||
119 | return QVariant(valueType->typeId, gadgetPtr); executed 358802 times by 24 tests: return QVariant(valueType->typeId, gadgetPtr); Executed by:
| 358802 | ||||||||||||
120 | } | - | ||||||||||||
121 | - | |||||||||||||
122 | - | |||||||||||||
123 | bool QQmlValueTypeReference::readReferenceValue() const | - | ||||||||||||
124 | { | - | ||||||||||||
125 | if (!d()->object)
| 2-5276 | ||||||||||||
126 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
127 | // A reference resource may be either a "true" reference (eg, to a QVector3D property) | - | ||||||||||||
128 | // or a "variant" reference (eg, to a QVariant property which happens to contain a value-type). | - | ||||||||||||
129 | QMetaProperty writebackProperty = d()->object->metaObject()->property(d()->property); | - | ||||||||||||
130 | if (writebackProperty.userType() == QMetaType::QVariant) {
| 320-4956 | ||||||||||||
131 | // variant-containing-value-type reference | - | ||||||||||||
132 | QVariant variantReferenceValue; | - | ||||||||||||
133 | - | |||||||||||||
134 | void *a[] = { &variantReferenceValue, nullptr }; | - | ||||||||||||
135 | QMetaObject::metacall(d()->object, QMetaObject::ReadProperty, d()->property, a); | - | ||||||||||||
136 | - | |||||||||||||
137 | int variantReferenceType = variantReferenceValue.userType(); | - | ||||||||||||
138 | if (variantReferenceType != typeId()) {
| 8-312 | ||||||||||||
139 | // This is a stale VariantReference. That is, the variant has been | - | ||||||||||||
140 | // overwritten with a different type in the meantime. | - | ||||||||||||
141 | // We need to modify this reference to the updated value type, if | - | ||||||||||||
142 | // possible, or return false if it is not a value type. | - | ||||||||||||
143 | if (QQmlValueTypeFactory::isValueType(variantReferenceType)) {
| 0-8 | ||||||||||||
144 | QQmlPropertyCache *cache = nullptr; | - | ||||||||||||
145 | if (const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(variantReferenceType))
| 2-6 | ||||||||||||
146 | cache = QJSEnginePrivate::get(engine())->cache(mo); executed 6 times by 1 test: cache = QJSEnginePrivate::get(engine())->cache(mo); Executed by:
| 6 | ||||||||||||
147 | if (d()->gadgetPtr) {
| 2-6 | ||||||||||||
148 | d()->valueType->metaType.destruct(d()->gadgetPtr); | - | ||||||||||||
149 | ::operator delete(d()->gadgetPtr); | - | ||||||||||||
150 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
151 | d()->gadgetPtr =nullptr; | - | ||||||||||||
152 | d()->setPropertyCache(cache); | - | ||||||||||||
153 | d()->valueType = QQmlValueTypeFactory::valueType(variantReferenceType); | - | ||||||||||||
154 | if (!cache)
| 2-6 | ||||||||||||
155 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
156 | } else { executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
157 | return false; never executed: return false; | 0 | ||||||||||||
158 | } | - | ||||||||||||
159 | } | - | ||||||||||||
160 | d()->setValue(variantReferenceValue); | - | ||||||||||||
161 | } else { executed 318 times by 4 tests: end of block Executed by:
| 318 | ||||||||||||
162 | if (!d()->gadgetPtr) {
| 458-4498 | ||||||||||||
163 | d()->gadgetPtr = ::operator new(d()->valueType->metaType.sizeOf()); | - | ||||||||||||
164 | d()->valueType->metaType.construct(d()->gadgetPtr, nullptr); | - | ||||||||||||
165 | } executed 4498 times by 24 tests: end of block Executed by:
| 4498 | ||||||||||||
166 | // value-type reference | - | ||||||||||||
167 | void *args[] = { d()->gadgetPtr, nullptr }; | - | ||||||||||||
168 | QMetaObject::metacall(d()->object, QMetaObject::ReadProperty, d()->property, args); | - | ||||||||||||
169 | } executed 4956 times by 29 tests: end of block Executed by:
| 4956 | ||||||||||||
170 | return true; executed 5274 times by 29 tests: return true; Executed by:
| 5274 | ||||||||||||
171 | } | - | ||||||||||||
172 | - | |||||||||||||
173 | void QQmlValueTypeWrapper::initProto(ExecutionEngine *v4) | - | ||||||||||||
174 | { | - | ||||||||||||
175 | if (v4->valueTypeWrapperPrototype()->d_unchecked())
| 628-368370 | ||||||||||||
176 | return; executed 368370 times by 35 tests: return; Executed by:
| 368370 | ||||||||||||
177 | - | |||||||||||||
178 | Scope scope(v4); | - | ||||||||||||
179 | ScopedObject o(scope, v4->newObject()); | - | ||||||||||||
180 | o->defineDefaultProperty(v4->id_toString(), method_toString, 1); | - | ||||||||||||
181 | v4->jsObjects[QV4::ExecutionEngine::ValueTypeProto] = o->d(); | - | ||||||||||||
182 | } executed 628 times by 44 tests: end of block Executed by:
| 628 | ||||||||||||
183 | - | |||||||||||||
184 | ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, QObject *object, int property, const QMetaObject *metaObject, int typeId) | - | ||||||||||||
185 | { | - | ||||||||||||
186 | Scope scope(engine); | - | ||||||||||||
187 | initProto(engine); | - | ||||||||||||
188 | - | |||||||||||||
189 | Scoped<QQmlValueTypeReference> r(scope, engine->memoryManager->allocate<QQmlValueTypeReference>()); | - | ||||||||||||
190 | r->d()->object = object; | - | ||||||||||||
191 | r->d()->property = property; | - | ||||||||||||
192 | r->d()->setPropertyCache(QJSEnginePrivate::get(engine)->cache(metaObject)); | - | ||||||||||||
193 | r->d()->valueType = QQmlValueTypeFactory::valueType(typeId); | - | ||||||||||||
194 | r->d()->gadgetPtr = nullptr; | - | ||||||||||||
195 | return r->asReturnedValue(); executed 5148 times by 32 tests: return r->asReturnedValue(); Executed by:
| 5148 | ||||||||||||
196 | } | - | ||||||||||||
197 | - | |||||||||||||
198 | ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, const QVariant &value, const QMetaObject *metaObject, int typeId) | - | ||||||||||||
199 | { | - | ||||||||||||
200 | Scope scope(engine); | - | ||||||||||||
201 | initProto(engine); | - | ||||||||||||
202 | - | |||||||||||||
203 | Scoped<QQmlValueTypeWrapper> r(scope, engine->memoryManager->allocate<QQmlValueTypeWrapper>()); | - | ||||||||||||
204 | r->d()->setPropertyCache(QJSEnginePrivate::get(engine)->cache(metaObject)); | - | ||||||||||||
205 | r->d()->valueType = QQmlValueTypeFactory::valueType(typeId); | - | ||||||||||||
206 | r->d()->gadgetPtr = nullptr; | - | ||||||||||||
207 | r->d()->setValue(value); | - | ||||||||||||
208 | return r->asReturnedValue(); executed 363850 times by 29 tests: return r->asReturnedValue(); Executed by:
| 363850 | ||||||||||||
209 | } | - | ||||||||||||
210 | - | |||||||||||||
211 | QVariant QQmlValueTypeWrapper::toVariant() const | - | ||||||||||||
212 | { | - | ||||||||||||
213 | if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>())
| 834-179230 | ||||||||||||
214 | if (!ref->readReferenceValue())
| 0-834 | ||||||||||||
215 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
216 | return d()->toVariant(); executed 180064 times by 24 tests: return d()->toVariant(); Executed by:
| 180064 | ||||||||||||
217 | } | - | ||||||||||||
218 | - | |||||||||||||
219 | bool QQmlValueTypeWrapper::toGadget(void *data) const | - | ||||||||||||
220 | { | - | ||||||||||||
221 | if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>())
| 0-2 | ||||||||||||
222 | if (!ref->readReferenceValue())
| 0 | ||||||||||||
223 | return false; never executed: return false; | 0 | ||||||||||||
224 | const int typeId = d()->valueType->typeId; | - | ||||||||||||
225 | QMetaType::destruct(typeId, data); | - | ||||||||||||
226 | QMetaType::construct(typeId, data, d()->gadgetPtr); | - | ||||||||||||
227 | return true; executed 2 times by 1 test: return true; Executed by:
| 2 | ||||||||||||
228 | } | - | ||||||||||||
229 | - | |||||||||||||
230 | bool QQmlValueTypeWrapper::virtualIsEqualTo(Managed *m, Managed *other) | - | ||||||||||||
231 | { | - | ||||||||||||
232 | Q_ASSERT(m && m->as<QQmlValueTypeWrapper>() && other); | - | ||||||||||||
233 | QV4::QQmlValueTypeWrapper *lv = static_cast<QQmlValueTypeWrapper *>(m); | - | ||||||||||||
234 | - | |||||||||||||
235 | if (QV4::VariantObject *rv = other->as<VariantObject>())
| 0-178734 | ||||||||||||
236 | return lv->isEqual(rv->d()->data()); never executed: return lv->isEqual(rv->d()->data()); | 0 | ||||||||||||
237 | - | |||||||||||||
238 | if (QV4::QQmlValueTypeWrapper *v = other->as<QQmlValueTypeWrapper>())
| 8-178726 | ||||||||||||
239 | return lv->isEqual(v->toVariant()); executed 178726 times by 9 tests: return lv->isEqual(v->toVariant()); Executed by:
| 178726 | ||||||||||||
240 | - | |||||||||||||
241 | return false; executed 8 times by 2 tests: return false; Executed by:
| 8 | ||||||||||||
242 | } | - | ||||||||||||
243 | - | |||||||||||||
244 | PropertyAttributes QQmlValueTypeWrapper::virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p) | - | ||||||||||||
245 | { | - | ||||||||||||
246 | if (id.isString()) {
| 0-14 | ||||||||||||
247 | Scope scope(m); | - | ||||||||||||
248 | ScopedString n(scope, id.asStringOrSymbol()); | - | ||||||||||||
249 | const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m); | - | ||||||||||||
250 | QQmlPropertyData *result = r->d()->propertyCache()->property(n.getPointer(), nullptr, nullptr); | - | ||||||||||||
251 | return result ? Attr_Data : Attr_Invalid; executed 14 times by 2 tests: return result ? Attr_Data : Attr_Invalid; Executed by:
| 14 | ||||||||||||
252 | } | - | ||||||||||||
253 | - | |||||||||||||
254 | return QV4::Object::virtualGetOwnProperty(m, id, p); never executed: return QV4::Object::virtualGetOwnProperty(m, id, p); | 0 | ||||||||||||
255 | } | - | ||||||||||||
256 | - | |||||||||||||
257 | void QQmlValueTypeWrapper::virtualAdvanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | name->setM(nullptr); | - | ||||||||||||
260 | *index = UINT_MAX; | - | ||||||||||||
261 | - | |||||||||||||
262 | QQmlValueTypeWrapper *that = static_cast<QQmlValueTypeWrapper*>(m); | - | ||||||||||||
263 | - | |||||||||||||
264 | if (QQmlValueTypeReference *ref = that->as<QQmlValueTypeReference>()) {
| 0-14 | ||||||||||||
265 | if (!ref->readReferenceValue())
| 0 | ||||||||||||
266 | return; never executed: return; | 0 | ||||||||||||
267 | } never executed: end of block | 0 | ||||||||||||
268 | - | |||||||||||||
269 | if (that->d()->propertyCache()) {
| 0-14 | ||||||||||||
270 | const QMetaObject *mo = that->d()->propertyCache()->createMetaObject(); | - | ||||||||||||
271 | const int propertyCount = mo->propertyCount(); | - | ||||||||||||
272 | if (it->arrayIndex < static_cast<uint>(propertyCount)) {
| 4-10 | ||||||||||||
273 | Scope scope(that->engine()); | - | ||||||||||||
274 | ScopedString propName(scope, that->engine()->newString(QString::fromUtf8(mo->property(it->arrayIndex).name()))); | - | ||||||||||||
275 | name->setM(propName->d()); | - | ||||||||||||
276 | ++it->arrayIndex; | - | ||||||||||||
277 | *attributes = QV4::Attr_Data; | - | ||||||||||||
278 | p->value = that->QV4::Object::get(propName); | - | ||||||||||||
279 | return; executed 10 times by 2 tests: return; Executed by:
| 10 | ||||||||||||
280 | } | - | ||||||||||||
281 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||
282 | QV4::Object::virtualAdvanceIterator(m, it, name, index, p, attributes); | - | ||||||||||||
283 | } executed 4 times by 2 tests: end of block Executed by:
| 4 | ||||||||||||
284 | - | |||||||||||||
285 | bool QQmlValueTypeWrapper::isEqual(const QVariant& value) const | - | ||||||||||||
286 | { | - | ||||||||||||
287 | if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>())
| 444-178282 | ||||||||||||
288 | if (!ref->readReferenceValue())
| 0-444 | ||||||||||||
289 | return false; never executed: return false; | 0 | ||||||||||||
290 | return (value == d()->toVariant()); executed 178726 times by 9 tests: return (value == d()->toVariant()); Executed by:
| 178726 | ||||||||||||
291 | } | - | ||||||||||||
292 | - | |||||||||||||
293 | int QQmlValueTypeWrapper::typeId() const | - | ||||||||||||
294 | { | - | ||||||||||||
295 | return d()->valueType->typeId; executed 322 times by 4 tests: return d()->valueType->typeId; Executed by:
| 322 | ||||||||||||
296 | } | - | ||||||||||||
297 | - | |||||||||||||
298 | bool QQmlValueTypeWrapper::write(QObject *target, int propertyIndex) const | - | ||||||||||||
299 | { | - | ||||||||||||
300 | bool destructGadgetOnExit = false; | - | ||||||||||||
301 | Q_ALLOCA_DECLARE(void, gadget); | - | ||||||||||||
302 | if (const QQmlValueTypeReference *ref = as<const QQmlValueTypeReference>()) {
| 328-2142 | ||||||||||||
303 | if (!d()->gadgetPtr) {
| 0-328 | ||||||||||||
304 | Q_ALLOCA_ASSIGN(void, gadget, d()->valueType->metaType.sizeOf()); | - | ||||||||||||
305 | d()->gadgetPtr = gadget; | - | ||||||||||||
306 | d()->valueType->metaType.construct(d()->gadgetPtr, nullptr); | - | ||||||||||||
307 | destructGadgetOnExit = true; | - | ||||||||||||
308 | } executed 328 times by 10 tests: end of block Executed by:
| 328 | ||||||||||||
309 | if (!ref->readReferenceValue())
| 0-328 | ||||||||||||
310 | return false; never executed: return false; | 0 | ||||||||||||
311 | } executed 328 times by 10 tests: end of block Executed by:
| 328 | ||||||||||||
312 | - | |||||||||||||
313 | int flags = 0; | - | ||||||||||||
314 | int status = -1; | - | ||||||||||||
315 | void *a[] = { d()->gadgetPtr, nullptr, &status, &flags }; | - | ||||||||||||
316 | QMetaObject::metacall(target, QMetaObject::WriteProperty, propertyIndex, a); | - | ||||||||||||
317 | - | |||||||||||||
318 | if (destructGadgetOnExit) {
| 328-2142 | ||||||||||||
319 | d()->valueType->metaType.destruct(d()->gadgetPtr); | - | ||||||||||||
320 | d()->gadgetPtr = nullptr; | - | ||||||||||||
321 | } executed 328 times by 10 tests: end of block Executed by:
| 328 | ||||||||||||
322 | return true; executed 2470 times by 24 tests: return true; Executed by:
| 2470 | ||||||||||||
323 | } | - | ||||||||||||
324 | - | |||||||||||||
325 | ReturnedValue QQmlValueTypeWrapper::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) | - | ||||||||||||
326 | { | - | ||||||||||||
327 | const Object *o = thisObject->as<Object>(); | - | ||||||||||||
328 | if (!o)
| 0-22 | ||||||||||||
329 | return b->engine()->throwTypeError(); never executed: return b->engine()->throwTypeError(); | 0 | ||||||||||||
330 | const QQmlValueTypeWrapper *w = o->as<QQmlValueTypeWrapper>(); | - | ||||||||||||
331 | if (!w)
| 0-22 | ||||||||||||
332 | return b->engine()->throwTypeError(); never executed: return b->engine()->throwTypeError(); | 0 | ||||||||||||
333 | - | |||||||||||||
334 | if (const QQmlValueTypeReference *ref = w->as<QQmlValueTypeReference>())
| 4-18 | ||||||||||||
335 | if (!ref->readReferenceValue())
| 0-18 | ||||||||||||
336 | RETURN_UNDEFINED(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
337 | - | |||||||||||||
338 | QString result; | - | ||||||||||||
339 | // Prepare a buffer to pass to QMetaType::convert() | - | ||||||||||||
340 | QString convertResult; | - | ||||||||||||
341 | convertResult.~QString(); | - | ||||||||||||
342 | if (QMetaType::convert(w->d()->gadgetPtr, w->d()->valueType->typeId, &convertResult, QMetaType::QString)) {
| 2-20 | ||||||||||||
343 | result = convertResult; | - | ||||||||||||
344 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
345 | result += QString::fromUtf8(QMetaType::typeName(w->d()->valueType->typeId)) | - | ||||||||||||
346 | + QLatin1Char('('); | - | ||||||||||||
347 | const QMetaObject *mo = w->d()->propertyCache()->metaObject(); | - | ||||||||||||
348 | const int propCount = mo->propertyCount(); | - | ||||||||||||
349 | for (int i = 0; i < propCount; ++i) {
| 20-144 | ||||||||||||
350 | if (mo->property(i).isDesignable()) {
| 16-128 | ||||||||||||
351 | QVariant value = mo->property(i).readOnGadget(w->d()->gadgetPtr); | - | ||||||||||||
352 | if (i > 0)
| 18-110 | ||||||||||||
353 | result += QLatin1String(", "); executed 110 times by 2 tests: result += QLatin1String(", "); Executed by:
| 110 | ||||||||||||
354 | result += value.toString(); | - | ||||||||||||
355 | } executed 128 times by 2 tests: end of block Executed by:
| 128 | ||||||||||||
356 | } executed 144 times by 2 tests: end of block Executed by:
| 144 | ||||||||||||
357 | result += QLatin1Char(')'); | - | ||||||||||||
358 | } executed 20 times by 2 tests: end of block Executed by:
| 20 | ||||||||||||
359 | return Encode(b->engine()->newString(result)); executed 22 times by 2 tests: return Encode(b->engine()->newString(result)); Executed by:
| 22 | ||||||||||||
360 | } | - | ||||||||||||
361 | - | |||||||||||||
362 | ReturnedValue QQmlValueTypeWrapper::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) | - | ||||||||||||
363 | { | - | ||||||||||||
364 | Q_ASSERT(m->as<QQmlValueTypeWrapper>()); | - | ||||||||||||
365 | - | |||||||||||||
366 | if (!id.isString())
| 40-8280 | ||||||||||||
367 | return Object::virtualGet(m, id, receiver, hasProperty); executed 40 times by 3 tests: return Object::virtualGet(m, id, receiver, hasProperty); Executed by:
| 40 | ||||||||||||
368 | - | |||||||||||||
369 | const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m); | - | ||||||||||||
370 | QV4::ExecutionEngine *v4 = r->engine(); | - | ||||||||||||
371 | Scope scope(v4); | - | ||||||||||||
372 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||
373 | - | |||||||||||||
374 | // Note: readReferenceValue() can change the reference->type. | - | ||||||||||||
375 | if (const QQmlValueTypeReference *reference = r->as<QQmlValueTypeReference>()) {
| 3582-4698 | ||||||||||||
376 | if (!reference->readReferenceValue())
| 2-3580 | ||||||||||||
377 | return Primitive::undefinedValue().asReturnedValue(); executed 2 times by 1 test: return Primitive::undefinedValue().asReturnedValue(); Executed by:
| 2 | ||||||||||||
378 | } executed 3580 times by 16 tests: end of block Executed by:
| 3580 | ||||||||||||
379 | - | |||||||||||||
380 | QQmlPropertyData *result = r->d()->propertyCache()->property(name.getPointer(), nullptr, nullptr); | - | ||||||||||||
381 | if (!result)
| 74-8204 | ||||||||||||
382 | return Object::virtualGet(m, id, receiver, hasProperty); executed 74 times by 4 tests: return Object::virtualGet(m, id, receiver, hasProperty); Executed by:
| 74 | ||||||||||||
383 | - | |||||||||||||
384 | if (hasProperty)
| 0-8204 | ||||||||||||
385 | *hasProperty = true; never executed: *hasProperty = true; | 0 | ||||||||||||
386 | - | |||||||||||||
387 | if (result->isFunction())
| 344-7860 | ||||||||||||
388 | // calling a Q_INVOKABLE function of a value type | - | ||||||||||||
389 | return QV4::QObjectMethod::create(v4->rootContext(), r, result->coreIndex()); executed 344 times by 5 tests: return QV4::QObjectMethod::create(v4->rootContext(), r, result->coreIndex()); Executed by:
| 344 | ||||||||||||
390 | - | |||||||||||||
391 | #define VALUE_TYPE_LOAD(metatype, cpptype, constructor) \ | - | ||||||||||||
392 | if (result->propType() == metatype) { \ | - | ||||||||||||
393 | cpptype v; \ | - | ||||||||||||
394 | void *args[] = { &v, 0 }; \ | - | ||||||||||||
395 | metaObject->d.static_metacall(reinterpret_cast<QObject*>(gadget), QMetaObject::ReadProperty, index, args); \ | - | ||||||||||||
396 | return QV4::Encode(constructor(v)); \ | - | ||||||||||||
397 | } | - | ||||||||||||
398 | - | |||||||||||||
399 | const QMetaObject *metaObject = r->d()->propertyCache()->metaObject(); | - | ||||||||||||
400 | - | |||||||||||||
401 | int index = result->coreIndex(); | - | ||||||||||||
402 | QQmlMetaObject::resolveGadgetMethodOrPropertyIndex(QMetaObject::ReadProperty, &metaObject, &index); | - | ||||||||||||
403 | - | |||||||||||||
404 | void *gadget = r->d()->gadgetPtr; | - | ||||||||||||
405 | - | |||||||||||||
406 | // These four types are the most common used by the value type wrappers | - | ||||||||||||
407 | VALUE_TYPE_LOAD(QMetaType::QReal, qreal, qreal); executed 5296 times by 13 tests: return QV4::Encode(qreal(v)); Executed by:
| 2564-5296 | ||||||||||||
408 | VALUE_TYPE_LOAD(QMetaType::Int || result->isEnum(), int, int); executed 328 times by 9 tests: return QV4::Encode(int(v)); Executed by:
| 2-2238 | ||||||||||||
409 | VALUE_TYPE_LOAD(QMetaType::Int, int, int); never executed: return QV4::Encode(int(v));
| 0-2236 | ||||||||||||
410 | VALUE_TYPE_LOAD(QMetaType::QString, QString, v4->newString); executed 18 times by 2 tests: return QV4::Encode(v4->newString(v)); Executed by:
| 18-2218 | ||||||||||||
411 | VALUE_TYPE_LOAD(QMetaType::Bool, bool, bool); executed 98 times by 3 tests: return QV4::Encode(bool(v)); Executed by:
| 98-2120 | ||||||||||||
412 | - | |||||||||||||
413 | QVariant v; | - | ||||||||||||
414 | void *args[] = { nullptr, nullptr }; | - | ||||||||||||
415 | if (result->propType() == QMetaType::QVariant) {
| 2-2118 | ||||||||||||
416 | args[0] = &v; | - | ||||||||||||
417 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
418 | v = QVariant(result->propType(), static_cast<void *>(nullptr)); | - | ||||||||||||
419 | args[0] = v.data(); | - | ||||||||||||
420 | } executed 2118 times by 5 tests: end of block Executed by:
| 2118 | ||||||||||||
421 | metaObject->d.static_metacall(reinterpret_cast<QObject*>(gadget), QMetaObject::ReadProperty, index, args); | - | ||||||||||||
422 | return v4->fromVariant(v); executed 2120 times by 5 tests: return v4->fromVariant(v); Executed by:
| 2120 | ||||||||||||
423 | #undef VALUE_TYPE_ACCESSOR | - | ||||||||||||
424 | } | - | ||||||||||||
425 | - | |||||||||||||
426 | bool QQmlValueTypeWrapper::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) | - | ||||||||||||
427 | { | - | ||||||||||||
428 | if (!id.isString())
| 0-88 | ||||||||||||
429 | return Object::virtualPut(m, id, value, receiver); never executed: return Object::virtualPut(m, id, value, receiver); | 0 | ||||||||||||
430 | - | |||||||||||||
431 | Q_ASSERT(m->as<QQmlValueTypeWrapper>()); | - | ||||||||||||
432 | ExecutionEngine *v4 = static_cast<QQmlValueTypeWrapper *>(m)->engine(); | - | ||||||||||||
433 | Scope scope(v4); | - | ||||||||||||
434 | if (scope.hasException())
| 0-88 | ||||||||||||
435 | return false; never executed: return false; | 0 | ||||||||||||
436 | - | |||||||||||||
437 | Scoped<QQmlValueTypeWrapper> r(scope, static_cast<QQmlValueTypeWrapper *>(m)); | - | ||||||||||||
438 | Scoped<QQmlValueTypeReference> reference(scope, m->d()); | - | ||||||||||||
439 | - | |||||||||||||
440 | int writeBackPropertyType = -1; | - | ||||||||||||
441 | - | |||||||||||||
442 | if (reference) {
| 14-74 | ||||||||||||
443 | QMetaProperty writebackProperty = reference->d()->object->metaObject()->property(reference->d()->property); | - | ||||||||||||
444 | - | |||||||||||||
445 | if (!writebackProperty.isWritable() || !reference->readReferenceValue())
| 2-72 | ||||||||||||
446 | return false; executed 4 times by 1 test: return false; Executed by:
| 4 | ||||||||||||
447 | - | |||||||||||||
448 | writeBackPropertyType = writebackProperty.userType(); | - | ||||||||||||
449 | } executed 70 times by 6 tests: end of block Executed by:
| 70 | ||||||||||||
450 | - | |||||||||||||
451 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||
452 | - | |||||||||||||
453 | const QMetaObject *metaObject = r->d()->propertyCache()->metaObject(); | - | ||||||||||||
454 | const QQmlPropertyData *pd = r->d()->propertyCache()->property(name.getPointer(), nullptr, nullptr); | - | ||||||||||||
455 | if (!pd)
| 2-82 | ||||||||||||
456 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
457 | - | |||||||||||||
458 | if (reference) {
| 14-68 | ||||||||||||
459 | QV4::ScopedFunctionObject f(scope, value); | - | ||||||||||||
460 | const QQmlQPointer<QObject> &referenceObject = reference->d()->object; | - | ||||||||||||
461 | const int referencePropertyIndex = reference->d()->property; | - | ||||||||||||
462 | - | |||||||||||||
463 | if (f) {
| 8-60 | ||||||||||||
464 | if (!f->isBinding()) {
| 2-6 | ||||||||||||
465 | // assigning a JS function to a non-var-property is not allowed. | - | ||||||||||||
466 | QString error = QStringLiteral("Cannot assign JavaScript function to value-type property"); | - | ||||||||||||
467 | ScopedString e(scope, v4->newString(error)); | - | ||||||||||||
468 | v4->throwError(e); | - | ||||||||||||
469 | return false; executed 2 times by 1 test: return false; Executed by:
| 2 | ||||||||||||
470 | } | - | ||||||||||||
471 | - | |||||||||||||
472 | QQmlContextData *context = v4->callingQmlContext(); | - | ||||||||||||
473 | - | |||||||||||||
474 | QQmlPropertyData cacheData; | - | ||||||||||||
475 | cacheData.setWritable(true); | - | ||||||||||||
476 | cacheData.setPropType(writeBackPropertyType); | - | ||||||||||||
477 | cacheData.setCoreIndex(referencePropertyIndex); | - | ||||||||||||
478 | - | |||||||||||||
479 | QV4::Scoped<QQmlBindingFunction> bindingFunction(scope, (const Value &)f); | - | ||||||||||||
480 | - | |||||||||||||
481 | QV4::ScopedFunctionObject f(scope, bindingFunction->bindingFunction()); | - | ||||||||||||
482 | QV4::ScopedContext ctx(scope, f->scope()); | - | ||||||||||||
483 | QQmlBinding *newBinding = QQmlBinding::create(&cacheData, f->function(), referenceObject, context, ctx); | - | ||||||||||||
484 | newBinding->setSourceLocation(bindingFunction->currentLocation()); | - | ||||||||||||
485 | if (f->isBoundFunction())
| 0-6 | ||||||||||||
486 | newBinding->setBoundFunction(static_cast<QV4::BoundFunction *>(f.getPointer())); never executed: newBinding->setBoundFunction(static_cast<QV4::BoundFunction *>(f.getPointer())); | 0 | ||||||||||||
487 | newBinding->setSourceLocation(bindingFunction->currentLocation()); | - | ||||||||||||
488 | newBinding->setTarget(referenceObject, cacheData, pd); | - | ||||||||||||
489 | QQmlPropertyPrivate::setBinding(newBinding); | - | ||||||||||||
490 | return true; executed 6 times by 2 tests: return true; Executed by:
| 6 | ||||||||||||
491 | } else { | - | ||||||||||||
492 | if (Q_UNLIKELY(lcBindingRemoval().isInfoEnabled())) {
| 2-58 | ||||||||||||
493 | if (auto binding = QQmlPropertyPrivate::binding(referenceObject, QQmlPropertyIndex(referencePropertyIndex, pd->coreIndex()))) {
| 0-2 | ||||||||||||
494 | Q_ASSERT(!binding->isValueTypeProxy()); | - | ||||||||||||
495 | const auto qmlBinding = static_cast<const QQmlBinding*>(binding); | - | ||||||||||||
496 | const auto stackFrame = v4->currentStackFrame; | - | ||||||||||||
497 | qCInfo(lcBindingRemoval, executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
498 | "Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
499 | referenceObject->metaObject()->className(), referenceObject->metaObject()->property(referencePropertyIndex).name(), executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
500 | qPrintable(qmlBinding->expressionIdentifier()), executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
501 | metaObject->property(pd->coreIndex()).name(), executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
502 | qPrintable(stackFrame->source()), stackFrame->lineNumber()); executed 2 times by 1 test: QMessageLogger( __FILE__ , 502 , __PRETTY_FUNCTION__, lcBindingRemoval().categoryName()).info("Overwriting binding on %s::%s which was initially bound at %s by setting \"%s\" at %s:%d", referenceObject->metaObject()->className(), referenceObject->metaObje...ferencePropertyIndex).name(), QtPrivate::asString(qmlBinding->expressionIdentifier()).toLocal8Bit().constData(), metaObject->property(pd->coreIndex()).name(), QtPrivate::asString(stackFrame->source()).toLocal8Bit().constData(), stackFrame->lineNumber()) ; Executed by:
| 2 | ||||||||||||
503 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
504 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
505 | QQmlPropertyPrivate::removeBinding(referenceObject, QQmlPropertyIndex(referencePropertyIndex, pd->coreIndex())); | - | ||||||||||||
506 | } executed 60 times by 5 tests: end of block Executed by:
| 60 | ||||||||||||
507 | } | - | ||||||||||||
508 | - | |||||||||||||
509 | QMetaProperty property = metaObject->property(pd->coreIndex()); | - | ||||||||||||
510 | Q_ASSERT(property.isValid()); | - | ||||||||||||
511 | - | |||||||||||||
512 | QVariant v = v4->toVariant(value, property.userType()); | - | ||||||||||||
513 | - | |||||||||||||
514 | if (property.isEnumType() && (QMetaType::Type)v.type() == QMetaType::Double)
| 0-70 | ||||||||||||
515 | v = v.toInt(); never executed: v = v.toInt(); | 0 | ||||||||||||
516 | - | |||||||||||||
517 | void *gadget = r->d()->gadgetPtr; | - | ||||||||||||
518 | property.writeOnGadget(gadget, v); | - | ||||||||||||
519 | - | |||||||||||||
520 | - | |||||||||||||
521 | if (reference) {
| 14-60 | ||||||||||||
522 | if (writeBackPropertyType == QMetaType::QVariant) {
| 12-48 | ||||||||||||
523 | QVariant variantReferenceValue = r->d()->toVariant(); | - | ||||||||||||
524 | - | |||||||||||||
525 | int flags = 0; | - | ||||||||||||
526 | int status = -1; | - | ||||||||||||
527 | void *a[] = { &variantReferenceValue, nullptr, &status, &flags }; | - | ||||||||||||
528 | QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); | - | ||||||||||||
529 | - | |||||||||||||
530 | } else { executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||
531 | int flags = 0; | - | ||||||||||||
532 | int status = -1; | - | ||||||||||||
533 | void *a[] = { r->d()->gadgetPtr, nullptr, &status, &flags }; | - | ||||||||||||
534 | QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); | - | ||||||||||||
535 | } executed 48 times by 5 tests: end of block Executed by:
| 48 | ||||||||||||
536 | } | - | ||||||||||||
537 | - | |||||||||||||
538 | return true; executed 74 times by 5 tests: return true; Executed by:
| 74 | ||||||||||||
539 | } | - | ||||||||||||
540 | - | |||||||||||||
541 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |