OpenCoverage

qv4estable.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4estable.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2018 Crimson AS <info@crimson.no>-
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 "qv4estable_p.h"-
41-
42using namespace QV4;-
43-
44// The ES spec requires that Map/Set be implemented using a data structure that-
45// is a little different from most; it requires nonlinear access, and must also-
46// preserve the order of insertion of items in a deterministic way.-
47//-
48// This class implements those requirements, except for fast access: that-
49// will be addressed in a followup patch.-
50-
51ESTable::ESTable()-
52 : m_capacity(8)-
53{-
54 m_keys = (Value*)malloc(m_capacity * sizeof(Value));-
55 m_values = (Value*)malloc(m_capacity * sizeof(Value));-
56 memset(m_keys, 0, m_capacity);-
57 memset(m_values, 0, m_capacity);-
58}
executed 1188 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
1188
59-
60ESTable::~ESTable()-
61{-
62 free(m_keys);-
63 free(m_values);-
64 m_size = 0;-
65 m_capacity = 0;-
66 m_keys = nullptr;-
67 m_values = nullptr;-
68}
executed 1198 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
1198
69-
70void ESTable::markObjects(MarkStack *s)-
71{-
72 for (uint i = 0; i < m_size; ++i) {
i < m_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
73 m_keys[i].mark(s);-
74 m_values[i].mark(s);-
75 }
never executed: end of block
0
76}
never executed: end of block
0
77-
78// Pretends that there's nothing in the table. Doesn't actually free memory, as-
79// it will almost certainly be reused again anyway.-
80void ESTable::clear()-
81{-
82 m_size = 0;-
83}
executed 52 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
52
84-
85// Update the table to contain \a value for a given \a key. The key is-
86// normalized, as required by the ES spec.-
87void ESTable::set(const Value &key, const Value &value)-
88{-
89 for (uint i = 0; i < m_size; ++i) {
i < m_sizeDescription
TRUEevaluated 1208 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 901 times by 1 test
Evaluated by:
  • tst_ecmascripttests
901-1208
90 if (m_keys[i].sameValueZero(key)) {
m_keys[i].sameValueZero(key)Description
TRUEevaluated 44 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 1163 times by 1 test
Evaluated by:
  • tst_ecmascripttests
44-1163
91 m_values[i] = value;-
92 return;
executed 44 times by 1 test: return;
Executed by:
  • tst_ecmascripttests
44
93 }-
94 }
executed 1163 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
1163
95-
96 if (m_capacity == m_size) {
m_capacity == m_sizeDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 898 times by 1 test
Evaluated by:
  • tst_ecmascripttests
4-898
97 uint oldCap = m_capacity;-
98 m_capacity *= 2;-
99 m_keys = (Value*)realloc(m_keys, m_capacity * sizeof(Value));-
100 m_values = (Value*)realloc(m_values, m_capacity * sizeof(Value));-
101 memset(m_keys + oldCap, 0, m_capacity - oldCap);-
102 memset(m_values + oldCap, 0, m_capacity - oldCap);-
103 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
4
104-
105 Value nk = key;-
106 if (nk.isDouble()) {
nk.isDouble()Description
TRUEevaluated 56 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 849 times by 1 test
Evaluated by:
  • tst_ecmascripttests
56-849
107 if (nk.doubleValue() == 0 && std::signbit(nk.doubleValue()))
nk.doubleValue() == 0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 32 times by 1 test
Evaluated by:
  • tst_ecmascripttests
std::signbit(nk.doubleValue())Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEnever evaluated
0-32
108 nk = Primitive::fromDouble(+0);
executed 24 times by 1 test: nk = Primitive::fromDouble(+0);
Executed by:
  • tst_ecmascripttests
24
109 }
executed 56 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
56
110-
111 m_keys[m_size] = nk;-
112 m_values[m_size] = value;-
113-
114 m_size++;-
115}
executed 904 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
904
116-
117// Returns true if the table contains \a key, false otherwise.-
118bool ESTable::has(const Value &key) const-
119{-
120 for (uint i = 0; i < m_size; ++i) {
i < m_sizeDescription
TRUEevaluated 276 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 104 times by 1 test
Evaluated by:
  • tst_ecmascripttests
104-276
121 if (m_keys[i].sameValueZero(key))
m_keys[i].sameValueZero(key)Description
TRUEevaluated 95 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 180 times by 1 test
Evaluated by:
  • tst_ecmascripttests
95-180
122 return true;
executed 95 times by 1 test: return true;
Executed by:
  • tst_ecmascripttests
95
123 }
executed 180 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
180
124-
125 return false;
executed 104 times by 1 test: return false;
Executed by:
  • tst_ecmascripttests
104
126}-
127-
128// Fetches the value for the given \a key, and if \a hasValue is passed in,-
129// it is set depending on whether or not the given key was found.-
130ReturnedValue ESTable::get(const Value &key, bool *hasValue) const-
131{-
132 for (uint i = 0; i < m_size; ++i) {
i < m_sizeDescription
TRUEevaluated 180 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_ecmascripttests
12-180
133 if (m_keys[i].sameValueZero(key)) {
m_keys[i].sameValueZero(key)Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 116 times by 1 test
Evaluated by:
  • tst_ecmascripttests
64-116
134 if (hasValue)
hasValueDescription
TRUEnever evaluated
FALSEevaluated 64 times by 1 test
Evaluated by:
  • tst_ecmascripttests
0-64
135 *hasValue = true;
never executed: *hasValue = true;
0
136 return m_values[i].asReturnedValue();
executed 64 times by 1 test: return m_values[i].asReturnedValue();
Executed by:
  • tst_ecmascripttests
64
137 }-
138 }
executed 116 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
116
139-
140 if (hasValue)
hasValueDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_ecmascripttests
0-12
141 *hasValue = false;
never executed: *hasValue = false;
0
142 return Encode::undefined();
executed 12 times by 1 test: return Encode::undefined();
Executed by:
  • tst_ecmascripttests
12
143}-
144-
145// Removes the given \a key from the table-
146bool ESTable::remove(const Value &key)-
147{-
148 bool found = false;-
149 uint idx = 0;-
150 for (; idx < m_size; ++idx) {
idx < m_sizeDescription
TRUEevaluated 136 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 28 times by 1 test
Evaluated by:
  • tst_ecmascripttests
28-136
151 if (m_keys[idx].sameValueZero(key)) {
m_keys[idx].sameValueZero(key)Description
TRUEevaluated 88 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 48 times by 1 test
Evaluated by:
  • tst_ecmascripttests
48-88
152 found = true;-
153 break;
executed 88 times by 1 test: break;
Executed by:
  • tst_ecmascripttests
88
154 }-
155 }
executed 48 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
48
156-
157 if (found == true) {
found == trueDescription
TRUEevaluated 88 times by 1 test
Evaluated by:
  • tst_ecmascripttests
FALSEevaluated 28 times by 1 test
Evaluated by:
  • tst_ecmascripttests
28-88
158 memmove(m_keys + idx, m_keys + idx + 1, m_size - idx);-
159 memmove(m_values + idx, m_values + idx + 1, m_size - idx);-
160 m_size--;-
161 }
executed 87 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
87
162 return found;
executed 116 times by 1 test: return found;
Executed by:
  • tst_ecmascripttests
116
163}-
164-
165// Returns the size of the table. Note that the size may not match the underlying allocation.-
166uint ESTable::size() const-
167{-
168 return m_size;
executed 836 times by 1 test: return m_size;
Executed by:
  • tst_ecmascripttests
836
169}-
170-
171// Retrieves a key and value for a given \a idx, and places them in \a key and-
172// \a value. They must be valid pointers.-
173void ESTable::iterate(uint idx, Value *key, Value *value)-
174{-
175 Q_ASSERT(idx < m_size);-
176 Q_ASSERT(key);-
177 Q_ASSERT(value);-
178 *key = m_keys[idx];-
179 *value = m_values[idx];-
180}
executed 400 times by 1 test: end of block
Executed by:
  • tst_ecmascripttests
400
181-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0