Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmltypewrapper.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 "qqmltypewrapper_p.h" | - | ||||||||||||||||||||||||
41 | #include <private/qv8engine_p.h> | - | ||||||||||||||||||||||||
42 | - | |||||||||||||||||||||||||
43 | #include <private/qqmlengine_p.h> | - | ||||||||||||||||||||||||
44 | #include <private/qqmlcontext_p.h> | - | ||||||||||||||||||||||||
45 | - | |||||||||||||||||||||||||
46 | #include <private/qjsvalue_p.h> | - | ||||||||||||||||||||||||
47 | #include <private/qv4functionobject_p.h> | - | ||||||||||||||||||||||||
48 | #include <private/qv4objectproto_p.h> | - | ||||||||||||||||||||||||
49 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||||||||||||||
50 | - | |||||||||||||||||||||||||
51 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
52 | - | |||||||||||||||||||||||||
53 | using namespace QV4; | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | DEFINE_OBJECT_VTABLE(QQmlTypeWrapper); | - | ||||||||||||||||||||||||
56 | DEFINE_OBJECT_VTABLE(QQmlScopedEnumWrapper); | - | ||||||||||||||||||||||||
57 | - | |||||||||||||||||||||||||
58 | void Heap::QQmlTypeWrapper::init() | - | ||||||||||||||||||||||||
59 | { | - | ||||||||||||||||||||||||
60 | Object::init(); | - | ||||||||||||||||||||||||
61 | mode = IncludeEnums; | - | ||||||||||||||||||||||||
62 | object.init(); | - | ||||||||||||||||||||||||
63 | } executed 149836 times by 42 tests: end of block Executed by:
| 149836 | ||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | void Heap::QQmlTypeWrapper::destroy() | - | ||||||||||||||||||||||||
66 | { | - | ||||||||||||||||||||||||
67 | QQmlType::derefHandle(typePrivate); | - | ||||||||||||||||||||||||
68 | typePrivate = nullptr; | - | ||||||||||||||||||||||||
69 | if (typeNamespace)
| 324-149504 | ||||||||||||||||||||||||
70 | typeNamespace->release(); executed 324 times by 5 tests: typeNamespace->release(); Executed by:
| 324 | ||||||||||||||||||||||||
71 | object.destroy(); | - | ||||||||||||||||||||||||
72 | Object::destroy(); | - | ||||||||||||||||||||||||
73 | } executed 149828 times by 42 tests: end of block Executed by:
| 149828 | ||||||||||||||||||||||||
74 | - | |||||||||||||||||||||||||
75 | QQmlType Heap::QQmlTypeWrapper::type() const | - | ||||||||||||||||||||||||
76 | { | - | ||||||||||||||||||||||||
77 | return QQmlType(typePrivate); executed 149874 times by 42 tests: return QQmlType(typePrivate); Executed by:
| 149874 | ||||||||||||||||||||||||
78 | } | - | ||||||||||||||||||||||||
79 | - | |||||||||||||||||||||||||
80 | bool QQmlTypeWrapper::isSingleton() const | - | ||||||||||||||||||||||||
81 | { | - | ||||||||||||||||||||||||
82 | return d()->type().isSingleton(); executed 32 times by 2 tests: return d()->type().isSingleton(); Executed by:
| 32 | ||||||||||||||||||||||||
83 | } | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | QObject* QQmlTypeWrapper::singletonObject() const | - | ||||||||||||||||||||||||
86 | { | - | ||||||||||||||||||||||||
87 | if (!isSingleton())
| 0 | ||||||||||||||||||||||||
88 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | QQmlEngine *e = engine()->qmlEngine(); | - | ||||||||||||||||||||||||
91 | QQmlType::SingletonInstanceInfo *siinfo = d()->type().singletonInstanceInfo(); | - | ||||||||||||||||||||||||
92 | siinfo->init(e); | - | ||||||||||||||||||||||||
93 | return siinfo->qobjectApi(e); never executed: return siinfo->qobjectApi(e); | 0 | ||||||||||||||||||||||||
94 | } | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | QVariant QQmlTypeWrapper::toVariant() const | - | ||||||||||||||||||||||||
97 | { | - | ||||||||||||||||||||||||
98 | // Only Singleton type wrappers can be converted to a variant. | - | ||||||||||||||||||||||||
99 | if (!isSingleton())
| 0-30 | ||||||||||||||||||||||||
100 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | QQmlEngine *e = engine()->qmlEngine(); | - | ||||||||||||||||||||||||
103 | QQmlType::SingletonInstanceInfo *siinfo = d()->type().singletonInstanceInfo(); | - | ||||||||||||||||||||||||
104 | siinfo->init(e); | - | ||||||||||||||||||||||||
105 | if (QObject *qobjectSingleton = siinfo->qobjectApi(e))
| 0-30 | ||||||||||||||||||||||||
106 | return QVariant::fromValue<QObject*>(qobjectSingleton); executed 30 times by 2 tests: return QVariant::fromValue<QObject*>(qobjectSingleton); Executed by:
| 30 | ||||||||||||||||||||||||
107 | - | |||||||||||||||||||||||||
108 | return QVariant::fromValue<QJSValue>(siinfo->scriptApi(e)); never executed: return QVariant::fromValue<QJSValue>(siinfo->scriptApi(e)); | 0 | ||||||||||||||||||||||||
109 | } | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | // Returns a type wrapper for type t on o. This allows access of enums, and attached properties. | - | ||||||||||||||||||||||||
113 | ReturnedValue QQmlTypeWrapper::create(QV4::ExecutionEngine *engine, QObject *o, const QQmlType &t, | - | ||||||||||||||||||||||||
114 | Heap::QQmlTypeWrapper::TypeNameMode mode) | - | ||||||||||||||||||||||||
115 | { | - | ||||||||||||||||||||||||
116 | Q_ASSERT(t.isValid()); | - | ||||||||||||||||||||||||
117 | Scope scope(engine); | - | ||||||||||||||||||||||||
118 | - | |||||||||||||||||||||||||
119 | Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
120 | w->d()->mode = mode; w->d()->object = o; | - | ||||||||||||||||||||||||
121 | w->d()->typePrivate = t.priv(); | - | ||||||||||||||||||||||||
122 | QQmlType::refHandle(w->d()->typePrivate); | - | ||||||||||||||||||||||||
123 | return w.asReturnedValue(); executed 149512 times by 42 tests: return w.asReturnedValue(); Executed by:
| 149512 | ||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | // Returns a type wrapper for importNamespace (of t) on o. This allows nested resolution of a type in a | - | ||||||||||||||||||||||||
127 | // namespace. | - | ||||||||||||||||||||||||
128 | ReturnedValue QQmlTypeWrapper::create(QV4::ExecutionEngine *engine, QObject *o, const QQmlRefPointer<QQmlTypeNameCache> &t, const QQmlImportRef *importNamespace, | - | ||||||||||||||||||||||||
129 | Heap::QQmlTypeWrapper::TypeNameMode mode) | - | ||||||||||||||||||||||||
130 | { | - | ||||||||||||||||||||||||
131 | Q_ASSERT(t); | - | ||||||||||||||||||||||||
132 | Q_ASSERT(importNamespace); | - | ||||||||||||||||||||||||
133 | Scope scope(engine); | - | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | Scoped<QQmlTypeWrapper> w(scope, engine->memoryManager->allocate<QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
136 | w->d()->mode = mode; w->d()->object = o; w->d()->typeNamespace = t.data(); w->d()->importNamespace = importNamespace; | - | ||||||||||||||||||||||||
137 | t->addref(); | - | ||||||||||||||||||||||||
138 | return w.asReturnedValue(); executed 324 times by 5 tests: return w.asReturnedValue(); Executed by:
| 324 | ||||||||||||||||||||||||
139 | } | - | ||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | static int enumForSingleton(QV4::ExecutionEngine *v4, String *name, QObject *qobjectSingleton, | - | ||||||||||||||||||||||||
142 | const QQmlType &type, bool *ok) | - | ||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||
144 | Q_ASSERT(ok != nullptr); | - | ||||||||||||||||||||||||
145 | int value = type.enumValue(QQmlEnginePrivate::get(v4->qmlEngine()), name, ok); | - | ||||||||||||||||||||||||
146 | if (*ok)
| 4-12 | ||||||||||||||||||||||||
147 | return value; executed 12 times by 2 tests: return value; Executed by:
| 12 | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | // ### Optimize | - | ||||||||||||||||||||||||
150 | QByteArray enumName = name->toQString().toUtf8(); | - | ||||||||||||||||||||||||
151 | const QMetaObject *metaObject = qobjectSingleton->metaObject(); | - | ||||||||||||||||||||||||
152 | for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) {
| 4 | ||||||||||||||||||||||||
153 | QMetaEnum e = metaObject->enumerator(ii); | - | ||||||||||||||||||||||||
154 | value = e.keyToValue(enumName.constData(), ok); | - | ||||||||||||||||||||||||
155 | if (*ok)
| 0-4 | ||||||||||||||||||||||||
156 | return value; never executed: return value; | 0 | ||||||||||||||||||||||||
157 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
158 | *ok = false; | - | ||||||||||||||||||||||||
159 | return -1; executed 4 times by 1 test: return -1; Executed by:
| 4 | ||||||||||||||||||||||||
160 | } | - | ||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||
162 | static ReturnedValue throwLowercaseEnumError(QV4::ExecutionEngine *v4, String *name, const QQmlType &type) | - | ||||||||||||||||||||||||
163 | { | - | ||||||||||||||||||||||||
164 | const QString message = | - | ||||||||||||||||||||||||
165 | QStringLiteral("Cannot access enum value '%1' of '%2', enum values need to start with an uppercase letter.") | - | ||||||||||||||||||||||||
166 | .arg(name->toQString()).arg(QLatin1String(type.typeName())); | - | ||||||||||||||||||||||||
167 | return v4->throwTypeError(message); never executed: return v4->throwTypeError(message); | 0 | ||||||||||||||||||||||||
168 | } | - | ||||||||||||||||||||||||
169 | - | |||||||||||||||||||||||||
170 | ReturnedValue QQmlTypeWrapper::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) | - | ||||||||||||||||||||||||
171 | { | - | ||||||||||||||||||||||||
172 | Q_ASSERT(m->as<QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | if (!id.isString())
| 56-148572 | ||||||||||||||||||||||||
175 | return Object::virtualGet(m, id, receiver, hasProperty); executed 56 times by 1 test: return Object::virtualGet(m, id, receiver, hasProperty); Executed by:
| 56 | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | QV4::ExecutionEngine *v4 = static_cast<const QQmlTypeWrapper *>(m)->engine(); | - | ||||||||||||||||||||||||
178 | QV4::Scope scope(v4); | - | ||||||||||||||||||||||||
179 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | Scoped<QQmlTypeWrapper> w(scope, static_cast<const QQmlTypeWrapper *>(m)); | - | ||||||||||||||||||||||||
182 | - | |||||||||||||||||||||||||
183 | if (hasProperty)
| 6-148566 | ||||||||||||||||||||||||
184 | *hasProperty = true; executed 6 times by 1 test: *hasProperty = true; Executed by:
| 6 | ||||||||||||||||||||||||
185 | - | |||||||||||||||||||||||||
186 | QQmlContextData *context = v4->callingQmlContext(); | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | QObject *object = w->d()->object; | - | ||||||||||||||||||||||||
189 | QQmlType type = w->d()->type(); | - | ||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||
191 | if (type.isValid()) {
| 324-148248 | ||||||||||||||||||||||||
192 | - | |||||||||||||||||||||||||
193 | // singleton types are handled differently to other types. | - | ||||||||||||||||||||||||
194 | if (type.isSingleton()) {
| 446-147802 | ||||||||||||||||||||||||
195 | QQmlEngine *e = v4->qmlEngine(); | - | ||||||||||||||||||||||||
196 | QQmlType::SingletonInstanceInfo *siinfo = type.singletonInstanceInfo(); | - | ||||||||||||||||||||||||
197 | siinfo->init(e); | - | ||||||||||||||||||||||||
198 | - | |||||||||||||||||||||||||
199 | QObject *qobjectSingleton = siinfo->qobjectApi(e); | - | ||||||||||||||||||||||||
200 | if (qobjectSingleton) {
| 28-418 | ||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||
202 | // check for enum value | - | ||||||||||||||||||||||||
203 | const bool includeEnums = w->d()->mode == Heap::QQmlTypeWrapper::IncludeEnums; | - | ||||||||||||||||||||||||
204 | if (includeEnums && name->startsWithUpper()) {
| 0-418 | ||||||||||||||||||||||||
205 | bool ok = false; | - | ||||||||||||||||||||||||
206 | const int value = enumForSingleton(v4, name, qobjectSingleton, type, &ok); | - | ||||||||||||||||||||||||
207 | if (ok)
| 0-12 | ||||||||||||||||||||||||
208 | return QV4::Primitive::fromInt32(value).asReturnedValue(); executed 12 times by 2 tests: return QV4::Primitive::fromInt32(value).asReturnedValue(); Executed by:
| 12 | ||||||||||||||||||||||||
209 | } never executed: end of block | 0 | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | // check for property. | - | ||||||||||||||||||||||||
212 | bool ok; | - | ||||||||||||||||||||||||
213 | const ReturnedValue result = QV4::QObjectWrapper::getQmlProperty(v4, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, &ok); | - | ||||||||||||||||||||||||
214 | if (hasProperty)
| 2-404 | ||||||||||||||||||||||||
215 | *hasProperty = ok; executed 2 times by 1 test: *hasProperty = ok; Executed by:
| 2 | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | // Warn when attempting to access a lowercased enum value, singleton case | - | ||||||||||||||||||||||||
218 | if (!ok && includeEnums && !name->startsWithUpper()) {
| 0-402 | ||||||||||||||||||||||||
219 | enumForSingleton(v4, name, qobjectSingleton, type, &ok); | - | ||||||||||||||||||||||||
220 | if (ok)
| 0-4 | ||||||||||||||||||||||||
221 | return throwLowercaseEnumError(v4, name, type); never executed: return throwLowercaseEnumError(v4, name, type); | 0 | ||||||||||||||||||||||||
222 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | return result; executed 406 times by 12 tests: return result; Executed by:
| 406 | ||||||||||||||||||||||||
225 | } else if (!siinfo->scriptApi(e).isUndefined()) {
| 0-28 | ||||||||||||||||||||||||
226 | // NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable. | - | ||||||||||||||||||||||||
227 | QV4::ScopedObject o(scope, QJSValuePrivate::convertedToValue(v4, siinfo->scriptApi(e))); | - | ||||||||||||||||||||||||
228 | if (!!o)
| 0-28 | ||||||||||||||||||||||||
229 | return o->get(name); executed 28 times by 1 test: return o->get(name); Executed by:
| 28 | ||||||||||||||||||||||||
230 | } never executed: end of block | 0 | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | // Fall through to base implementation | - | ||||||||||||||||||||||||
233 | - | |||||||||||||||||||||||||
234 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
235 | - | |||||||||||||||||||||||||
236 | if (name->startsWithUpper()) {
| 6166-141636 | ||||||||||||||||||||||||
237 | bool ok = false; | - | ||||||||||||||||||||||||
238 | int value = type.enumValue(QQmlEnginePrivate::get(v4->qmlEngine()), name, &ok); | - | ||||||||||||||||||||||||
239 | if (ok)
| 8-6158 | ||||||||||||||||||||||||
240 | return QV4::Primitive::fromInt32(value).asReturnedValue(); executed 6158 times by 26 tests: return QV4::Primitive::fromInt32(value).asReturnedValue(); Executed by:
| 6158 | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | value = type.scopedEnumIndex(QQmlEnginePrivate::get(v4->qmlEngine()), name, &ok); | - | ||||||||||||||||||||||||
243 | if (ok) {
| 0-8 | ||||||||||||||||||||||||
244 | Scoped<QQmlScopedEnumWrapper> enumWrapper(scope, v4->memoryManager->allocate<QQmlScopedEnumWrapper>()); | - | ||||||||||||||||||||||||
245 | enumWrapper->d()->typePrivate = type.priv(); | - | ||||||||||||||||||||||||
246 | QQmlType::refHandle(enumWrapper->d()->typePrivate); | - | ||||||||||||||||||||||||
247 | enumWrapper->d()->scopeEnumIndex = value; | - | ||||||||||||||||||||||||
248 | return enumWrapper.asReturnedValue(); never executed: return enumWrapper.asReturnedValue(); | 0 | ||||||||||||||||||||||||
249 | } | - | ||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||
251 | // Fall through to base implementation | - | ||||||||||||||||||||||||
252 | - | |||||||||||||||||||||||||
253 | } else if (w->d()->object) { executed 8 times by 1 test: end of block Executed by:
| 2-141634 | ||||||||||||||||||||||||
254 | QObject *ao = qmlAttachedPropertiesObjectById(type.attachedPropertiesId(QQmlEnginePrivate::get(v4->qmlEngine())), object); | - | ||||||||||||||||||||||||
255 | if (ao)
| 8-141626 | ||||||||||||||||||||||||
256 | return QV4::QObjectWrapper::getQmlProperty(v4, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty); executed 141626 times by 19 tests: return QV4::QObjectWrapper::getQmlProperty(v4, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty); Executed by:
| 141626 | ||||||||||||||||||||||||
257 | - | |||||||||||||||||||||||||
258 | // Fall through to base implementation | - | ||||||||||||||||||||||||
259 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | // Fall through to base implementation | - | ||||||||||||||||||||||||
262 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | // Fall through to base implementation | - | ||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||
266 | } else if (w->d()->typeNamespace) {
| 0-324 | ||||||||||||||||||||||||
267 | Q_ASSERT(w->d()->importNamespace); | - | ||||||||||||||||||||||||
268 | QQmlTypeNameCache::Result r = w->d()->typeNamespace->query(name, w->d()->importNamespace); | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | if (r.isValid()) {
| 2-322 | ||||||||||||||||||||||||
271 | if (r.type.isValid()) {
| 8-314 | ||||||||||||||||||||||||
272 | return create(scope.engine, object, r.type, w->d()->mode); executed 314 times by 5 tests: return create(scope.engine, object, r.type, w->d()->mode); Executed by:
| 314 | ||||||||||||||||||||||||
273 | } else if (r.scriptIndex != -1) {
| 0-8 | ||||||||||||||||||||||||
274 | QV4::ScopedObject scripts(scope, context->importedScripts.valueRef()); | - | ||||||||||||||||||||||||
275 | return scripts->get(r.scriptIndex); executed 8 times by 1 test: return scripts->get(r.scriptIndex); Executed by:
| 8 | ||||||||||||||||||||||||
276 | } else if (r.importNamespace) {
| 0 | ||||||||||||||||||||||||
277 | return create(scope.engine, object, context->imports, r.importNamespace); never executed: return create(scope.engine, object, context->imports, r.importNamespace); | 0 | ||||||||||||||||||||||||
278 | } | - | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||
282 | } | - | ||||||||||||||||||||||||
283 | - | |||||||||||||||||||||||||
284 | // Fall through to base implementation | - | ||||||||||||||||||||||||
285 | - | |||||||||||||||||||||||||
286 | } else { executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
287 | Q_ASSERT(!"Unreachable"); | - | ||||||||||||||||||||||||
288 | } never executed: end of block | 0 | ||||||||||||||||||||||||
289 | - | |||||||||||||||||||||||||
290 | bool ok = false; | - | ||||||||||||||||||||||||
291 | const ReturnedValue result = Object::virtualGet(m, id, receiver, &ok); | - | ||||||||||||||||||||||||
292 | if (hasProperty)
| 2-18 | ||||||||||||||||||||||||
293 | *hasProperty = ok; executed 2 times by 1 test: *hasProperty = ok; Executed by:
| 2 | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | // Warn when attempting to access a lowercased enum value, non-singleton case | - | ||||||||||||||||||||||||
296 | if (!ok && type.isValid() && !type.isSingleton() && !name->startsWithUpper()) {
| 0-16 | ||||||||||||||||||||||||
297 | bool enumOk = false; | - | ||||||||||||||||||||||||
298 | type.enumValue(QQmlEnginePrivate::get(v4->qmlEngine()), name, &enumOk); | - | ||||||||||||||||||||||||
299 | if (enumOk)
| 0-6 | ||||||||||||||||||||||||
300 | return throwLowercaseEnumError(v4, name, type); never executed: return throwLowercaseEnumError(v4, name, type); | 0 | ||||||||||||||||||||||||
301 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | return result; executed 20 times by 1 test: return result; Executed by:
| 20 | ||||||||||||||||||||||||
304 | } | - | ||||||||||||||||||||||||
305 | - | |||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | bool QQmlTypeWrapper::virtualPut(Managed *m, PropertyKey id, const Value &value, Value *receiver) | - | ||||||||||||||||||||||||
308 | { | - | ||||||||||||||||||||||||
309 | if (!id.isString())
| 0-1184 | ||||||||||||||||||||||||
310 | return Object::virtualPut(m, id, value, receiver); never executed: return Object::virtualPut(m, id, value, receiver); | 0 | ||||||||||||||||||||||||
311 | - | |||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||
313 | Q_ASSERT(m->as<QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
314 | QQmlTypeWrapper *w = static_cast<QQmlTypeWrapper *>(m); | - | ||||||||||||||||||||||||
315 | QV4::Scope scope(w); | - | ||||||||||||||||||||||||
316 | if (scope.engine->hasException)
| 0-1184 | ||||||||||||||||||||||||
317 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||||||||||||||
320 | QQmlContextData *context = scope.engine->callingQmlContext(); | - | ||||||||||||||||||||||||
321 | - | |||||||||||||||||||||||||
322 | QQmlType type = w->d()->type(); | - | ||||||||||||||||||||||||
323 | if (type.isValid() && !type.isSingleton() && w->d()->object) {
| 0-1184 | ||||||||||||||||||||||||
324 | QObject *object = w->d()->object; | - | ||||||||||||||||||||||||
325 | QQmlEngine *e = scope.engine->qmlEngine(); | - | ||||||||||||||||||||||||
326 | QObject *ao = qmlAttachedPropertiesObjectById(type.attachedPropertiesId(QQmlEnginePrivate::get(e)), object); | - | ||||||||||||||||||||||||
327 | if (ao)
| 0-1112 | ||||||||||||||||||||||||
328 | return QV4::QObjectWrapper::setQmlProperty(scope.engine, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, value); executed 1112 times by 5 tests: return QV4::QObjectWrapper::setQmlProperty(scope.engine, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, value); Executed by:
| 1112 | ||||||||||||||||||||||||
329 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
330 | } else if (type.isSingleton()) {
| 0-72 | ||||||||||||||||||||||||
331 | QQmlEngine *e = scope.engine->qmlEngine(); | - | ||||||||||||||||||||||||
332 | QQmlType::SingletonInstanceInfo *siinfo = type.singletonInstanceInfo(); | - | ||||||||||||||||||||||||
333 | siinfo->init(e); | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | QObject *qobjectSingleton = siinfo->qobjectApi(e); | - | ||||||||||||||||||||||||
336 | if (qobjectSingleton) {
| 4-68 | ||||||||||||||||||||||||
337 | return QV4::QObjectWrapper::setQmlProperty(scope.engine, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, value); executed 68 times by 6 tests: return QV4::QObjectWrapper::setQmlProperty(scope.engine, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, value); Executed by:
| 68 | ||||||||||||||||||||||||
338 | } else if (!siinfo->scriptApi(e).isUndefined()) {
| 0-4 | ||||||||||||||||||||||||
339 | QV4::ScopedObject apiprivate(scope, QJSValuePrivate::convertedToValue(scope.engine, siinfo->scriptApi(e))); | - | ||||||||||||||||||||||||
340 | if (!apiprivate) {
| 0-4 | ||||||||||||||||||||||||
341 | QString error = QLatin1String("Cannot assign to read-only property \"") + name->toQString() + QLatin1Char('\"'); | - | ||||||||||||||||||||||||
342 | scope.engine->throwError(error); | - | ||||||||||||||||||||||||
343 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
344 | } else { | - | ||||||||||||||||||||||||
345 | return apiprivate->put(name, value); executed 4 times by 1 test: return apiprivate->put(name, value); Executed by:
| 4 | ||||||||||||||||||||||||
346 | } | - | ||||||||||||||||||||||||
347 | } | - | ||||||||||||||||||||||||
348 | } never executed: end of block | 0 | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | PropertyAttributes QQmlTypeWrapper::virtualGetOwnProperty(Managed *m, PropertyKey id, Property *p) | - | ||||||||||||||||||||||||
354 | { | - | ||||||||||||||||||||||||
355 | if (id.isString()) {
| 0-6 | ||||||||||||||||||||||||
356 | Scope scope(m); | - | ||||||||||||||||||||||||
357 | ScopedString n(scope, id.asStringOrSymbol()); | - | ||||||||||||||||||||||||
358 | // ### Implement more efficiently. | - | ||||||||||||||||||||||||
359 | bool hasProperty = false; | - | ||||||||||||||||||||||||
360 | static_cast<Object *>(m)->get(n, &hasProperty); | - | ||||||||||||||||||||||||
361 | return hasProperty ? Attr_Data : Attr_Invalid; executed 6 times by 1 test: return hasProperty ? Attr_Data : Attr_Invalid; Executed by:
| 6 | ||||||||||||||||||||||||
362 | } | - | ||||||||||||||||||||||||
363 | - | |||||||||||||||||||||||||
364 | return QV4::Object::virtualGetOwnProperty(m, id, p); never executed: return QV4::Object::virtualGetOwnProperty(m, id, p); | 0 | ||||||||||||||||||||||||
365 | } | - | ||||||||||||||||||||||||
366 | - | |||||||||||||||||||||||||
367 | bool QQmlTypeWrapper::virtualIsEqualTo(Managed *a, Managed *b) | - | ||||||||||||||||||||||||
368 | { | - | ||||||||||||||||||||||||
369 | Q_ASSERT(a->as<QV4::QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
370 | QV4::QQmlTypeWrapper *qmlTypeWrapperA = static_cast<QV4::QQmlTypeWrapper *>(a); | - | ||||||||||||||||||||||||
371 | if (QV4::QQmlTypeWrapper *qmlTypeWrapperB = b->as<QV4::QQmlTypeWrapper>())
| 2-6 | ||||||||||||||||||||||||
372 | return qmlTypeWrapperA->toVariant() == qmlTypeWrapperB->toVariant(); executed 2 times by 1 test: return qmlTypeWrapperA->toVariant() == qmlTypeWrapperB->toVariant(); Executed by:
| 2 | ||||||||||||||||||||||||
373 | else if (QV4::QObjectWrapper *qobjectWrapper = b->as<QV4::QObjectWrapper>())
| 0-6 | ||||||||||||||||||||||||
374 | return qmlTypeWrapperA->toVariant().value<QObject*>() == qobjectWrapper->object(); executed 6 times by 1 test: return qmlTypeWrapperA->toVariant().value<QObject*>() == qobjectWrapper->object(); Executed by:
| 6 | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
377 | } | - | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | ReturnedValue QQmlTypeWrapper::virtualInstanceOf(const Object *typeObject, const Value &var) | - | ||||||||||||||||||||||||
380 | { | - | ||||||||||||||||||||||||
381 | Q_ASSERT(typeObject->as<QV4::QQmlTypeWrapper>()); | - | ||||||||||||||||||||||||
382 | const QV4::QQmlTypeWrapper *typeWrapper = static_cast<const QV4::QQmlTypeWrapper *>(typeObject); | - | ||||||||||||||||||||||||
383 | QV4::ExecutionEngine *engine = typeObject->internalClass()->engine; | - | ||||||||||||||||||||||||
384 | QQmlEnginePrivate *qenginepriv = QQmlEnginePrivate::get(engine->qmlEngine()); | - | ||||||||||||||||||||||||
385 | - | |||||||||||||||||||||||||
386 | // can only compare a QObject* against a QML type | - | ||||||||||||||||||||||||
387 | const QObjectWrapper *wrapper = var.as<QObjectWrapper>(); | - | ||||||||||||||||||||||||
388 | if (!wrapper)
| 0-56 | ||||||||||||||||||||||||
389 | return engine->throwTypeError(); never executed: return engine->throwTypeError(); | 0 | ||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||
391 | // in case the wrapper outlived the QObject* | - | ||||||||||||||||||||||||
392 | const QObject *wrapperObject = wrapper->object(); | - | ||||||||||||||||||||||||
393 | if (!wrapperObject)
| 0-56 | ||||||||||||||||||||||||
394 | return engine->throwTypeError(); never executed: return engine->throwTypeError(); | 0 | ||||||||||||||||||||||||
395 | - | |||||||||||||||||||||||||
396 | const int myTypeId = typeWrapper->d()->type().typeId(); | - | ||||||||||||||||||||||||
397 | QQmlMetaObject myQmlType; | - | ||||||||||||||||||||||||
398 | if (myTypeId == 0) {
| 0-56 | ||||||||||||||||||||||||
399 | // we're a composite type; a composite type cannot be equal to a | - | ||||||||||||||||||||||||
400 | // non-composite object instance (Rectangle{} is never an instance of | - | ||||||||||||||||||||||||
401 | // CustomRectangle) | - | ||||||||||||||||||||||||
402 | QQmlData *theirDData = QQmlData::get(wrapperObject, /*create=*/false); | - | ||||||||||||||||||||||||
403 | Q_ASSERT(theirDData); // must exist, otherwise how do we have a QObjectWrapper for it?! | - | ||||||||||||||||||||||||
404 | if (!theirDData->compilationUnit)
| 0 | ||||||||||||||||||||||||
405 | return Encode(false); never executed: return Encode(false); | 0 | ||||||||||||||||||||||||
406 | - | |||||||||||||||||||||||||
407 | QQmlRefPointer<QQmlTypeData> td = qenginepriv->typeLoader.getType(typeWrapper->d()->type().sourceUrl()); | - | ||||||||||||||||||||||||
408 | CompiledData::CompilationUnit *cu = td->compilationUnit(); | - | ||||||||||||||||||||||||
409 | myQmlType = qenginepriv->metaObjectForType(cu->metaTypeId); | - | ||||||||||||||||||||||||
410 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
411 | myQmlType = qenginepriv->metaObjectForType(myTypeId); | - | ||||||||||||||||||||||||
412 | } executed 56 times by 1 test: end of block Executed by:
| 56 | ||||||||||||||||||||||||
413 | - | |||||||||||||||||||||||||
414 | const QMetaObject *theirType = wrapperObject->metaObject(); | - | ||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||
416 | return QV4::Encode(QQmlMetaObject::canConvert(theirType, myQmlType)); executed 56 times by 1 test: return QV4::Encode(QQmlMetaObject::canConvert(theirType, myQmlType)); Executed by:
| 56 | ||||||||||||||||||||||||
417 | } | - | ||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||
419 | void Heap::QQmlScopedEnumWrapper::destroy() | - | ||||||||||||||||||||||||
420 | { | - | ||||||||||||||||||||||||
421 | QQmlType::derefHandle(typePrivate); | - | ||||||||||||||||||||||||
422 | typePrivate = nullptr; | - | ||||||||||||||||||||||||
423 | Object::destroy(); | - | ||||||||||||||||||||||||
424 | } never executed: end of block | 0 | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | QQmlType Heap::QQmlScopedEnumWrapper::type() const | - | ||||||||||||||||||||||||
427 | { | - | ||||||||||||||||||||||||
428 | return QQmlType(typePrivate); never executed: return QQmlType(typePrivate); | 0 | ||||||||||||||||||||||||
429 | } | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | ReturnedValue QQmlScopedEnumWrapper::virtualGet(const Managed *m, PropertyKey id, const Value *receiver, bool *hasProperty) | - | ||||||||||||||||||||||||
432 | { | - | ||||||||||||||||||||||||
433 | Q_ASSERT(m->as<QQmlScopedEnumWrapper>()); | - | ||||||||||||||||||||||||
434 | if (!id.isString())
| 0 | ||||||||||||||||||||||||
435 | return Object::virtualGet(m, id, receiver, hasProperty); never executed: return Object::virtualGet(m, id, receiver, hasProperty); | 0 | ||||||||||||||||||||||||
436 | - | |||||||||||||||||||||||||
437 | const QQmlScopedEnumWrapper *resource = static_cast<const QQmlScopedEnumWrapper *>(m); | - | ||||||||||||||||||||||||
438 | QV4::ExecutionEngine *v4 = resource->engine(); | - | ||||||||||||||||||||||||
439 | QV4::Scope scope(v4); | - | ||||||||||||||||||||||||
440 | ScopedString name(scope, id.asStringOrSymbol()); | - | ||||||||||||||||||||||||
441 | - | |||||||||||||||||||||||||
442 | QQmlType type = resource->d()->type(); | - | ||||||||||||||||||||||||
443 | int index = resource->d()->scopeEnumIndex; | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | bool ok = false; | - | ||||||||||||||||||||||||
446 | int value = type.scopedEnumValue(QQmlEnginePrivate::get(v4->qmlEngine()), index, name, &ok); | - | ||||||||||||||||||||||||
447 | if (hasProperty)
| 0 | ||||||||||||||||||||||||
448 | *hasProperty = ok; never executed: *hasProperty = ok; | 0 | ||||||||||||||||||||||||
449 | if (ok)
| 0 | ||||||||||||||||||||||||
450 | return QV4::Primitive::fromInt32(value).asReturnedValue(); never executed: return QV4::Primitive::fromInt32(value).asReturnedValue(); | 0 | ||||||||||||||||||||||||
451 | - | |||||||||||||||||||||||||
452 | return Encode::undefined(); never executed: return Encode::undefined(); | 0 | ||||||||||||||||||||||||
453 | } | - | ||||||||||||||||||||||||
454 | - | |||||||||||||||||||||||||
455 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |