Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4arraydata.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 | #include "qv4arraydata_p.h" | - | ||||||||||||||||||
40 | #include "qv4object_p.h" | - | ||||||||||||||||||
41 | #include "qv4functionobject_p.h" | - | ||||||||||||||||||
42 | #include <private/qv4mm_p.h> | - | ||||||||||||||||||
43 | #include "qv4runtime_p.h" | - | ||||||||||||||||||
44 | #include "qv4argumentsobject_p.h" | - | ||||||||||||||||||
45 | #include "qv4string_p.h" | - | ||||||||||||||||||
46 | #include "qv4jscall_p.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | using namespace QV4; | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | DEFINE_MANAGED_VTABLE(ArrayData); | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | const ArrayVTable SimpleArrayData::static_vtbl = | - | ||||||||||||||||||
53 | { | - | ||||||||||||||||||
54 | DEFINE_MANAGED_VTABLE_INT(SimpleArrayData, nullptr), | - | ||||||||||||||||||
55 | Heap::ArrayData::Simple, | - | ||||||||||||||||||
56 | SimpleArrayData::reallocate, | - | ||||||||||||||||||
57 | SimpleArrayData::get, | - | ||||||||||||||||||
58 | SimpleArrayData::put, | - | ||||||||||||||||||
59 | SimpleArrayData::putArray, | - | ||||||||||||||||||
60 | SimpleArrayData::del, | - | ||||||||||||||||||
61 | SimpleArrayData::setAttribute, | - | ||||||||||||||||||
62 | SimpleArrayData::push_front, | - | ||||||||||||||||||
63 | SimpleArrayData::pop_front, | - | ||||||||||||||||||
64 | SimpleArrayData::truncate, | - | ||||||||||||||||||
65 | SimpleArrayData::length | - | ||||||||||||||||||
66 | }; | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | const ArrayVTable SparseArrayData::static_vtbl = | - | ||||||||||||||||||
69 | { | - | ||||||||||||||||||
70 | DEFINE_MANAGED_VTABLE_INT(SparseArrayData, nullptr), | - | ||||||||||||||||||
71 | Heap::ArrayData::Sparse, | - | ||||||||||||||||||
72 | SparseArrayData::reallocate, | - | ||||||||||||||||||
73 | SparseArrayData::get, | - | ||||||||||||||||||
74 | SparseArrayData::put, | - | ||||||||||||||||||
75 | SparseArrayData::putArray, | - | ||||||||||||||||||
76 | SparseArrayData::del, | - | ||||||||||||||||||
77 | SparseArrayData::setAttribute, | - | ||||||||||||||||||
78 | SparseArrayData::push_front, | - | ||||||||||||||||||
79 | SparseArrayData::pop_front, | - | ||||||||||||||||||
80 | SparseArrayData::truncate, | - | ||||||||||||||||||
81 | SparseArrayData::length | - | ||||||||||||||||||
82 | }; | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | Q_STATIC_ASSERT(sizeof(Heap::ArrayData) == sizeof(Heap::SimpleArrayData)); | - | ||||||||||||||||||
85 | Q_STATIC_ASSERT(sizeof(Heap::ArrayData) == sizeof(Heap::SparseArrayData)); | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | void Heap::ArrayData::markObjects(Heap::Base *base, MarkStack *stack) | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | ArrayData *a = static_cast<ArrayData *>(base); | - | ||||||||||||||||||
90 | a->values.mark(stack); | - | ||||||||||||||||||
91 | } executed 13121 times by 11 tests: end of block Executed by:
| 13121 | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | - | |||||||||||||||||||
94 | void ArrayData::realloc(Object *o, Type newType, uint requested, bool enforceAttributes) | - | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | Scope scope(o->engine()); | - | ||||||||||||||||||
97 | Scoped<ArrayData> d(scope, o->arrayData()); | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | uint alloc = 8; | - | ||||||||||||||||||
100 | uint toCopy = 0; | - | ||||||||||||||||||
101 | uint offset = 0; | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | if (d) {
| 22063-71822 | ||||||||||||||||||
104 | bool hasAttrs = d->attrs(); | - | ||||||||||||||||||
105 | enforceAttributes |= hasAttrs; | - | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | if (requested <= d->alloc() && newType == d->type() && hasAttrs == enforceAttributes)
| 823-13353 | ||||||||||||||||||
108 | return; executed 7193 times by 7 tests: return; Executed by:
| 7193 | ||||||||||||||||||
109 | if (alloc < d->alloc())
| 2280-12598 | ||||||||||||||||||
110 | alloc = d->alloc(); executed 2280 times by 7 tests: alloc = d->alloc(); Executed by:
| 2280 | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | if (d->type() < Heap::ArrayData::Sparse) {
| 5211-9663 | ||||||||||||||||||
113 | offset = d->d()->offset; | - | ||||||||||||||||||
114 | toCopy = d->d()->values.size; | - | ||||||||||||||||||
115 | } else { executed 9668 times by 12 tests: end of block Executed by:
| 9668 | ||||||||||||||||||
116 | toCopy = d->alloc(); | - | ||||||||||||||||||
117 | } executed 5211 times by 1 test: end of block Executed by:
| 5211 | ||||||||||||||||||
118 | if (d->type() > newType)
| 2631-12250 | ||||||||||||||||||
119 | newType = d->type(); executed 2631 times by 1 test: newType = d->type(); Executed by:
| 2631 | ||||||||||||||||||
120 | } executed 14875 times by 12 tests: end of block Executed by:
| 14875 | ||||||||||||||||||
121 | if (enforceAttributes && newType == Heap::ArrayData::Simple)
| 822-80174 | ||||||||||||||||||
122 | newType = Heap::ArrayData::Complex; executed 818 times by 1 test: newType = Heap::ArrayData::Complex; Executed by:
| 818 | ||||||||||||||||||
123 | - | |||||||||||||||||||
124 | while (alloc < requested)
| 10480-86694 | ||||||||||||||||||
125 | alloc *= 2; executed 10482 times by 13 tests: alloc *= 2; Executed by:
| 10482 | ||||||||||||||||||
126 | size_t size = sizeof(Heap::ArrayData) + (alloc - 1)*sizeof(Value); | - | ||||||||||||||||||
127 | if (enforceAttributes)
| 6516-80185 | ||||||||||||||||||
128 | size += alloc*sizeof(PropertyAttributes); executed 6521 times by 1 test: size += alloc*sizeof(PropertyAttributes); Executed by:
| 6521 | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | Scoped<ArrayData> newData(scope); | - | ||||||||||||||||||
131 | if (newType < Heap::ArrayData::Sparse) {
| 8394-78286 | ||||||||||||||||||
132 | Heap::SimpleArrayData *n = scope.engine->memoryManager->allocManaged<SimpleArrayData>(size); | - | ||||||||||||||||||
133 | n->init(); | - | ||||||||||||||||||
134 | n->offset = 0; | - | ||||||||||||||||||
135 | n->values.size = d ? d->d()->values.size : 0;
| 6951-71343 | ||||||||||||||||||
136 | newData = n; | - | ||||||||||||||||||
137 | } else { executed 78312 times by 51 tests: end of block Executed by:
| 78312 | ||||||||||||||||||
138 | Heap::SparseArrayData *n = scope.engine->memoryManager->allocManaged<SparseArrayData>(size); | - | ||||||||||||||||||
139 | n->init(); | - | ||||||||||||||||||
140 | newData = n; | - | ||||||||||||||||||
141 | } executed 8404 times by 2 tests: end of block Executed by:
| 8404 | ||||||||||||||||||
142 | newData->setAlloc(alloc); | - | ||||||||||||||||||
143 | newData->setType(newType); | - | ||||||||||||||||||
144 | newData->setAttrs(enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->d()->values.values + alloc) : nullptr); | - | ||||||||||||||||||
145 | o->setArrayData(newData); | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | if (d) {
| 14888-71885 | ||||||||||||||||||
148 | if (enforceAttributes) {
| 6079-8807 | ||||||||||||||||||
149 | if (d->attrs())
| 2649-3434 | ||||||||||||||||||
150 | memcpy(newData->attrs(), d->attrs(), sizeof(PropertyAttributes)*toCopy); executed 2649 times by 1 test: memcpy(newData->attrs(), d->attrs(), sizeof(PropertyAttributes)*toCopy); Executed by:
| 2649 | ||||||||||||||||||
151 | else | - | ||||||||||||||||||
152 | for (uint i = 0; i < toCopy; ++i)
| 3426-25822 | ||||||||||||||||||
153 | newData->attrs()[i] = Attr_Data; executed 25820 times by 1 test: newData->attrs()[i] = Attr_Data; Executed by:
| 25820 | ||||||||||||||||||
154 | } executed 6072 times by 1 test: end of block Executed by:
| 6072 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | if (toCopy > d->d()->values.alloc - offset) {
| 24-14861 | ||||||||||||||||||
157 | uint copyFromStart = toCopy - (d->d()->values.alloc - offset); | - | ||||||||||||||||||
158 | // no write barrier required here | - | ||||||||||||||||||
159 | memcpy(newData->d()->values.values + toCopy - copyFromStart, d->d()->values.values, sizeof(Value)*copyFromStart); | - | ||||||||||||||||||
160 | toCopy -= copyFromStart; | - | ||||||||||||||||||
161 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
162 | // no write barrier required here | - | ||||||||||||||||||
163 | memcpy(newData->d()->values.values, d->d()->values.values + offset, sizeof(Value)*toCopy); | - | ||||||||||||||||||
164 | } executed 14871 times by 12 tests: end of block Executed by:
| 14871 | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | if (newType != Heap::ArrayData::Sparse)
| 8403-78282 | ||||||||||||||||||
167 | return; executed 78280 times by 51 tests: return; Executed by:
| 78280 | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | Heap::SparseArrayData *sparse = static_cast<Heap::SparseArrayData *>(newData->d()); | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | Value *lastFree; | - | ||||||||||||||||||
172 | if (d && d->type() == Heap::ArrayData::Sparse) {
| 2718-5213 | ||||||||||||||||||
173 | Heap::SparseArrayData *old = static_cast<Heap::SparseArrayData *>(d->d()); | - | ||||||||||||||||||
174 | sparse->sparse = old->sparse; | - | ||||||||||||||||||
175 | old->sparse = nullptr; | - | ||||||||||||||||||
176 | lastFree = &sparse->sparse->freeList; | - | ||||||||||||||||||
177 | } else { executed 5215 times by 1 test: end of block Executed by:
| 5215 | ||||||||||||||||||
178 | sparse->sparse = new SparseArray; | - | ||||||||||||||||||
179 | lastFree = &sparse->sparse->freeList; | - | ||||||||||||||||||
180 | *lastFree = Encode(0); | - | ||||||||||||||||||
181 | for (uint i = 0; i < toCopy; ++i) {
| 3183-21077 | ||||||||||||||||||
182 | if (!sparse->values[i].isEmpty()) {
| 2563-18514 | ||||||||||||||||||
183 | SparseArrayNode *n = sparse->sparse->insert(i); | - | ||||||||||||||||||
184 | n->value = i; | - | ||||||||||||||||||
185 | } else { executed 2565 times by 1 test: end of block Executed by:
| 2565 | ||||||||||||||||||
186 | *lastFree = Encode(i); | - | ||||||||||||||||||
187 | sparse->values.values[i].setEmpty(); | - | ||||||||||||||||||
188 | lastFree = &sparse->values.values[i]; | - | ||||||||||||||||||
189 | } executed 18516 times by 1 test: end of block Executed by:
| 18516 | ||||||||||||||||||
190 | } | - | ||||||||||||||||||
191 | } executed 3183 times by 2 tests: end of block Executed by:
| 3183 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | if (toCopy < sparse->values.alloc) {
| 2609-5790 | ||||||||||||||||||
194 | for (uint i = toCopy; i < sparse->values.alloc; ++i) {
| 5801-4237763 | ||||||||||||||||||
195 | *lastFree = Encode(i); | - | ||||||||||||||||||
196 | sparse->values.values[i].setEmpty(); | - | ||||||||||||||||||
197 | lastFree = &sparse->values.values[i]; | - | ||||||||||||||||||
198 | } executed 4237749 times by 2 tests: end of block Executed by:
| 4237749 | ||||||||||||||||||
199 | } executed 5804 times by 2 tests: end of block Executed by:
| 5804 | ||||||||||||||||||
200 | *lastFree = Encode(-1); | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | Q_ASSERT(sparse->sparse->freeList.isInteger()); | - | ||||||||||||||||||
203 | // ### Could explicitly free the old data | - | ||||||||||||||||||
204 | } executed 8406 times by 2 tests: end of block Executed by:
| 8406 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | Heap::ArrayData *SimpleArrayData::reallocate(Object *o, uint n, bool enforceAttributes) | - | ||||||||||||||||||
207 | { | - | ||||||||||||||||||
208 | realloc(o, Heap::ArrayData::Simple, n, enforceAttributes); | - | ||||||||||||||||||
209 | return o->arrayData(); executed 5858 times by 8 tests: return o->arrayData(); Executed by:
| 5858 | ||||||||||||||||||
210 | } | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | void ArrayData::ensureAttributes(Object *o) | - | ||||||||||||||||||
213 | { | - | ||||||||||||||||||
214 | if (o->arrayData() && o->arrayData()->attrs)
| 0-5987 | ||||||||||||||||||
215 | return; executed 2572 times by 1 test: return; Executed by:
| 2572 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | ArrayData::realloc(o, Heap::ArrayData::Simple, 0, true); | - | ||||||||||||||||||
218 | } executed 3415 times by 1 test: end of block Executed by:
| 3415 | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | ReturnedValue SimpleArrayData::get(const Heap::ArrayData *d, uint index) | - | ||||||||||||||||||
221 | { | - | ||||||||||||||||||
222 | const Heap::SimpleArrayData *dd = static_cast<const Heap::SimpleArrayData *>(d); | - | ||||||||||||||||||
223 | if (index >= dd->values.size)
| 8454-70340 | ||||||||||||||||||
224 | return Primitive::emptyValue().asReturnedValue(); executed 70338 times by 16 tests: return Primitive::emptyValue().asReturnedValue(); Executed by:
| 70338 | ||||||||||||||||||
225 | return dd->data(index).asReturnedValue(); executed 8454 times by 1 test: return dd->data(index).asReturnedValue(); Executed by:
| 8454 | ||||||||||||||||||
226 | } | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | bool SimpleArrayData::put(Object *o, uint index, const Value &value) | - | ||||||||||||||||||
229 | { | - | ||||||||||||||||||
230 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
231 | Q_ASSERT(index >= dd->values.size || !dd->attrs || !dd->attrs[index].isAccessor()); | - | ||||||||||||||||||
232 | // ### honour attributes | - | ||||||||||||||||||
233 | dd->setData(o->engine(), index, value); | - | ||||||||||||||||||
234 | if (index >= dd->values.size) {
| 0-21288 | ||||||||||||||||||
235 | if (dd->attrs)
| 0-21308 | ||||||||||||||||||
236 | dd->attrs[index] = Attr_Data; never executed: dd->attrs[index] = Attr_Data; | 0 | ||||||||||||||||||
237 | dd->values.size = index + 1; | - | ||||||||||||||||||
238 | } executed 21292 times by 19 tests: end of block Executed by:
| 21292 | ||||||||||||||||||
239 | return true; executed 21301 times by 19 tests: return true; Executed by:
| 21301 | ||||||||||||||||||
240 | } | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | bool SimpleArrayData::del(Object *o, uint index) | - | ||||||||||||||||||
243 | { | - | ||||||||||||||||||
244 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
245 | if (index >= dd->values.size)
| 16-1626 | ||||||||||||||||||
246 | return true; executed 16 times by 1 test: return true; Executed by:
| 16 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | if (!dd->attrs || dd->attrs[index].isConfigurable()) {
| 82-1202 | ||||||||||||||||||
249 | dd->setData(o->engine(), index, Primitive::emptyValue()); | - | ||||||||||||||||||
250 | if (dd->attrs)
| 82-1205 | ||||||||||||||||||
251 | dd->attrs[index] = Attr_Data; executed 82 times by 1 test: dd->attrs[index] = Attr_Data; Executed by:
| 82 | ||||||||||||||||||
252 | return true; executed 1285 times by 7 tests: return true; Executed by:
| 1285 | ||||||||||||||||||
253 | } | - | ||||||||||||||||||
254 | if (dd->data(index).isEmpty())
| 0-342 | ||||||||||||||||||
255 | return true; never executed: return true; | 0 | ||||||||||||||||||
256 | return false; executed 342 times by 1 test: return false; Executed by:
| 342 | ||||||||||||||||||
257 | } | - | ||||||||||||||||||
258 | - | |||||||||||||||||||
259 | void SimpleArrayData::setAttribute(Object *o, uint index, PropertyAttributes attrs) | - | ||||||||||||||||||
260 | { | - | ||||||||||||||||||
261 | o->arrayData()->attrs[index] = attrs; | - | ||||||||||||||||||
262 | } executed 866 times by 1 test: end of block Executed by:
| 866 | ||||||||||||||||||
263 | - | |||||||||||||||||||
264 | void SimpleArrayData::push_front(Object *o, const Value *values, uint n) | - | ||||||||||||||||||
265 | { | - | ||||||||||||||||||
266 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
267 | Q_ASSERT(!dd->attrs); | - | ||||||||||||||||||
268 | if (dd->values.size + n > dd->values.alloc) {
| 16-20060 | ||||||||||||||||||
269 | realloc(o, Heap::ArrayData::Simple, dd->values.size + n, false); | - | ||||||||||||||||||
270 | Q_ASSERT(o->d()->arrayData->type == Heap::ArrayData::Simple); | - | ||||||||||||||||||
271 | dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
272 | } executed 16 times by 3 tests: end of block Executed by:
| 16 | ||||||||||||||||||
273 | if (n <= dd->offset) {
| 54-20022 | ||||||||||||||||||
274 | dd->offset -= n; // there is enough space left in front | - | ||||||||||||||||||
275 | } else { executed 20022 times by 2 tests: end of block Executed by:
| 20022 | ||||||||||||||||||
276 | // we need to wrap around, so: | - | ||||||||||||||||||
277 | dd->offset = dd->values.alloc - // start at the back, but subtract: | - | ||||||||||||||||||
278 | (n - dd->offset); // the number of items we can put in the free space at the start of the allocated array | - | ||||||||||||||||||
279 | } executed 54 times by 4 tests: end of block Executed by:
| 54 | ||||||||||||||||||
280 | dd->values.size += n; | - | ||||||||||||||||||
281 | for (uint i = 0; i < n; ++i)
| 20052-20076 | ||||||||||||||||||
282 | dd->setData(o->engine(), i, values[i]); executed 20052 times by 4 tests: dd->setData(o->engine(), i, values[i]); Executed by:
| 20052 | ||||||||||||||||||
283 | } executed 20076 times by 4 tests: end of block Executed by:
| 20076 | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | ReturnedValue SimpleArrayData::pop_front(Object *o) | - | ||||||||||||||||||
286 | { | - | ||||||||||||||||||
287 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
288 | Q_ASSERT(!dd->attrs); | - | ||||||||||||||||||
289 | if (!dd->values.size)
| 8-122 | ||||||||||||||||||
290 | return Encode::undefined(); executed 8 times by 1 test: return Encode::undefined(); Executed by:
| 8 | ||||||||||||||||||
291 | - | |||||||||||||||||||
292 | ReturnedValue v = dd->data(0).isEmpty() ? Encode::undefined() : dd->data(0).asReturnedValue();
| 8-114 | ||||||||||||||||||
293 | dd->offset = (dd->offset + 1) % dd->values.alloc; | - | ||||||||||||||||||
294 | --dd->values.size; | - | ||||||||||||||||||
295 | return v; executed 122 times by 2 tests: return v; Executed by:
| 122 | ||||||||||||||||||
296 | } | - | ||||||||||||||||||
297 | - | |||||||||||||||||||
298 | uint SimpleArrayData::truncate(Object *o, uint newLen) | - | ||||||||||||||||||
299 | { | - | ||||||||||||||||||
300 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
301 | if (dd->values.size < newLen)
| 0-485 | ||||||||||||||||||
302 | return newLen; never executed: return newLen; | 0 | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | if (!dd->attrs) {
| 68-417 | ||||||||||||||||||
305 | dd->values.size = newLen; | - | ||||||||||||||||||
306 | return newLen; executed 417 times by 7 tests: return newLen; Executed by:
| 417 | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | while (dd->values.size > newLen) {
| 4-92 | ||||||||||||||||||
310 | if (!dd->data(dd->values.size - 1).isEmpty() && !dd->attrs[dd->values.size - 1].isConfigurable())
| 0-92 | ||||||||||||||||||
311 | return dd->values.size; executed 64 times by 1 test: return dd->values.size; Executed by:
| 64 | ||||||||||||||||||
312 | --dd->values.size; | - | ||||||||||||||||||
313 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||||||||
314 | return dd->values.size; executed 4 times by 1 test: return dd->values.size; Executed by:
| 4 | ||||||||||||||||||
315 | } | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | uint SimpleArrayData::length(const Heap::ArrayData *d) | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | return d->values.size; executed 270031 times by 17 tests: return d->values.size; Executed by:
| 270031 | ||||||||||||||||||
320 | } | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | bool SimpleArrayData::putArray(Object *o, uint index, const Value *values, uint n) | - | ||||||||||||||||||
323 | { | - | ||||||||||||||||||
324 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
325 | if (index + n > dd->values.alloc) {
| 5216-136023 | ||||||||||||||||||
326 | reallocate(o, index + n + 1, false); | - | ||||||||||||||||||
327 | dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
328 | } executed 5216 times by 8 tests: end of block Executed by:
| 5216 | ||||||||||||||||||
329 | QV4::ExecutionEngine *e = o->engine(); | - | ||||||||||||||||||
330 | for (uint i = dd->values.size; i < index; ++i)
| 0-141239 | ||||||||||||||||||
331 | dd->setData(e, i, Primitive::emptyValue()); never executed: dd->setData(e, i, Primitive::emptyValue()); | 0 | ||||||||||||||||||
332 | for (uint i = 0; i < n; ++i)
| 133485-141266 | ||||||||||||||||||
333 | dd->setData(e, index + i, values[i]); executed 133489 times by 17 tests: dd->setData(e, index + i, values[i]); Executed by:
| 133489 | ||||||||||||||||||
334 | dd->values.size = qMax(dd->values.size, index + n); | - | ||||||||||||||||||
335 | return true; executed 141253 times by 18 tests: return true; Executed by:
| 141253 | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | void SparseArrayData::free(Heap::ArrayData *d, uint idx) | - | ||||||||||||||||||
339 | { | - | ||||||||||||||||||
340 | Q_ASSERT(d && d->type == Heap::ArrayData::Sparse); | - | ||||||||||||||||||
341 | Value *v = d->values.values + idx; | - | ||||||||||||||||||
342 | if (d->attrs && d->attrs[idx].isAccessor()) {
| 8-885 | ||||||||||||||||||
343 | // double slot, free both. Order is important, so we have a double slot for allocation again afterwards. | - | ||||||||||||||||||
344 | v[1] = d->sparse->freeList; | - | ||||||||||||||||||
345 | v[0] = Encode(idx + 1); | - | ||||||||||||||||||
346 | } else { executed 186 times by 1 test: end of block Executed by:
| 186 | ||||||||||||||||||
347 | *v = d->sparse->freeList; | - | ||||||||||||||||||
348 | } executed 707 times by 1 test: end of block Executed by:
| 707 | ||||||||||||||||||
349 | d->sparse->freeList = Encode(idx); | - | ||||||||||||||||||
350 | if (d->attrs)
| 8-887 | ||||||||||||||||||
351 | d->attrs[idx].clear(); executed 887 times by 1 test: d->attrs[idx].clear(); Executed by:
| 887 | ||||||||||||||||||
352 | } executed 895 times by 1 test: end of block Executed by:
| 895 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | Heap::ArrayData *SparseArrayData::reallocate(Object *o, uint n, bool enforceAttributes) | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | realloc(o, Heap::ArrayData::Sparse, n, enforceAttributes); | - | ||||||||||||||||||
357 | return o->arrayData(); executed 2629 times by 1 test: return o->arrayData(); Executed by:
| 2629 | ||||||||||||||||||
358 | } | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | // double slots are required for accessor properties | - | ||||||||||||||||||
361 | uint SparseArrayData::allocate(Object *o, bool doubleSlot) | - | ||||||||||||||||||
362 | { | - | ||||||||||||||||||
363 | Q_ASSERT(o->d()->arrayData->type == Heap::ArrayData::Sparse); | - | ||||||||||||||||||
364 | Heap::SimpleArrayData *dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
365 | if (doubleSlot) {
| 835-3548 | ||||||||||||||||||
366 | Value *last = &dd->sparse->freeList; | - | ||||||||||||||||||
367 | while (1) { | - | ||||||||||||||||||
368 | if (last->int_32() == -1) {
| 1504-2579 | ||||||||||||||||||
369 | reallocate(o, dd->values.alloc + 2, true); | - | ||||||||||||||||||
370 | dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
371 | last = &dd->sparse->freeList; | - | ||||||||||||||||||
372 | Q_ASSERT(last->int_32() != -1); | - | ||||||||||||||||||
373 | } executed 2594 times by 1 test: end of block Executed by:
| 2594 | ||||||||||||||||||
374 | - | |||||||||||||||||||
375 | Q_ASSERT(dd->values[static_cast<uint>(last->int_32())].int_32() != last->int_32()); | - | ||||||||||||||||||
376 | if (dd->values[static_cast<uint>(last->int_32())].int_32() == last->int_32() + 1) {
| 536-3557 | ||||||||||||||||||
377 | // found two slots in a row | - | ||||||||||||||||||
378 | uint idx = static_cast<uint>(last->int_32()); | - | ||||||||||||||||||
379 | *last = Encode(dd->values[static_cast<uint>(last->int_32()) + 1].int_32()); | - | ||||||||||||||||||
380 | dd->attrs[idx] = Attr_Accessor; | - | ||||||||||||||||||
381 | return idx; executed 3549 times by 1 test: return idx; Executed by:
| 3549 | ||||||||||||||||||
382 | } | - | ||||||||||||||||||
383 | last = &dd->values.values[last->int_32()]; | - | ||||||||||||||||||
384 | } executed 536 times by 1 test: end of block Executed by:
| 536 | ||||||||||||||||||
385 | } else { never executed: end of block | 0 | ||||||||||||||||||
386 | if (dd->sparse->freeList.int_32() == -1) {
| 8-827 | ||||||||||||||||||
387 | reallocate(o, dd->values.alloc + 1, false); | - | ||||||||||||||||||
388 | dd = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
389 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
390 | Q_ASSERT(dd->sparse->freeList.int_32() != -1); | - | ||||||||||||||||||
391 | uint idx = static_cast<uint>(dd->sparse->freeList.int_32()); | - | ||||||||||||||||||
392 | dd->sparse->freeList = dd->values[idx]; | - | ||||||||||||||||||
393 | Q_ASSERT(dd->sparse->freeList.isInteger()); | - | ||||||||||||||||||
394 | if (dd->attrs)
| 232-604 | ||||||||||||||||||
395 | dd->attrs[idx] = Attr_Data; executed 604 times by 1 test: dd->attrs[idx] = Attr_Data; Executed by:
| 604 | ||||||||||||||||||
396 | return idx; executed 836 times by 2 tests: return idx; Executed by:
| 836 | ||||||||||||||||||
397 | } | - | ||||||||||||||||||
398 | } | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | ReturnedValue SparseArrayData::get(const Heap::ArrayData *d, uint index) | - | ||||||||||||||||||
401 | { | - | ||||||||||||||||||
402 | const Heap::SparseArrayData *s = static_cast<const Heap::SparseArrayData *>(d); | - | ||||||||||||||||||
403 | index = s->mappedIndex(index); | - | ||||||||||||||||||
404 | if (index == UINT_MAX)
| 94-295 | ||||||||||||||||||
405 | return Primitive::emptyValue().asReturnedValue(); executed 94 times by 1 test: return Primitive::emptyValue().asReturnedValue(); Executed by:
| 94 | ||||||||||||||||||
406 | return s->values[index].asReturnedValue(); executed 296 times by 1 test: return s->values[index].asReturnedValue(); Executed by:
| 296 | ||||||||||||||||||
407 | } | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | bool SparseArrayData::put(Object *o, uint index, const Value &value) | - | ||||||||||||||||||
410 | { | - | ||||||||||||||||||
411 | if (value.isEmpty())
| 0-334 | ||||||||||||||||||
412 | return true; never executed: return true; | 0 | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | Heap::SparseArrayData *s = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
415 | SparseArrayNode *n = s->sparse->insert(index); | - | ||||||||||||||||||
416 | Q_ASSERT(n->value == UINT_MAX || !s->attrs || !s->attrs[n->value].isAccessor()); | - | ||||||||||||||||||
417 | if (n->value == UINT_MAX)
| 0-334 | ||||||||||||||||||
418 | n->value = allocate(o); executed 334 times by 1 test: n->value = allocate(o); Executed by:
| 334 | ||||||||||||||||||
419 | s = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
420 | s->setArrayData(o->engine(), n->value, value); | - | ||||||||||||||||||
421 | if (s->attrs)
| 0-334 | ||||||||||||||||||
422 | s->attrs[n->value] = Attr_Data; executed 334 times by 1 test: s->attrs[n->value] = Attr_Data; Executed by:
| 334 | ||||||||||||||||||
423 | return true; executed 334 times by 1 test: return true; Executed by:
| 334 | ||||||||||||||||||
424 | } | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | bool SparseArrayData::del(Object *o, uint index) | - | ||||||||||||||||||
427 | { | - | ||||||||||||||||||
428 | Heap::SparseArrayData *dd = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | SparseArrayNode *n = dd->sparse->findNode(index); | - | ||||||||||||||||||
431 | if (!n)
| 4-764 | ||||||||||||||||||
432 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
433 | - | |||||||||||||||||||
434 | uint pidx = n->value; | - | ||||||||||||||||||
435 | Q_ASSERT(!dd->values[pidx].isEmpty()); | - | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | bool isAccessor = false; | - | ||||||||||||||||||
438 | if (dd->attrs) {
| 4-759 | ||||||||||||||||||
439 | if (!dd->attrs[pidx].isConfigurable())
| 362-400 | ||||||||||||||||||
440 | return false; executed 359 times by 1 test: return false; Executed by:
| 359 | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | isAccessor = dd->attrs[pidx].isAccessor(); | - | ||||||||||||||||||
443 | dd->attrs[pidx] = Attr_Data; | - | ||||||||||||||||||
444 | } executed 403 times by 1 test: end of block Executed by:
| 403 | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | if (isAccessor) {
| 154-253 | ||||||||||||||||||
447 | // free up both indices | - | ||||||||||||||||||
448 | dd->values.values[pidx + 1] = dd->sparse->freeList; | - | ||||||||||||||||||
449 | dd->values.values[pidx] = Encode(pidx + 1); | - | ||||||||||||||||||
450 | } else { executed 252 times by 1 test: end of block Executed by:
| 252 | ||||||||||||||||||
451 | Q_ASSERT(dd->type == Heap::ArrayData::Sparse); | - | ||||||||||||||||||
452 | dd->values.values[pidx] = dd->sparse->freeList; | - | ||||||||||||||||||
453 | } executed 154 times by 2 tests: end of block Executed by:
| 154 | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | dd->sparse->freeList = Encode(pidx); | - | ||||||||||||||||||
456 | dd->sparse->erase(n); | - | ||||||||||||||||||
457 | return true; executed 405 times by 2 tests: return true; Executed by:
| 405 | ||||||||||||||||||
458 | } | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | void SparseArrayData::setAttribute(Object *o, uint index, PropertyAttributes attrs) | - | ||||||||||||||||||
461 | { | - | ||||||||||||||||||
462 | Heap::SparseArrayData *d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
463 | SparseArrayNode *n = d->sparse->insert(index); | - | ||||||||||||||||||
464 | if (n->value == UINT_MAX) {
| 2037-3034 | ||||||||||||||||||
465 | n->value = allocate(o, attrs.isAccessor()); | - | ||||||||||||||||||
466 | d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
467 | } executed 3038 times by 1 test: end of block Executed by:
| 3038 | ||||||||||||||||||
468 | else if (attrs.isAccessor() != d->attrs[n->value].isAccessor()) {
| 699-1332 | ||||||||||||||||||
469 | // need to convert the slot | - | ||||||||||||||||||
470 | free(o->arrayData(), n->value); | - | ||||||||||||||||||
471 | n->value = allocate(o, attrs.isAccessor()); | - | ||||||||||||||||||
472 | d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
473 | } executed 700 times by 1 test: end of block Executed by:
| 700 | ||||||||||||||||||
474 | d->attrs[n->value] = attrs; | - | ||||||||||||||||||
475 | } executed 5071 times by 1 test: end of block Executed by:
| 5071 | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | void SparseArrayData::push_front(Object *o, const Value *values, uint n) | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | Heap::SparseArrayData *d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
480 | Q_ASSERT(!d->attrs); | - | ||||||||||||||||||
481 | for (int i = static_cast<int>(n) - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||
482 | uint idx = allocate(o); | - | ||||||||||||||||||
483 | d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
484 | d->setArrayData(o->engine(), idx, values[i]); | - | ||||||||||||||||||
485 | d->sparse->push_front(idx); | - | ||||||||||||||||||
486 | } never executed: end of block | 0 | ||||||||||||||||||
487 | } never executed: end of block | 0 | ||||||||||||||||||
488 | - | |||||||||||||||||||
489 | ReturnedValue SparseArrayData::pop_front(Object *o) | - | ||||||||||||||||||
490 | { | - | ||||||||||||||||||
491 | Heap::SparseArrayData *d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
492 | Q_ASSERT(!d->attrs); | - | ||||||||||||||||||
493 | uint idx = d->sparse->pop_front(); | - | ||||||||||||||||||
494 | ReturnedValue v; | - | ||||||||||||||||||
495 | if (idx != UINT_MAX) {
| 0 | ||||||||||||||||||
496 | v = d->values[idx].asReturnedValue(); | - | ||||||||||||||||||
497 | free(o->arrayData(), idx); | - | ||||||||||||||||||
498 | } else { never executed: end of block | 0 | ||||||||||||||||||
499 | v = Encode::undefined(); | - | ||||||||||||||||||
500 | } never executed: end of block | 0 | ||||||||||||||||||
501 | return v; never executed: return v; | 0 | ||||||||||||||||||
502 | } | - | ||||||||||||||||||
503 | - | |||||||||||||||||||
504 | uint SparseArrayData::truncate(Object *o, uint newLen) | - | ||||||||||||||||||
505 | { | - | ||||||||||||||||||
506 | Heap::SparseArrayData *d = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
507 | SparseArrayNode *begin = d->sparse->lowerBound(newLen); | - | ||||||||||||||||||
508 | if (begin != d->sparse->end()) {
| 0-158 | ||||||||||||||||||
509 | SparseArrayNode *it = d->sparse->end()->previousNode(); | - | ||||||||||||||||||
510 | while (1) { | - | ||||||||||||||||||
511 | if (d->attrs) {
| 8-232 | ||||||||||||||||||
512 | if (!d->attrs[it->value].isConfigurable()) {
| 46-186 | ||||||||||||||||||
513 | newLen = it->key() + 1; | - | ||||||||||||||||||
514 | break; executed 46 times by 1 test: break; Executed by:
| 46 | ||||||||||||||||||
515 | } | - | ||||||||||||||||||
516 | } executed 186 times by 1 test: end of block Executed by:
| 186 | ||||||||||||||||||
517 | free(o->arrayData(), it->value); | - | ||||||||||||||||||
518 | bool brk = (it == begin); | - | ||||||||||||||||||
519 | SparseArrayNode *prev = it->previousNode(); | - | ||||||||||||||||||
520 | d->sparse->erase(it); | - | ||||||||||||||||||
521 | if (brk)
| 82-112 | ||||||||||||||||||
522 | break; executed 112 times by 1 test: break; Executed by:
| 112 | ||||||||||||||||||
523 | it = prev; | - | ||||||||||||||||||
524 | } executed 82 times by 1 test: end of block Executed by:
| 82 | ||||||||||||||||||
525 | } executed 158 times by 1 test: end of block Executed by:
| 158 | ||||||||||||||||||
526 | return newLen; executed 158 times by 1 test: return newLen; Executed by:
| 158 | ||||||||||||||||||
527 | } | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | uint SparseArrayData::length(const Heap::ArrayData *d) | - | ||||||||||||||||||
530 | { | - | ||||||||||||||||||
531 | const Heap::SparseArrayData *dd = static_cast<const Heap::SparseArrayData *>(d); | - | ||||||||||||||||||
532 | if (!dd->sparse)
| 0-10 | ||||||||||||||||||
533 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
534 | SparseArrayNode *n = dd->sparse->end(); | - | ||||||||||||||||||
535 | n = n->previousNode(); | - | ||||||||||||||||||
536 | return n ? n->key() + 1 : 0; executed 10 times by 1 test: return n ? n->key() + 1 : 0; Executed by:
| 10 | ||||||||||||||||||
537 | } | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | bool SparseArrayData::putArray(Object *o, uint index, const Value *values, uint n) | - | ||||||||||||||||||
540 | { | - | ||||||||||||||||||
541 | for (uint i = 0; i < n; ++i)
| 334-450 | ||||||||||||||||||
542 | put(o, index + i, values[i]); executed 334 times by 1 test: put(o, index + i, values[i]); Executed by:
| 334 | ||||||||||||||||||
543 | return true; executed 450 times by 1 test: return true; Executed by:
| 450 | ||||||||||||||||||
544 | } | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | - | |||||||||||||||||||
547 | uint ArrayData::append(Object *obj, ArrayObject *otherObj, uint n) | - | ||||||||||||||||||
548 | { | - | ||||||||||||||||||
549 | Q_ASSERT(!obj->d()->arrayData || !obj->d()->arrayData->attrs); | - | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | if (!n)
| 8-58 | ||||||||||||||||||
552 | return obj->getLength(); executed 8 times by 1 test: return obj->getLength(); Executed by:
| 8 | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | Scope scope(obj->engine()); | - | ||||||||||||||||||
555 | Scoped<ArrayData> other(scope, otherObj->arrayData()); | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | if (other && other->isSparse())
| 0-58 | ||||||||||||||||||
558 | obj->initSparseArray(); never executed: obj->initSparseArray(); | 0 | ||||||||||||||||||
559 | else | - | ||||||||||||||||||
560 | obj->arrayCreate(); executed 58 times by 2 tests: obj->arrayCreate(); Executed by:
| 58 | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | uint oldSize = obj->getLength(); | - | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | if (!other || ArgumentsObject::isNonStrictArgumentsObject(otherObj)) {
| 0-58 | ||||||||||||||||||
565 | ScopedValue v(scope); | - | ||||||||||||||||||
566 | for (uint i = 0; i < n; ++i)
| 0 | ||||||||||||||||||
567 | obj->arraySet(oldSize + i, (v = otherObj->get(i))); never executed: obj->arraySet(oldSize + i, (v = otherObj->get(i))); | 0 | ||||||||||||||||||
568 | } else if (other && other->isSparse()) { never executed: end of block
| 0-58 | ||||||||||||||||||
569 | Heap::SparseArrayData *os = static_cast<Heap::SparseArrayData *>(other->d()); | - | ||||||||||||||||||
570 | if (other->hasAttributes()) {
| 0 | ||||||||||||||||||
571 | ScopedValue v(scope); | - | ||||||||||||||||||
572 | for (const SparseArrayNode *it = os->sparse->begin(); | - | ||||||||||||||||||
573 | it != os->sparse->end(); it = it->nextNode()) {
| 0 | ||||||||||||||||||
574 | v = otherObj->getValue(os->values[it->value], other->d()->attrs[it->value]); | - | ||||||||||||||||||
575 | obj->arraySet(oldSize + it->key(), v); | - | ||||||||||||||||||
576 | } never executed: end of block | 0 | ||||||||||||||||||
577 | } else { never executed: end of block | 0 | ||||||||||||||||||
578 | for (const SparseArrayNode *it = other->d()->sparse->begin(); | - | ||||||||||||||||||
579 | it != os->sparse->end(); it = it->nextNode())
| 0 | ||||||||||||||||||
580 | obj->arraySet(oldSize + it->key(), os->values[it->value]); never executed: obj->arraySet(oldSize + it->key(), os->values[it->value]); | 0 | ||||||||||||||||||
581 | } never executed: end of block | 0 | ||||||||||||||||||
582 | } else { | - | ||||||||||||||||||
583 | Heap::SimpleArrayData *os = static_cast<Heap::SimpleArrayData *>(other->d()); | - | ||||||||||||||||||
584 | uint toCopy = n; | - | ||||||||||||||||||
585 | uint chunk = toCopy; | - | ||||||||||||||||||
586 | if (chunk > os->values.alloc - os->offset)
| 0-58 | ||||||||||||||||||
587 | chunk = os->values.alloc - os->offset; never executed: chunk = os->values.alloc - os->offset; | 0 | ||||||||||||||||||
588 | obj->arrayPut(oldSize, os->values.data() + os->offset, chunk); | - | ||||||||||||||||||
589 | toCopy -= chunk; | - | ||||||||||||||||||
590 | if (toCopy)
| 0-58 | ||||||||||||||||||
591 | obj->arrayPut(oldSize + chunk, os->values.data(), toCopy); never executed: obj->arrayPut(oldSize + chunk, os->values.data(), toCopy); | 0 | ||||||||||||||||||
592 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | return oldSize + n; executed 58 times by 2 tests: return oldSize + n; Executed by:
| 58 | ||||||||||||||||||
595 | } | - | ||||||||||||||||||
596 | - | |||||||||||||||||||
597 | void ArrayData::insert(Object *o, uint index, const Value *v, bool isAccessor) | - | ||||||||||||||||||
598 | { | - | ||||||||||||||||||
599 | if (!isAccessor && o->d()->arrayData->type != Heap::ArrayData::Sparse) {
| 348-49578 | ||||||||||||||||||
600 | Heap::SimpleArrayData *d = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
601 | if (index < 0x1000 || index < d->values.size + (d->values.size >> 2)) {
| 0-49283 | ||||||||||||||||||
602 | if (index >= d->values.alloc) {
| 794-48445 | ||||||||||||||||||
603 | o->arrayReserve(index + 1); | - | ||||||||||||||||||
604 | d = o->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
605 | } executed 790 times by 7 tests: end of block Executed by:
| 790 | ||||||||||||||||||
606 | if (index >= d->values.size) {
| 148-49088 | ||||||||||||||||||
607 | // mark possible hole in the array | - | ||||||||||||||||||
608 | for (uint i = d->values.size; i < index; ++i)
| 49132-68222 | ||||||||||||||||||
609 | d->setData(o->engine(), i, Primitive::emptyValue()); executed 68216 times by 6 tests: d->setData(o->engine(), i, Primitive::emptyValue()); Executed by:
| 68216 | ||||||||||||||||||
610 | d->values.size = index + 1; | - | ||||||||||||||||||
611 | } executed 49106 times by 31 tests: end of block Executed by:
| 49106 | ||||||||||||||||||
612 | d->setData(o->engine(), index, *v); | - | ||||||||||||||||||
613 | return; executed 49260 times by 31 tests: return; Executed by:
| 49260 | ||||||||||||||||||
614 | } | - | ||||||||||||||||||
615 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | o->initSparseArray(); | - | ||||||||||||||||||
618 | Heap::SparseArrayData *s = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
619 | SparseArrayNode *n = s->sparse->insert(index); | - | ||||||||||||||||||
620 | if (n->value == UINT_MAX)
| 308-3047 | ||||||||||||||||||
621 | n->value = SparseArrayData::allocate(o, isAccessor); executed 308 times by 2 tests: n->value = SparseArrayData::allocate(o, isAccessor); Executed by:
| 308 | ||||||||||||||||||
622 | s = o->d()->arrayData.cast<Heap::SparseArrayData>(); | - | ||||||||||||||||||
623 | s->setArrayData(o->engine(), n->value, *v); | - | ||||||||||||||||||
624 | if (isAccessor)
| 356-3003 | ||||||||||||||||||
625 | s->setArrayData(o->engine(), n->value + Object::SetterOffset, v[Object::SetterOffset]); executed 2992 times by 1 test: s->setArrayData(o->engine(), n->value + Object::SetterOffset, v[Object::SetterOffset]); Executed by:
| 2992 | ||||||||||||||||||
626 | } executed 3347 times by 2 tests: end of block Executed by:
| 3347 | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | - | |||||||||||||||||||
629 | class ArrayElementLessThan | - | ||||||||||||||||||
630 | { | - | ||||||||||||||||||
631 | public: | - | ||||||||||||||||||
632 | inline ArrayElementLessThan(ExecutionEngine *engine, const Value &comparefn) | - | ||||||||||||||||||
633 | : m_engine(engine), m_comparefn(comparefn) {} executed 176 times by 6 tests: end of block Executed by:
| 176 | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | bool operator()(Value v1, Value v2) const; | - | ||||||||||||||||||
636 | - | |||||||||||||||||||
637 | private: | - | ||||||||||||||||||
638 | ExecutionEngine *m_engine; | - | ||||||||||||||||||
639 | const Value &m_comparefn; | - | ||||||||||||||||||
640 | }; | - | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | - | |||||||||||||||||||
643 | bool ArrayElementLessThan::operator()(Value v1, Value v2) const | - | ||||||||||||||||||
644 | { | - | ||||||||||||||||||
645 | Scope scope(m_engine); | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | if (v1.isUndefined() || v1.isEmpty())
| 0-9020 | ||||||||||||||||||
648 | return false; executed 64 times by 1 test: return false; Executed by:
| 64 | ||||||||||||||||||
649 | if (v2.isUndefined() || v2.isEmpty())
| 0-8972 | ||||||||||||||||||
650 | return true; executed 48 times by 1 test: return true; Executed by:
| 48 | ||||||||||||||||||
651 | ScopedFunctionObject o(scope, m_comparefn); | - | ||||||||||||||||||
652 | if (o) {
| 3248-5724 | ||||||||||||||||||
653 | Scope scope(o->engine()); | - | ||||||||||||||||||
654 | ScopedValue result(scope); | - | ||||||||||||||||||
655 | JSCallData jsCallData(scope, 2); | - | ||||||||||||||||||
656 | jsCallData->args[0] = v1; | - | ||||||||||||||||||
657 | jsCallData->args[1] = v2; | - | ||||||||||||||||||
658 | result = o->call(jsCallData); | - | ||||||||||||||||||
659 | - | |||||||||||||||||||
660 | return result->toNumber() < 0; executed 5724 times by 3 tests: return result->toNumber() < 0; Executed by:
| 5724 | ||||||||||||||||||
661 | } | - | ||||||||||||||||||
662 | ScopedString p1s(scope, v1.toString(scope.engine)); | - | ||||||||||||||||||
663 | ScopedString p2s(scope, v2.toString(scope.engine)); | - | ||||||||||||||||||
664 | return p1s->toQString() < p2s->toQString(); executed 3248 times by 4 tests: return p1s->toQString() < p2s->toQString(); Executed by:
| 3248 | ||||||||||||||||||
665 | } | - | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | template <typename RandomAccessIterator, typename T, typename LessThan> | - | ||||||||||||||||||
668 | void sortHelper(RandomAccessIterator start, RandomAccessIterator end, const T &t, LessThan lessThan) | - | ||||||||||||||||||
669 | { | - | ||||||||||||||||||
670 | top: | - | ||||||||||||||||||
671 | int span = int(end - start); | - | ||||||||||||||||||
672 | if (span < 2)
| 254-990 | ||||||||||||||||||
673 | return; executed 254 times by 5 tests: return; Executed by:
| 254 | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | --end; | - | ||||||||||||||||||
676 | RandomAccessIterator low = start, high = end - 1; | - | ||||||||||||||||||
677 | RandomAccessIterator pivot = start + span / 2; | - | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | if (lessThan(*end, *start))
| 424-566 | ||||||||||||||||||
680 | qSwap(*end, *start); executed 424 times by 5 tests: qSwap(*end, *start); Executed by:
| 424 | ||||||||||||||||||
681 | if (span == 2)
| 274-716 | ||||||||||||||||||
682 | return; executed 274 times by 3 tests: return; Executed by:
| 274 | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | if (lessThan(*pivot, *start))
| 254-462 | ||||||||||||||||||
685 | qSwap(*pivot, *start); executed 254 times by 5 tests: qSwap(*pivot, *start); Executed by:
| 254 | ||||||||||||||||||
686 | if (lessThan(*end, *pivot))
| 196-520 | ||||||||||||||||||
687 | qSwap(*end, *pivot); executed 196 times by 4 tests: qSwap(*end, *pivot); Executed by:
| 196 | ||||||||||||||||||
688 | if (span == 3)
| 182-534 | ||||||||||||||||||
689 | return; executed 182 times by 5 tests: return; Executed by:
| 182 | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | qSwap(*pivot, *end); | - | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | while (low < high) {
| 146-1072 | ||||||||||||||||||
694 | while (low < high && lessThan(*low, *end))
| 154-4636 | ||||||||||||||||||
695 | ++low; executed 3718 times by 4 tests: ++low; Executed by:
| 3718 | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | while (high > low && lessThan(*end, *high))
| 388-1492 | ||||||||||||||||||
698 | --high; executed 808 times by 3 tests: --high; Executed by:
| 808 | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | if (low < high) {
| 388-684 | ||||||||||||||||||
701 | qSwap(*low, *high); | - | ||||||||||||||||||
702 | ++low; | - | ||||||||||||||||||
703 | --high; | - | ||||||||||||||||||
704 | } else { executed 684 times by 3 tests: end of block Executed by:
| 684 | ||||||||||||||||||
705 | break; executed 388 times by 4 tests: break; Executed by:
| 388 | ||||||||||||||||||
706 | } | - | ||||||||||||||||||
707 | } | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | if (lessThan(*low, *end))
| 114-420 | ||||||||||||||||||
710 | ++low; executed 114 times by 2 tests: ++low; Executed by:
| 114 | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | qSwap(*end, *low); | - | ||||||||||||||||||
713 | sortHelper(start, low, t, lessThan); | - | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | start = low + 1; | - | ||||||||||||||||||
716 | ++end; | - | ||||||||||||||||||
717 | goto top; executed 534 times by 4 tests: goto top; Executed by:
| 534 | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | - | |||||||||||||||||||
721 | void ArrayData::sort(ExecutionEngine *engine, Object *thisObject, const Value &comparefn, uint len) | - | ||||||||||||||||||
722 | { | - | ||||||||||||||||||
723 | if (!len)
| 10-184 | ||||||||||||||||||
724 | return; executed 10 times by 2 tests: return; Executed by:
| 10 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | Scope scope(engine); | - | ||||||||||||||||||
727 | Scoped<ArrayData> arrayData(scope, thisObject->arrayData()); | - | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | if (!arrayData || !arrayData->length())
| 0-184 | ||||||||||||||||||
730 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | if (!comparefn.isUndefined() && !comparefn.isFunctionObject()) {
| 4-112 | ||||||||||||||||||
733 | engine->throwTypeError(); | - | ||||||||||||||||||
734 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
735 | } | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | // The spec says the sorting goes through a series of get,put and delete operations. | - | ||||||||||||||||||
738 | // this implies that the attributes don't get sorted around. | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | if (arrayData->type() == Heap::ArrayData::Sparse) {
| 0-176 | ||||||||||||||||||
741 | // since we sort anyway, we can simply iterate over the entries in the sparse | - | ||||||||||||||||||
742 | // array and append them one by one to a regular one. | - | ||||||||||||||||||
743 | Scoped<SparseArrayData> sparse(scope, static_cast<Heap::SparseArrayData *>(arrayData->d())); | - | ||||||||||||||||||
744 | - | |||||||||||||||||||
745 | if (!sparse->sparse()->nEntries())
| 0 | ||||||||||||||||||
746 | return; never executed: return; | 0 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | thisObject->setArrayData(nullptr); | - | ||||||||||||||||||
749 | ArrayData::realloc(thisObject, Heap::ArrayData::Simple, sparse->sparse()->nEntries(), sparse->attrs() ? true : false); | - | ||||||||||||||||||
750 | Heap::SimpleArrayData *d = thisObject->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | SparseArrayNode *n = sparse->sparse()->begin(); | - | ||||||||||||||||||
753 | uint i = 0; | - | ||||||||||||||||||
754 | if (sparse->attrs()) {
| 0 | ||||||||||||||||||
755 | while (n != sparse->sparse()->end()) {
| 0 | ||||||||||||||||||
756 | if (n->value >= len)
| 0 | ||||||||||||||||||
757 | break; never executed: break; | 0 | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | PropertyAttributes a = sparse->attrs() ? sparse->attrs()[n->value] : Attr_Data;
| 0 | ||||||||||||||||||
760 | d->setData(engine, i, Value::fromReturnedValue(thisObject->getValue(sparse->arrayData()[n->value], a))); | - | ||||||||||||||||||
761 | d->attrs[i] = a.isAccessor() ? Attr_Data : a;
| 0 | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | n = n->nextNode(); | - | ||||||||||||||||||
764 | ++i; | - | ||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||
766 | } else { never executed: end of block | 0 | ||||||||||||||||||
767 | while (n != sparse->sparse()->end()) {
| 0 | ||||||||||||||||||
768 | if (n->value >= len)
| 0 | ||||||||||||||||||
769 | break; never executed: break; | 0 | ||||||||||||||||||
770 | d->setData(engine, i, sparse->arrayData()[n->value]); | - | ||||||||||||||||||
771 | n = n->nextNode(); | - | ||||||||||||||||||
772 | ++i; | - | ||||||||||||||||||
773 | } never executed: end of block | 0 | ||||||||||||||||||
774 | } never executed: end of block | 0 | ||||||||||||||||||
775 | d->values.size = i; | - | ||||||||||||||||||
776 | if (len > i)
| 0 | ||||||||||||||||||
777 | len = i; never executed: len = i; | 0 | ||||||||||||||||||
778 | if (n != sparse->sparse()->end()) {
| 0 | ||||||||||||||||||
779 | // have some entries outside the sort range that we need to ignore when sorting | - | ||||||||||||||||||
780 | thisObject->initSparseArray(); | - | ||||||||||||||||||
781 | while (n != sparse->sparse()->end()) {
| 0 | ||||||||||||||||||
782 | PropertyAttributes a = sparse->attrs() ? sparse->attrs()[n->value] : Attr_Data;
| 0 | ||||||||||||||||||
783 | thisObject->arraySet(n->value, reinterpret_cast<const Property *>(sparse->arrayData() + n->value), a); | - | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | n = n->nextNode(); | - | ||||||||||||||||||
786 | } never executed: end of block | 0 | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | } never executed: end of block | 0 | ||||||||||||||||||
789 | } else { never executed: end of block | 0 | ||||||||||||||||||
790 | Heap::SimpleArrayData *d = thisObject->d()->arrayData.cast<Heap::SimpleArrayData>(); | - | ||||||||||||||||||
791 | if (len > d->values.size)
| 8-168 | ||||||||||||||||||
792 | len = d->values.size; executed 8 times by 1 test: len = d->values.size; Executed by:
| 8 | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | // sort empty values to the end | - | ||||||||||||||||||
795 | for (uint i = 0; i < len; i++) {
| 176-1784 | ||||||||||||||||||
796 | if (d->data(i).isEmpty()) {
| 12-1772 | ||||||||||||||||||
797 | while (--len > i)
| 0-12 | ||||||||||||||||||
798 | if (!d->data(len).isEmpty())
| 0-12 | ||||||||||||||||||
799 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||
800 | Q_ASSERT(!d->attrs || !d->attrs[len].isAccessor()); | - | ||||||||||||||||||
801 | d->setData(engine, i, d->data(len)); | - | ||||||||||||||||||
802 | d->setData(engine, len, Primitive::emptyValue()); | - | ||||||||||||||||||
803 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
804 | } executed 1784 times by 6 tests: end of block Executed by:
| 1784 | ||||||||||||||||||
805 | - | |||||||||||||||||||
806 | if (!len)
| 0-176 | ||||||||||||||||||
807 | return; never executed: return; | 0 | ||||||||||||||||||
808 | } executed 176 times by 6 tests: end of block Executed by:
| 176 | ||||||||||||||||||
809 | - | |||||||||||||||||||
810 | - | |||||||||||||||||||
811 | ArrayElementLessThan lessThan(engine, static_cast<const FunctionObject &>(comparefn)); | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | Value *begin = thisObject->arrayData()->values.values; | - | ||||||||||||||||||
814 | sortHelper(begin, begin + len, *begin, lessThan); | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | #ifdef CHECK_SPARSE_ARRAYS | - | ||||||||||||||||||
817 | thisObject->initSparseArray(); | - | ||||||||||||||||||
818 | #endif | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | } executed 176 times by 6 tests: end of block Executed by:
| 176 | ||||||||||||||||||
Source code | Switch to Preprocessed file |