Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/qml/qqmldelayedcallqueue.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 "qqmldelayedcallqueue_p.h" | - | ||||||
41 | #include <private/qv8engine_p.h> | - | ||||||
42 | #include <private/qqmlengine_p.h> | - | ||||||
43 | #include <private/qqmljavascriptexpression_p.h> | - | ||||||
44 | #include <private/qv4value_p.h> | - | ||||||
45 | #include <private/qv4jscall_p.h> | - | ||||||
46 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||
47 | - | |||||||
48 | #include <QQmlError> | - | ||||||
49 | - | |||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||
51 | - | |||||||
52 | // | - | ||||||
53 | // struct QQmlDelayedCallQueue::DelayedFunctionCall | - | ||||||
54 | // | - | ||||||
55 | - | |||||||
56 | void QQmlDelayedCallQueue::DelayedFunctionCall::execute(QV4::ExecutionEngine *engine) const | - | ||||||
57 | { | - | ||||||
58 | if (!m_guarded ||
| 0-94 | ||||||
59 | (!m_objectGuard.isNull() &&
| 12-82 | ||||||
60 | !QQmlData::wasDeleted(m_objectGuard) &&
| 0-82 | ||||||
61 | QQmlData::get(m_objectGuard) &&
| 0-82 | ||||||
62 | !QQmlData::get(m_objectGuard)->isQueuedForDeletion)) {
| 0-82 | ||||||
63 | - | |||||||
64 | QV4::Scope scope(engine); | - | ||||||
65 | - | |||||||
66 | QV4::ArrayObject *array = m_args.as<QV4::ArrayObject>(); | - | ||||||
67 | const QV4::FunctionObject *callback = m_function.as<QV4::FunctionObject>(); | - | ||||||
68 | Q_ASSERT(callback); | - | ||||||
69 | const int argCount = array ? array->getLength() : 0;
| 6-76 | ||||||
70 | QV4::JSCallData jsCallData(scope, argCount); | - | ||||||
71 | *jsCallData->thisObject = QV4::Encode::undefined(); | - | ||||||
72 | - | |||||||
73 | for (int i = 0; i < argCount; i++) {
| 10-82 | ||||||
74 | jsCallData->args[i] = array->get(i); | - | ||||||
75 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||
76 | - | |||||||
77 | callback->call(jsCallData); | - | ||||||
78 | - | |||||||
79 | if (scope.engine->hasException) {
| 2-80 | ||||||
80 | QQmlError error = scope.engine->catchExceptionAsQmlError(); | - | ||||||
81 | error.setDescription(error.description() + QLatin1String(" (exception occurred during delayed function evaluation)")); | - | ||||||
82 | QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error); | - | ||||||
83 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
84 | } executed 82 times by 2 tests: end of block Executed by:
| 82 | ||||||
85 | } executed 94 times by 2 tests: end of block Executed by:
| 94 | ||||||
86 | - | |||||||
87 | // | - | ||||||
88 | // class QQmlDelayedCallQueue | - | ||||||
89 | // | - | ||||||
90 | - | |||||||
91 | QQmlDelayedCallQueue::QQmlDelayedCallQueue() | - | ||||||
92 | : QObject(nullptr), m_engine(nullptr), m_callbackOutstanding(false) | - | ||||||
93 | { | - | ||||||
94 | } executed 11448 times by 151 tests: end of block Executed by:
| 11448 | ||||||
95 | - | |||||||
96 | QQmlDelayedCallQueue::~QQmlDelayedCallQueue() | - | ||||||
97 | { | - | ||||||
98 | } | - | ||||||
99 | - | |||||||
100 | void QQmlDelayedCallQueue::init(QV4::ExecutionEngine* engine) | - | ||||||
101 | { | - | ||||||
102 | m_engine = engine; | - | ||||||
103 | - | |||||||
104 | const QMetaObject &metaObject = QQmlDelayedCallQueue::staticMetaObject; | - | ||||||
105 | int methodIndex = metaObject.indexOfSlot("ticked()"); | - | ||||||
106 | m_tickedMethod = metaObject.method(methodIndex); | - | ||||||
107 | } executed 11448 times by 151 tests: end of block Executed by:
| 11448 | ||||||
108 | - | |||||||
109 | QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) | - | ||||||
110 | { | - | ||||||
111 | QV4::Scope scope(b); | - | ||||||
112 | if (argc == 0)
| 0-454 | ||||||
113 | THROW_GENERIC_ERROR("Qt.callLater: no arguments given"); never executed: return scope.engine->throwError(QString::fromUtf8("Qt.callLater: no arguments given")); | 0 | ||||||
114 | - | |||||||
115 | const QV4::FunctionObject *func = argv[0].as<QV4::FunctionObject>(); | - | ||||||
116 | - | |||||||
117 | if (!func)
| 0-454 | ||||||
118 | THROW_GENERIC_ERROR("Qt.callLater: first argument not a function or signal"); never executed: return scope.engine->throwError(QString::fromUtf8("Qt.callLater: first argument not a function or signal")); | 0 | ||||||
119 | - | |||||||
120 | QPair<QObject *, int> functionData = QV4::QObjectMethod::extractQtMethod(func); | - | ||||||
121 | QV4::ReturnedValue arg0 = argc ? argv[0].asReturnedValue() : QV4::Encode::undefined();
| 0-454 | ||||||
122 | - | |||||||
123 | QVector<DelayedFunctionCall>::Iterator iter; | - | ||||||
124 | if (functionData.second != -1) {
| 218-236 | ||||||
125 | // This is a QObject function wrapper | - | ||||||
126 | iter = m_delayedFunctionCalls.begin(); | - | ||||||
127 | while (iter != m_delayedFunctionCalls.end()) {
| 42-410 | ||||||
128 | DelayedFunctionCall& dfc = *iter; | - | ||||||
129 | QPair<QObject *, int> storedFunctionData = QV4::QObjectMethod::extractQtMethod(dfc.m_function.as<QV4::FunctionObject>()); | - | ||||||
130 | if (storedFunctionData == functionData) {
| 194-216 | ||||||
131 | break; // Already stored! executed 194 times by 1 test: break; Executed by:
| 194 | ||||||
132 | } | - | ||||||
133 | ++iter; | - | ||||||
134 | } executed 216 times by 1 test: end of block Executed by:
| 216 | ||||||
135 | } else { executed 236 times by 1 test: end of block Executed by:
| 236 | ||||||
136 | // This is a JavaScript function (dynamic slot on VMEMO) | - | ||||||
137 | iter = m_delayedFunctionCalls.begin(); | - | ||||||
138 | while (iter != m_delayedFunctionCalls.end()) {
| 62-500 | ||||||
139 | DelayedFunctionCall& dfc = *iter; | - | ||||||
140 | if (arg0 == dfc.m_function.value()) {
| 156-344 | ||||||
141 | break; // Already stored! executed 156 times by 2 tests: break; Executed by:
| 156 | ||||||
142 | } | - | ||||||
143 | ++iter; | - | ||||||
144 | } executed 344 times by 1 test: end of block Executed by:
| 344 | ||||||
145 | } executed 218 times by 2 tests: end of block Executed by:
| 218 | ||||||
146 | - | |||||||
147 | const bool functionAlreadyStored = (iter != m_delayedFunctionCalls.end()); | - | ||||||
148 | if (functionAlreadyStored) {
| 104-350 | ||||||
149 | DelayedFunctionCall dfc = *iter; | - | ||||||
150 | m_delayedFunctionCalls.erase(iter); | - | ||||||
151 | m_delayedFunctionCalls.append(dfc); | - | ||||||
152 | } else { executed 350 times by 2 tests: end of block Executed by:
| 350 | ||||||
153 | m_delayedFunctionCalls.append(QV4::PersistentValue(m_engine, arg0)); | - | ||||||
154 | } executed 104 times by 2 tests: end of block Executed by:
| 104 | ||||||
155 | - | |||||||
156 | DelayedFunctionCall& dfc = m_delayedFunctionCalls.last(); | - | ||||||
157 | if (dfc.m_objectGuard.isNull()) {
| 104-350 | ||||||
158 | if (functionData.second != -1) {
| 42-62 | ||||||
159 | // if it's a qobject function wrapper, guard against qobject deletion | - | ||||||
160 | dfc.m_objectGuard = QQmlGuard<QObject>(functionData.first); | - | ||||||
161 | dfc.m_guarded = true; | - | ||||||
162 | } else if (func->scope()->type == QV4::Heap::ExecutionContext::Type_QmlContext) { executed 42 times by 1 test: end of block Executed by:
| 2-60 | ||||||
163 | QV4::QmlContext::Data *g = static_cast<QV4::QmlContext::Data *>(func->scope()); | - | ||||||
164 | Q_ASSERT(g->qml()->scopeObject); | - | ||||||
165 | dfc.m_objectGuard = QQmlGuard<QObject>(g->qml()->scopeObject); | - | ||||||
166 | dfc.m_guarded = true; | - | ||||||
167 | } executed 60 times by 2 tests: end of block Executed by:
| 60 | ||||||
168 | } executed 104 times by 2 tests: end of block Executed by:
| 104 | ||||||
169 | storeAnyArguments(dfc, argv, argc, 1, m_engine); | - | ||||||
170 | - | |||||||
171 | if (!m_callbackOutstanding) {
| 24-430 | ||||||
172 | m_tickedMethod.invoke(this, Qt::QueuedConnection); | - | ||||||
173 | m_callbackOutstanding = true; | - | ||||||
174 | } executed 24 times by 2 tests: end of block Executed by:
| 24 | ||||||
175 | return QV4::Encode::undefined(); executed 454 times by 2 tests: return QV4::Encode::undefined(); Executed by:
| 454 | ||||||
176 | } | - | ||||||
177 | - | |||||||
178 | void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, const QV4::Value *argv, int argc, int offset, QV4::ExecutionEngine *engine) | - | ||||||
179 | { | - | ||||||
180 | const int length = argc - offset; | - | ||||||
181 | if (length == 0) {
| 12-442 | ||||||
182 | dfc.m_args.clear(); | - | ||||||
183 | return; executed 442 times by 2 tests: return; Executed by:
| 442 | ||||||
184 | } | - | ||||||
185 | QV4::Scope scope(engine); | - | ||||||
186 | QV4::ScopedArrayObject array(scope, engine->newArrayObject(length)); | - | ||||||
187 | uint i = 0; | - | ||||||
188 | for (int j = offset, ej = argc; j < ej; ++i, ++j)
| 12-24 | ||||||
189 | array->put(i, argv[j]); executed 24 times by 1 test: array->put(i, argv[j]); Executed by:
| 24 | ||||||
190 | dfc.m_args.set(engine, array); | - | ||||||
191 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||
192 | - | |||||||
193 | void QQmlDelayedCallQueue::executeAllExpired_Later() | - | ||||||
194 | { | - | ||||||
195 | // Make a local copy of the list and clear m_delayedFunctionCalls | - | ||||||
196 | // This ensures correct behavior in the case of recursive calls to Qt.callLater() | - | ||||||
197 | QVector<DelayedFunctionCall> delayedCalls = m_delayedFunctionCalls; | - | ||||||
198 | m_delayedFunctionCalls.clear(); | - | ||||||
199 | - | |||||||
200 | QVector<DelayedFunctionCall>::Iterator iter = delayedCalls.begin(); | - | ||||||
201 | while (iter != delayedCalls.end()) {
| 22-94 | ||||||
202 | DelayedFunctionCall& dfc = *iter; | - | ||||||
203 | dfc.execute(m_engine); | - | ||||||
204 | ++iter; | - | ||||||
205 | } executed 94 times by 2 tests: end of block Executed by:
| 94 | ||||||
206 | } executed 22 times by 2 tests: end of block Executed by:
| 22 | ||||||
207 | - | |||||||
208 | void QQmlDelayedCallQueue::ticked() | - | ||||||
209 | { | - | ||||||
210 | m_callbackOutstanding = false; | - | ||||||
211 | executeAllExpired_Later(); | - | ||||||
212 | } executed 22 times by 2 tests: end of block Executed by:
| 22 | ||||||
213 | - | |||||||
214 | QT_END_NAMESPACE | - | ||||||
215 | - | |||||||
216 | #include "moc_qqmldelayedcallqueue_p.cpp" | - | ||||||
Source code | Switch to Preprocessed file |