Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4serialize.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 "qv4serialize_p.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #include <private/qv8engine_p.h> | - | ||||||||||||
43 | #if QT_CONFIG(qml_list_model) | - | ||||||||||||
44 | #include <private/qqmllistmodel_p.h> | - | ||||||||||||
45 | #include <private/qqmllistmodelworkeragent_p.h> | - | ||||||||||||
46 | #endif | - | ||||||||||||
47 | - | |||||||||||||
48 | #include <private/qv4value_p.h> | - | ||||||||||||
49 | #include <private/qv4dateobject_p.h> | - | ||||||||||||
50 | #include <private/qv4regexpobject_p.h> | - | ||||||||||||
51 | #if QT_CONFIG(qml_sequence_object) | - | ||||||||||||
52 | #include <private/qv4sequenceobject_p.h> | - | ||||||||||||
53 | #endif | - | ||||||||||||
54 | #include <private/qv4objectproto_p.h> | - | ||||||||||||
55 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||
56 | - | |||||||||||||
57 | QT_BEGIN_NAMESPACE | - | ||||||||||||
58 | - | |||||||||||||
59 | using namespace QV4; | - | ||||||||||||
60 | - | |||||||||||||
61 | // We allow the following JavaScript types to be passed between the main and | - | ||||||||||||
62 | // the secondary thread: | - | ||||||||||||
63 | // + undefined | - | ||||||||||||
64 | // + null | - | ||||||||||||
65 | // + Boolean | - | ||||||||||||
66 | // + String | - | ||||||||||||
67 | // + Function | - | ||||||||||||
68 | // + Array | - | ||||||||||||
69 | // + "Simple" Objects | - | ||||||||||||
70 | // + Number | - | ||||||||||||
71 | // + Date | - | ||||||||||||
72 | // + RegExp | - | ||||||||||||
73 | // <quint8 type><quint24 size><data> | - | ||||||||||||
74 | - | |||||||||||||
75 | enum Type { | - | ||||||||||||
76 | WorkerUndefined, | - | ||||||||||||
77 | WorkerNull, | - | ||||||||||||
78 | WorkerTrue, | - | ||||||||||||
79 | WorkerFalse, | - | ||||||||||||
80 | WorkerString, | - | ||||||||||||
81 | WorkerFunction, | - | ||||||||||||
82 | WorkerArray, | - | ||||||||||||
83 | WorkerObject, | - | ||||||||||||
84 | WorkerInt32, | - | ||||||||||||
85 | WorkerUint32, | - | ||||||||||||
86 | WorkerNumber, | - | ||||||||||||
87 | WorkerDate, | - | ||||||||||||
88 | WorkerRegexp, | - | ||||||||||||
89 | #if QT_CONFIG(qml_list_model) | - | ||||||||||||
90 | WorkerListModel, | - | ||||||||||||
91 | #endif | - | ||||||||||||
92 | #if QT_CONFIG(qml_sequence_object) | - | ||||||||||||
93 | WorkerSequence | - | ||||||||||||
94 | #endif | - | ||||||||||||
95 | }; | - | ||||||||||||
96 | - | |||||||||||||
97 | static inline quint32 valueheader(Type type, quint32 size = 0) | - | ||||||||||||
98 | { | - | ||||||||||||
99 | return quint8(type) << 24 | (size & 0xFFFFFF); executed 11872 times by 5 tests: return quint8(type) << 24 | (size & 0xFFFFFF); Executed by:
| 11872 | ||||||||||||
100 | } | - | ||||||||||||
101 | - | |||||||||||||
102 | static inline Type headertype(quint32 header) | - | ||||||||||||
103 | { | - | ||||||||||||
104 | return (Type)(header >> 24); executed 11860 times by 5 tests: return (Type)(header >> 24); Executed by:
| 11860 | ||||||||||||
105 | } | - | ||||||||||||
106 | - | |||||||||||||
107 | static inline quint32 headersize(quint32 header) | - | ||||||||||||
108 | { | - | ||||||||||||
109 | return header & 0xFFFFFF; executed 8682 times by 5 tests: return header & 0xFFFFFF; Executed by:
| 8682 | ||||||||||||
110 | } | - | ||||||||||||
111 | - | |||||||||||||
112 | static inline void push(QByteArray &data, quint32 value) | - | ||||||||||||
113 | { | - | ||||||||||||
114 | data.append((const char *)&value, sizeof(quint32)); | - | ||||||||||||
115 | } executed 12496 times by 5 tests: end of block Executed by:
| 12496 | ||||||||||||
116 | - | |||||||||||||
117 | static inline void push(QByteArray &data, double value) | - | ||||||||||||
118 | { | - | ||||||||||||
119 | data.append((const char *)&value, sizeof(double)); | - | ||||||||||||
120 | } executed 126 times by 3 tests: end of block Executed by:
| 126 | ||||||||||||
121 | - | |||||||||||||
122 | static inline void push(QByteArray &data, void *ptr) | - | ||||||||||||
123 | { | - | ||||||||||||
124 | data.append((const char *)&ptr, sizeof(void *)); | - | ||||||||||||
125 | } executed 928 times by 2 tests: end of block Executed by:
| 928 | ||||||||||||
126 | - | |||||||||||||
127 | static inline void reserve(QByteArray &data, int extra) | - | ||||||||||||
128 | { | - | ||||||||||||
129 | data.reserve(data.size() + extra); | - | ||||||||||||
130 | } executed 7564 times by 5 tests: end of block Executed by:
| 7564 | ||||||||||||
131 | - | |||||||||||||
132 | static inline quint32 popUint32(const char *&data) | - | ||||||||||||
133 | { | - | ||||||||||||
134 | quint32 rv = *((const quint32 *)data); | - | ||||||||||||
135 | data += sizeof(quint32); | - | ||||||||||||
136 | return rv; executed 12484 times by 5 tests: return rv; Executed by:
| 12484 | ||||||||||||
137 | } | - | ||||||||||||
138 | - | |||||||||||||
139 | static inline double popDouble(const char *&data) | - | ||||||||||||
140 | { | - | ||||||||||||
141 | double rv = *((const double *)data); | - | ||||||||||||
142 | data += sizeof(double); | - | ||||||||||||
143 | return rv; executed 126 times by 3 tests: return rv; Executed by:
| 126 | ||||||||||||
144 | } | - | ||||||||||||
145 | - | |||||||||||||
146 | static inline void *popPtr(const char *&data) | - | ||||||||||||
147 | { | - | ||||||||||||
148 | void *rv = *((void *const *)data); | - | ||||||||||||
149 | data += sizeof(void *); | - | ||||||||||||
150 | return rv; executed 928 times by 2 tests: return rv; Executed by:
| 928 | ||||||||||||
151 | } | - | ||||||||||||
152 | - | |||||||||||||
153 | // XXX TODO: Check that worker script is exception safe in the case of | - | ||||||||||||
154 | // serialization/deserialization failures | - | ||||||||||||
155 | - | |||||||||||||
156 | #define ALIGN(size) (((size) + 3) & ~3) | - | ||||||||||||
157 | void Serialize::serialize(QByteArray &data, const QV4::Value &v, ExecutionEngine *engine) | - | ||||||||||||
158 | { | - | ||||||||||||
159 | QV4::Scope scope(engine); | - | ||||||||||||
160 | - | |||||||||||||
161 | if (v.isEmpty()) {
| 0-11872 | ||||||||||||
162 | Q_ASSERT(!"Serialize: got empty value"); | - | ||||||||||||
163 | } else if (v.isUndefined()) { never executed: end of block
| 0-11412 | ||||||||||||
164 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
165 | } else if (v.isNull()) { executed 460 times by 2 tests: end of block Executed by:
| 56-11356 | ||||||||||||
166 | push(data, valueheader(WorkerNull)); | - | ||||||||||||
167 | } else if (v.isBoolean()) { executed 56 times by 1 test: end of block Executed by:
| 56-10370 | ||||||||||||
168 | push(data, valueheader(v.booleanValue() == true ? WorkerTrue : WorkerFalse)); | - | ||||||||||||
169 | } else if (v.isString()) { executed 986 times by 3 tests: end of block Executed by:
| 986-5888 | ||||||||||||
170 | const QString &qstr = v.toQString(); | - | ||||||||||||
171 | int length = qstr.length(); | - | ||||||||||||
172 | if (length > 0xFFFFFF) {
| 0-5888 | ||||||||||||
173 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
174 | return; never executed: return; | 0 | ||||||||||||
175 | } | - | ||||||||||||
176 | int utf16size = ALIGN(length * sizeof(quint16)); | - | ||||||||||||
177 | - | |||||||||||||
178 | reserve(data, utf16size + sizeof(quint32)); | - | ||||||||||||
179 | push(data, valueheader(WorkerString, length)); | - | ||||||||||||
180 | - | |||||||||||||
181 | int offset = data.size(); | - | ||||||||||||
182 | data.resize(data.size() + utf16size); | - | ||||||||||||
183 | char *buffer = data.data() + offset; | - | ||||||||||||
184 | - | |||||||||||||
185 | memcpy(buffer, qstr.constData(), length*sizeof(QChar)); | - | ||||||||||||
186 | } else if (v.as<FunctionObject>()) { executed 5888 times by 5 tests: end of block Executed by:
| 0-5888 | ||||||||||||
187 | // XXX TODO: Implement passing function objects between the main and | - | ||||||||||||
188 | // worker scripts | - | ||||||||||||
189 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
190 | } else if (const QV4::ArrayObject *array = v.as<ArrayObject>()) { never executed: end of block
| 0-3624 | ||||||||||||
191 | uint length = array->getLength(); | - | ||||||||||||
192 | if (length > 0xFFFFFF) {
| 0-858 | ||||||||||||
193 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
194 | return; never executed: return; | 0 | ||||||||||||
195 | } | - | ||||||||||||
196 | reserve(data, sizeof(quint32) + length * sizeof(quint32)); | - | ||||||||||||
197 | push(data, valueheader(WorkerArray, length)); | - | ||||||||||||
198 | ScopedValue val(scope); | - | ||||||||||||
199 | for (uint ii = 0; ii < length; ++ii)
| 858-2046 | ||||||||||||
200 | serialize(data, (val = array->get(ii)), engine); executed 2046 times by 3 tests: serialize(data, (val = array->get(ii)), engine); Executed by:
| 2046 | ||||||||||||
201 | } else if (v.isInteger()) { executed 858 times by 3 tests: end of block Executed by:
| 620-3004 | ||||||||||||
202 | reserve(data, 2 * sizeof(quint32)); | - | ||||||||||||
203 | push(data, valueheader(WorkerInt32)); | - | ||||||||||||
204 | push(data, (quint32)v.integerValue()); | - | ||||||||||||
205 | // } else if (v.IsUint32()) { | - | ||||||||||||
206 | // reserve(data, 2 * sizeof(quint32)); | - | ||||||||||||
207 | // push(data, valueheader(WorkerUint32)); | - | ||||||||||||
208 | // push(data, v.Uint32Value()); | - | ||||||||||||
209 | } else if (v.isNumber()) { executed 620 times by 3 tests: end of block Executed by:
| 122-2882 | ||||||||||||
210 | reserve(data, sizeof(quint32) + sizeof(double)); | - | ||||||||||||
211 | push(data, valueheader(WorkerNumber)); | - | ||||||||||||
212 | push(data, v.asDouble()); | - | ||||||||||||
213 | } else if (const QV4::DateObject *d = v.as<DateObject>()) { executed 122 times by 3 tests: end of block Executed by:
| 4-2878 | ||||||||||||
214 | reserve(data, sizeof(quint32) + sizeof(double)); | - | ||||||||||||
215 | push(data, valueheader(WorkerDate)); | - | ||||||||||||
216 | push(data, d->date()); | - | ||||||||||||
217 | } else if (const RegExpObject *re = v.as<RegExpObject>()) { executed 4 times by 1 test: end of block Executed by:
| 4-2874 | ||||||||||||
218 | quint32 flags = re->flags(); | - | ||||||||||||
219 | QString pattern = re->source(); | - | ||||||||||||
220 | int length = pattern.length() + 1; | - | ||||||||||||
221 | if (length > 0xFFFFFF) {
| 0-4 | ||||||||||||
222 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
223 | return; never executed: return; | 0 | ||||||||||||
224 | } | - | ||||||||||||
225 | int utf16size = ALIGN(length * sizeof(quint16)); | - | ||||||||||||
226 | - | |||||||||||||
227 | reserve(data, sizeof(quint32) + utf16size); | - | ||||||||||||
228 | push(data, valueheader(WorkerRegexp, flags)); | - | ||||||||||||
229 | push(data, (quint32)length); | - | ||||||||||||
230 | - | |||||||||||||
231 | int offset = data.size(); | - | ||||||||||||
232 | data.resize(data.size() + utf16size); | - | ||||||||||||
233 | char *buffer = data.data() + offset; | - | ||||||||||||
234 | - | |||||||||||||
235 | memcpy(buffer, pattern.constData(), length*sizeof(QChar)); | - | ||||||||||||
236 | } else if (const QObjectWrapper *qobjectWrapper = v.as<QV4::QObjectWrapper>()) { executed 4 times by 1 test: end of block Executed by:
| 4-1940 | ||||||||||||
237 | // XXX TODO: Generalize passing objects between the main thread and worker scripts so | - | ||||||||||||
238 | // that others can trivially plug in their elements. | - | ||||||||||||
239 | #if QT_CONFIG(qml_list_model) | - | ||||||||||||
240 | QQmlListModel *lm = qobject_cast<QQmlListModel *>(qobjectWrapper->object()); | - | ||||||||||||
241 | if (lm && lm->agent()) {
| 0-928 | ||||||||||||
242 | QQmlListModelWorkerAgent *agent = lm->agent(); | - | ||||||||||||
243 | agent->addref(); | - | ||||||||||||
244 | push(data, valueheader(WorkerListModel)); | - | ||||||||||||
245 | push(data, (void *)agent); | - | ||||||||||||
246 | return; executed 928 times by 2 tests: return; Executed by:
| 928 | ||||||||||||
247 | } | - | ||||||||||||
248 | #else | - | ||||||||||||
249 | Q_UNUSED(qobjectWrapper); | - | ||||||||||||
250 | #endif | - | ||||||||||||
251 | // No other QObject's are allowed to be sent | - | ||||||||||||
252 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
253 | } else if (const Object *o = v.as<Object>()) { executed 6 times by 1 test: end of block Executed by:
| 0-1940 | ||||||||||||
254 | #if QT_CONFIG(qml_sequence_object) | - | ||||||||||||
255 | if (o->isListType()) {
| 68-1872 | ||||||||||||
256 | // valid sequence. we generate a length (sequence length + 1 for the sequence type) | - | ||||||||||||
257 | uint seqLength = ScopedValue(scope, o->get(engine->id_length()))->toUInt32(); | - | ||||||||||||
258 | uint length = seqLength + 1; | - | ||||||||||||
259 | if (length > 0xFFFFFF) {
| 0-68 | ||||||||||||
260 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
261 | return; never executed: return; | 0 | ||||||||||||
262 | } | - | ||||||||||||
263 | reserve(data, sizeof(quint32) + length * sizeof(quint32)); | - | ||||||||||||
264 | push(data, valueheader(WorkerSequence, length)); | - | ||||||||||||
265 | serialize(data, QV4::Primitive::fromInt32(QV4::SequencePrototype::metaTypeForSequence(o)), engine); // sequence type | - | ||||||||||||
266 | ScopedValue val(scope); | - | ||||||||||||
267 | for (uint ii = 0; ii < seqLength; ++ii)
| 68-188 | ||||||||||||
268 | serialize(data, (val = o->get(ii)), engine); // sequence elements executed 188 times by 2 tests: serialize(data, (val = o->get(ii)), engine); Executed by:
| 188 | ||||||||||||
269 | - | |||||||||||||
270 | return; executed 68 times by 2 tests: return; Executed by:
| 68 | ||||||||||||
271 | } | - | ||||||||||||
272 | #endif | - | ||||||||||||
273 | - | |||||||||||||
274 | // regular object | - | ||||||||||||
275 | QV4::ScopedValue val(scope, v); | - | ||||||||||||
276 | QV4::ScopedArrayObject properties(scope, QV4::ObjectPrototype::getOwnPropertyNames(engine, val)); | - | ||||||||||||
277 | quint32 length = properties->getLength(); | - | ||||||||||||
278 | if (length > 0xFFFFFF) {
| 0-1872 | ||||||||||||
279 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
280 | return; never executed: return; | 0 | ||||||||||||
281 | } | - | ||||||||||||
282 | push(data, valueheader(WorkerObject, length)); | - | ||||||||||||
283 | - | |||||||||||||
284 | QV4::ScopedValue s(scope); | - | ||||||||||||
285 | for (quint32 ii = 0; ii < length; ++ii) {
| 1872-3706 | ||||||||||||
286 | s = properties->get(ii); | - | ||||||||||||
287 | serialize(data, s, engine); | - | ||||||||||||
288 | - | |||||||||||||
289 | QV4::String *str = s->as<String>(); | - | ||||||||||||
290 | val = o->get(str); | - | ||||||||||||
291 | if (scope.hasException())
| 0-3706 | ||||||||||||
292 | scope.engine->catchException(); never executed: scope.engine->catchException(); | 0 | ||||||||||||
293 | - | |||||||||||||
294 | serialize(data, val, engine); | - | ||||||||||||
295 | } executed 3706 times by 4 tests: end of block Executed by:
| 3706 | ||||||||||||
296 | return; executed 1872 times by 4 tests: return; Executed by:
| 1872 | ||||||||||||
297 | } else { | - | ||||||||||||
298 | push(data, valueheader(WorkerUndefined)); | - | ||||||||||||
299 | } never executed: end of block | 0 | ||||||||||||
300 | } | - | ||||||||||||
301 | - | |||||||||||||
302 | ReturnedValue Serialize::deserialize(const char *&data, ExecutionEngine *engine) | - | ||||||||||||
303 | { | - | ||||||||||||
304 | quint32 header = popUint32(data); | - | ||||||||||||
305 | Type type = headertype(header); | - | ||||||||||||
306 | - | |||||||||||||
307 | Scope scope(engine); | - | ||||||||||||
308 | - | |||||||||||||
309 | switch (type) { | - | ||||||||||||
310 | case WorkerUndefined: executed 466 times by 2 tests: case WorkerUndefined: Executed by:
| 466 | ||||||||||||
311 | return QV4::Encode::undefined(); executed 466 times by 2 tests: return QV4::Encode::undefined(); Executed by:
| 466 | ||||||||||||
312 | case WorkerNull: executed 56 times by 1 test: case WorkerNull: Executed by:
| 56 | ||||||||||||
313 | return QV4::Encode::null(); executed 56 times by 1 test: return QV4::Encode::null(); Executed by:
| 56 | ||||||||||||
314 | case WorkerTrue: executed 966 times by 3 tests: case WorkerTrue: Executed by:
| 966 | ||||||||||||
315 | return QV4::Encode(true); executed 966 times by 3 tests: return QV4::Encode(true); Executed by:
| 966 | ||||||||||||
316 | case WorkerFalse: executed 16 times by 1 test: case WorkerFalse: Executed by:
| 16 | ||||||||||||
317 | return QV4::Encode(false); executed 16 times by 1 test: return QV4::Encode(false); Executed by:
| 16 | ||||||||||||
318 | case WorkerString: executed 5884 times by 5 tests: case WorkerString: Executed by:
| 5884 | ||||||||||||
319 | { | - | ||||||||||||
320 | quint32 size = headersize(header); | - | ||||||||||||
321 | QString qstr((const QChar *)data, size); | - | ||||||||||||
322 | data += ALIGN(size * sizeof(quint16)); | - | ||||||||||||
323 | return QV4::Encode(engine->newString(qstr)); executed 5884 times by 5 tests: return QV4::Encode(engine->newString(qstr)); Executed by:
| 5884 | ||||||||||||
324 | } | - | ||||||||||||
325 | case WorkerFunction: never executed: case WorkerFunction: | 0 | ||||||||||||
326 | Q_ASSERT(!"Unreachable"); | - | ||||||||||||
327 | break; never executed: break; | 0 | ||||||||||||
328 | case WorkerArray: executed 858 times by 3 tests: case WorkerArray: Executed by:
| 858 | ||||||||||||
329 | { | - | ||||||||||||
330 | quint32 size = headersize(header); | - | ||||||||||||
331 | ScopedArrayObject a(scope, engine->newArrayObject()); | - | ||||||||||||
332 | ScopedValue v(scope); | - | ||||||||||||
333 | for (quint32 ii = 0; ii < size; ++ii) {
| 858-2046 | ||||||||||||
334 | v = deserialize(data, engine); | - | ||||||||||||
335 | a->put(ii, v); | - | ||||||||||||
336 | } executed 2046 times by 3 tests: end of block Executed by:
| 2046 | ||||||||||||
337 | return a.asReturnedValue(); executed 858 times by 3 tests: return a.asReturnedValue(); Executed by:
| 858 | ||||||||||||
338 | } | - | ||||||||||||
339 | case WorkerObject: executed 1868 times by 4 tests: case WorkerObject: Executed by:
| 1868 | ||||||||||||
340 | { | - | ||||||||||||
341 | quint32 size = headersize(header); | - | ||||||||||||
342 | ScopedObject o(scope, engine->newObject()); | - | ||||||||||||
343 | ScopedValue name(scope); | - | ||||||||||||
344 | ScopedString n(scope); | - | ||||||||||||
345 | ScopedValue value(scope); | - | ||||||||||||
346 | for (quint32 ii = 0; ii < size; ++ii) {
| 1868-3702 | ||||||||||||
347 | name = deserialize(data, engine); | - | ||||||||||||
348 | value = deserialize(data, engine); | - | ||||||||||||
349 | n = name->asReturnedValue(); | - | ||||||||||||
350 | o->put(n, value); | - | ||||||||||||
351 | } executed 3702 times by 4 tests: end of block Executed by:
| 3702 | ||||||||||||
352 | return o.asReturnedValue(); executed 1868 times by 4 tests: return o.asReturnedValue(); Executed by:
| 1868 | ||||||||||||
353 | } | - | ||||||||||||
354 | case WorkerInt32: executed 620 times by 3 tests: case WorkerInt32: Executed by:
| 620 | ||||||||||||
355 | return QV4::Encode((qint32)popUint32(data)); executed 620 times by 3 tests: return QV4::Encode((qint32)popUint32(data)); Executed by:
| 620 | ||||||||||||
356 | case WorkerUint32: never executed: case WorkerUint32: | 0 | ||||||||||||
357 | return QV4::Encode(popUint32(data)); never executed: return QV4::Encode(popUint32(data)); | 0 | ||||||||||||
358 | case WorkerNumber: executed 122 times by 3 tests: case WorkerNumber: Executed by:
| 122 | ||||||||||||
359 | return QV4::Encode(popDouble(data)); executed 122 times by 3 tests: return QV4::Encode(popDouble(data)); Executed by:
| 122 | ||||||||||||
360 | case WorkerDate: executed 4 times by 1 test: case WorkerDate: Executed by:
| 4 | ||||||||||||
361 | return QV4::Encode(engine->newDateObject(QV4::Primitive::fromDouble(popDouble(data)))); executed 4 times by 1 test: return QV4::Encode(engine->newDateObject(QV4::Primitive::fromDouble(popDouble(data)))); Executed by:
| 4 | ||||||||||||
362 | case WorkerRegexp: executed 4 times by 1 test: case WorkerRegexp: Executed by:
| 4 | ||||||||||||
363 | { | - | ||||||||||||
364 | quint32 flags = headersize(header); | - | ||||||||||||
365 | quint32 length = popUint32(data); | - | ||||||||||||
366 | QString pattern = QString((const QChar *)data, length - 1); | - | ||||||||||||
367 | data += ALIGN(length * sizeof(quint16)); | - | ||||||||||||
368 | return Encode(engine->newRegExpObject(pattern, flags)); executed 4 times by 1 test: return Encode(engine->newRegExpObject(pattern, flags)); Executed by:
| 4 | ||||||||||||
369 | } | - | ||||||||||||
370 | #if QT_CONFIG(qml_list_model) | - | ||||||||||||
371 | case WorkerListModel: executed 928 times by 2 tests: case WorkerListModel: Executed by:
| 928 | ||||||||||||
372 | { | - | ||||||||||||
373 | void *ptr = popPtr(data); | - | ||||||||||||
374 | QQmlListModelWorkerAgent *agent = (QQmlListModelWorkerAgent *)ptr; | - | ||||||||||||
375 | QV4::ScopedValue rv(scope, QV4::QObjectWrapper::wrap(engine, agent)); | - | ||||||||||||
376 | // ### Find a better solution then the ugly property | - | ||||||||||||
377 | QQmlListModelWorkerAgent::VariantRef ref(agent); | - | ||||||||||||
378 | QVariant var = qVariantFromValue(ref); | - | ||||||||||||
379 | QV4::ScopedValue v(scope, scope.engine->fromVariant(var)); | - | ||||||||||||
380 | QV4::ScopedString s(scope, engine->newString(QStringLiteral("__qml:hidden:ref"))); executed 928 times by 2 tests: return qstring_literal_temp; Executed by:
| 928 | ||||||||||||
381 | rv->as<Object>()->defineReadonlyProperty(s, v); | - | ||||||||||||
382 | - | |||||||||||||
383 | agent->release(); | - | ||||||||||||
384 | agent->setEngine(engine); | - | ||||||||||||
385 | return rv->asReturnedValue(); executed 928 times by 2 tests: return rv->asReturnedValue(); Executed by:
| 928 | ||||||||||||
386 | } | - | ||||||||||||
387 | #endif | - | ||||||||||||
388 | #if QT_CONFIG(qml_sequence_object) | - | ||||||||||||
389 | case WorkerSequence: executed 68 times by 2 tests: case WorkerSequence: Executed by:
| 68 | ||||||||||||
390 | { | - | ||||||||||||
391 | ScopedValue value(scope); | - | ||||||||||||
392 | bool succeeded = false; | - | ||||||||||||
393 | quint32 length = headersize(header); | - | ||||||||||||
394 | quint32 seqLength = length - 1; | - | ||||||||||||
395 | value = deserialize(data, engine); | - | ||||||||||||
396 | int sequenceType = value->integerValue(); | - | ||||||||||||
397 | ScopedArrayObject array(scope, engine->newArrayObject()); | - | ||||||||||||
398 | array->arrayReserve(seqLength); | - | ||||||||||||
399 | for (quint32 ii = 0; ii < seqLength; ++ii) {
| 68-188 | ||||||||||||
400 | value = deserialize(data, engine); | - | ||||||||||||
401 | array->arrayPut(ii, value); | - | ||||||||||||
402 | } executed 188 times by 2 tests: end of block Executed by:
| 188 | ||||||||||||
403 | array->setArrayLengthUnchecked(seqLength); | - | ||||||||||||
404 | QVariant seqVariant = QV4::SequencePrototype::toVariant(array, sequenceType, &succeeded); | - | ||||||||||||
405 | return QV4::SequencePrototype::fromVariant(engine, seqVariant, &succeeded); executed 68 times by 2 tests: return QV4::SequencePrototype::fromVariant(engine, seqVariant, &succeeded); Executed by:
| 68 | ||||||||||||
406 | } | - | ||||||||||||
407 | #endif | - | ||||||||||||
408 | } | - | ||||||||||||
409 | Q_ASSERT(!"Unreachable"); | - | ||||||||||||
410 | return QV4::Encode::undefined(); never executed: return QV4::Encode::undefined(); | 0 | ||||||||||||
411 | } | - | ||||||||||||
412 | - | |||||||||||||
413 | QByteArray Serialize::serialize(const QV4::Value &value, ExecutionEngine *engine) | - | ||||||||||||
414 | { | - | ||||||||||||
415 | QByteArray rv; | - | ||||||||||||
416 | serialize(rv, value, engine); | - | ||||||||||||
417 | return rv; executed 2158 times by 5 tests: return rv; Executed by:
| 2158 | ||||||||||||
418 | } | - | ||||||||||||
419 | - | |||||||||||||
420 | ReturnedValue Serialize::deserialize(const QByteArray &data, ExecutionEngine *engine) | - | ||||||||||||
421 | { | - | ||||||||||||
422 | const char *stream = data.constData(); | - | ||||||||||||
423 | return deserialize(stream, engine); executed 2154 times by 5 tests: return deserialize(stream, engine); Executed by:
| 2154 | ||||||||||||
424 | } | - | ||||||||||||
425 | - | |||||||||||||
426 | QT_END_NAMESPACE | - | ||||||||||||
427 | - | |||||||||||||
Source code | Switch to Preprocessed file |