Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.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 "qv4datacollector.h" | - | ||||||||||||
41 | #include "qv4debugger.h" | - | ||||||||||||
42 | #include "qv4debugjob.h" | - | ||||||||||||
43 | - | |||||||||||||
44 | #include <private/qv4script_p.h> | - | ||||||||||||
45 | #include <private/qv4string_p.h> | - | ||||||||||||
46 | #include <private/qv4objectiterator_p.h> | - | ||||||||||||
47 | #include <private/qv4identifier_p.h> | - | ||||||||||||
48 | #include <private/qv4runtime_p.h> | - | ||||||||||||
49 | #include <private/qv4identifiertable_p.h> | - | ||||||||||||
50 | - | |||||||||||||
51 | #include <private/qqmlcontext_p.h> | - | ||||||||||||
52 | #include <private/qqmlengine_p.h> | - | ||||||||||||
53 | - | |||||||||||||
54 | #include <QtCore/qjsonarray.h> | - | ||||||||||||
55 | #include <QtCore/qjsonobject.h> | - | ||||||||||||
56 | - | |||||||||||||
57 | QT_BEGIN_NAMESPACE | - | ||||||||||||
58 | - | |||||||||||||
59 | QV4::CppStackFrame *QV4DataCollector::findFrame(int frame) | - | ||||||||||||
60 | { | - | ||||||||||||
61 | QV4::CppStackFrame *f = engine()->currentStackFrame; | - | ||||||||||||
62 | while (f && frame) {
| 0-1544 | ||||||||||||
63 | --frame; | - | ||||||||||||
64 | f = f->parent; | - | ||||||||||||
65 | } executed 1200 times by 1 test: end of block Executed by:
| 1200 | ||||||||||||
66 | return f; executed 344 times by 1 test: return f; Executed by:
| 344 | ||||||||||||
67 | } | - | ||||||||||||
68 | - | |||||||||||||
69 | QV4::Heap::ExecutionContext *QV4DataCollector::findContext(int frame) | - | ||||||||||||
70 | { | - | ||||||||||||
71 | QV4::CppStackFrame *f = findFrame(frame); | - | ||||||||||||
72 | - | |||||||||||||
73 | return f ? f->context()->d() : nullptr; executed 172 times by 1 test: return f ? f->context()->d() : nullptr; Executed by:
| 172 | ||||||||||||
74 | } | - | ||||||||||||
75 | - | |||||||||||||
76 | QV4::Heap::ExecutionContext *QV4DataCollector::findScope(QV4::Heap::ExecutionContext *ctx, int scope) | - | ||||||||||||
77 | { | - | ||||||||||||
78 | for (; scope > 0 && ctx; --scope)
| 0-72 | ||||||||||||
79 | ctx = ctx->outer; executed 60 times by 1 test: ctx = ctx->outer; Executed by:
| 60 | ||||||||||||
80 | - | |||||||||||||
81 | return ctx; executed 72 times by 1 test: return ctx; Executed by:
| 72 | ||||||||||||
82 | } | - | ||||||||||||
83 | - | |||||||||||||
84 | QVector<QV4::Heap::ExecutionContext::ContextType> QV4DataCollector::getScopeTypes(int frame) | - | ||||||||||||
85 | { | - | ||||||||||||
86 | QVector<QV4::Heap::ExecutionContext::ContextType> types; | - | ||||||||||||
87 | - | |||||||||||||
88 | QV4::Heap::ExecutionContext *it = findFrame(frame)->context()->d(); | - | ||||||||||||
89 | - | |||||||||||||
90 | for (; it; it = it->outer)
| 172-436 | ||||||||||||
91 | types.append(QV4::Heap::ExecutionContext::ContextType(it->type)); executed 436 times by 1 test: types.append(QV4::Heap::ExecutionContext::ContextType(it->type)); Executed by:
| 436 | ||||||||||||
92 | - | |||||||||||||
93 | return types; executed 172 times by 1 test: return types; Executed by:
| 172 | ||||||||||||
94 | } | - | ||||||||||||
95 | - | |||||||||||||
96 | int QV4DataCollector::encodeScopeType(QV4::Heap::ExecutionContext::ContextType scopeType) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | switch (scopeType) { | - | ||||||||||||
99 | case QV4::Heap::ExecutionContext::Type_GlobalContext: executed 100 times by 1 test: case QV4::Heap::ExecutionContext::Type_GlobalContext: Executed by:
| 100 | ||||||||||||
100 | break; executed 100 times by 1 test: break; Executed by:
| 100 | ||||||||||||
101 | case QV4::Heap::ExecutionContext::Type_WithContext: never executed: case QV4::Heap::ExecutionContext::Type_WithContext: | 0 | ||||||||||||
102 | return 2; never executed: return 2; | 0 | ||||||||||||
103 | case QV4::Heap::ExecutionContext::Type_CallContext: executed 144 times by 1 test: case QV4::Heap::ExecutionContext::Type_CallContext: Executed by:
| 144 | ||||||||||||
104 | return 1; executed 144 times by 1 test: return 1; Executed by:
| 144 | ||||||||||||
105 | case QV4::Heap::ExecutionContext::Type_QmlContext: never executed: case QV4::Heap::ExecutionContext::Type_QmlContext: | 0 | ||||||||||||
106 | return 3; never executed: return 3; | 0 | ||||||||||||
107 | case QV4::Heap::ExecutionContext::Type_BlockContext: executed 60 times by 1 test: case QV4::Heap::ExecutionContext::Type_BlockContext: Executed by:
| 60 | ||||||||||||
108 | return 4; executed 60 times by 1 test: return 4; Executed by:
| 60 | ||||||||||||
109 | } | - | ||||||||||||
110 | return 0; executed 100 times by 1 test: return 0; Executed by:
| 100 | ||||||||||||
111 | } | - | ||||||||||||
112 | - | |||||||||||||
113 | QV4DataCollector::QV4DataCollector(QV4::ExecutionEngine *engine) | - | ||||||||||||
114 | : m_engine(engine), m_namesAsObjects(true), m_redundantRefs(true) | - | ||||||||||||
115 | { | - | ||||||||||||
116 | m_values.set(engine, engine->newArrayObject()); | - | ||||||||||||
117 | } executed 194 times by 3 tests: end of block Executed by:
| 194 | ||||||||||||
118 | - | |||||||||||||
119 | // TODO: Directly call addRef() once we don't need to support redundantRefs anymore | - | ||||||||||||
120 | QV4DataCollector::Ref QV4DataCollector::collect(const QV4::ScopedValue &value) | - | ||||||||||||
121 | { | - | ||||||||||||
122 | Ref ref = addRef(value); | - | ||||||||||||
123 | if (m_redundantRefs)
| 110-134 | ||||||||||||
124 | m_collectedRefs.append(ref); executed 134 times by 1 test: m_collectedRefs.append(ref); Executed by:
| 134 | ||||||||||||
125 | return ref; executed 244 times by 1 test: return ref; Executed by:
| 244 | ||||||||||||
126 | } | - | ||||||||||||
127 | - | |||||||||||||
128 | const QV4::Object *collectProperty(const QV4::ScopedValue &value, QV4::ExecutionEngine *engine, | - | ||||||||||||
129 | QJsonObject &dict) | - | ||||||||||||
130 | { | - | ||||||||||||
131 | QV4::Scope scope(engine); | - | ||||||||||||
132 | QV4::ScopedValue typeString(scope, QV4::Runtime::method_typeofValue(engine, value)); | - | ||||||||||||
133 | dict.insert(QStringLiteral("type"), typeString->toQStringNoThrow()); executed 684 times by 1 test: return qstring_literal_temp; Executed by:
| 684 | ||||||||||||
134 | - | |||||||||||||
135 | const QLatin1String valueKey("value"); | - | ||||||||||||
136 | switch (value->type()) { | - | ||||||||||||
137 | case QV4::Value::Empty_Type: never executed: case QV4::Value::Empty_Type: | 0 | ||||||||||||
138 | Q_ASSERT(!"empty Value encountered"); | - | ||||||||||||
139 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
140 | case QV4::Value::Undefined_Type: executed 24 times by 1 test: case QV4::Value::Undefined_Type: Executed by:
| 24 | ||||||||||||
141 | dict.insert(valueKey, QJsonValue::Undefined); | - | ||||||||||||
142 | return nullptr; executed 24 times by 1 test: return nullptr; Executed by:
| 24 | ||||||||||||
143 | case QV4::Value::Null_Type: executed 12 times by 1 test: case QV4::Value::Null_Type: Executed by:
| 12 | ||||||||||||
144 | dict.insert(valueKey, QJsonValue::Null); | - | ||||||||||||
145 | return nullptr; executed 12 times by 1 test: return nullptr; Executed by:
| 12 | ||||||||||||
146 | case QV4::Value::Boolean_Type: never executed: case QV4::Value::Boolean_Type: | 0 | ||||||||||||
147 | dict.insert(valueKey, value->booleanValue()); | - | ||||||||||||
148 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
149 | case QV4::Value::Managed_Type: executed 346 times by 1 test: case QV4::Value::Managed_Type: Executed by:
| 346 | ||||||||||||
150 | if (const QV4::String *s = value->as<QV4::String>()) {
| 14-332 | ||||||||||||
151 | dict.insert(valueKey, s->toQString()); | - | ||||||||||||
152 | } else if (const QV4::ArrayObject *a = value->as<QV4::ArrayObject>()) { executed 14 times by 1 test: end of block Executed by:
| 0-332 | ||||||||||||
153 | // size of an array is number of its numerical properties; We don't consider free form | - | ||||||||||||
154 | // object properties here. | - | ||||||||||||
155 | dict.insert(valueKey, qint64(a->getLength())); | - | ||||||||||||
156 | return a; never executed: return a; | 0 | ||||||||||||
157 | } else if (const QV4::Object *o = value->as<QV4::Object>()) {
| 0-332 | ||||||||||||
158 | int numProperties = 0; | - | ||||||||||||
159 | QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly); | - | ||||||||||||
160 | QV4::PropertyAttributes attrs; | - | ||||||||||||
161 | uint index; | - | ||||||||||||
162 | QV4::ScopedProperty p(scope); | - | ||||||||||||
163 | QV4::ScopedString name(scope); | - | ||||||||||||
164 | while (true) { | - | ||||||||||||
165 | it.next(name.getRef(), &index, p, &attrs); | - | ||||||||||||
166 | if (attrs.isEmpty())
| 332-414 | ||||||||||||
167 | break; executed 332 times by 1 test: break; Executed by:
| 332 | ||||||||||||
168 | else | - | ||||||||||||
169 | ++numProperties; executed 414 times by 1 test: ++numProperties; Executed by:
| 414 | ||||||||||||
170 | } | - | ||||||||||||
171 | dict.insert(valueKey, numProperties); | - | ||||||||||||
172 | return o; executed 332 times by 1 test: return o; Executed by:
| 332 | ||||||||||||
173 | } else { | - | ||||||||||||
174 | Q_UNREACHABLE(); | - | ||||||||||||
175 | } never executed: end of block | 0 | ||||||||||||
176 | return nullptr; executed 14 times by 1 test: return nullptr; Executed by:
| 14 | ||||||||||||
177 | case QV4::Value::Integer_Type: executed 302 times by 1 test: case QV4::Value::Integer_Type: Executed by:
| 302 | ||||||||||||
178 | dict.insert(valueKey, value->integerValue()); | - | ||||||||||||
179 | return nullptr; executed 302 times by 1 test: return nullptr; Executed by:
| 302 | ||||||||||||
180 | default: {// double never executed: default: | 0 | ||||||||||||
181 | const double val = value->doubleValue(); | - | ||||||||||||
182 | if (qIsFinite(val))
| 0 | ||||||||||||
183 | dict.insert(valueKey, val); never executed: dict.insert(valueKey, val); | 0 | ||||||||||||
184 | else if (qIsNaN(val))
| 0 | ||||||||||||
185 | dict.insert(valueKey, QStringLiteral("NaN")); never executed: dict.insert(valueKey, ([]() noexcept -> QString { enum { Size = sizeof(u"" "NaN")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "NaN" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); never executed: return qstring_literal_temp; | 0 | ||||||||||||
186 | else if (val < 0)
| 0 | ||||||||||||
187 | dict.insert(valueKey, QStringLiteral("-Infinity")); never executed: dict.insert(valueKey, ([]() noexcept -> QString { enum { Size = sizeof(u"" "-Infinity")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "-Infinity" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); never executed: return qstring_literal_temp; | 0 | ||||||||||||
188 | else | - | ||||||||||||
189 | dict.insert(valueKey, QStringLiteral("Infinity")); never executed: dict.insert(valueKey, ([]() noexcept -> QString { enum { Size = sizeof(u"" "Infinity")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "Infinity" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); never executed: return qstring_literal_temp; | 0 | ||||||||||||
190 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
191 | } | - | ||||||||||||
192 | } | - | ||||||||||||
193 | } | - | ||||||||||||
194 | - | |||||||||||||
195 | QJsonObject QV4DataCollector::lookupRef(Ref ref, bool deep) | - | ||||||||||||
196 | { | - | ||||||||||||
197 | QJsonObject dict; | - | ||||||||||||
198 | - | |||||||||||||
199 | if (m_namesAsObjects) {
| 0-426 | ||||||||||||
200 | if (lookupSpecialRef(ref, &dict))
| 116-310 | ||||||||||||
201 | return dict; executed 116 times by 1 test: return dict; Executed by:
| 116 | ||||||||||||
202 | } executed 310 times by 1 test: end of block Executed by:
| 310 | ||||||||||||
203 | - | |||||||||||||
204 | if (m_redundantRefs)
| 44-266 | ||||||||||||
205 | deep = true; executed 266 times by 1 test: deep = true; Executed by:
| 266 | ||||||||||||
206 | - | |||||||||||||
207 | dict.insert(QStringLiteral("handle"), qint64(ref)); executed 310 times by 1 test: return qstring_literal_temp; Executed by:
| 310 | ||||||||||||
208 | QV4::Scope scope(engine()); | - | ||||||||||||
209 | QV4::ScopedValue value(scope, getValue(ref)); | - | ||||||||||||
210 | - | |||||||||||||
211 | const QV4::Object *object = collectProperty(value, engine(), dict); | - | ||||||||||||
212 | if (deep && object)
| 0-310 | ||||||||||||
213 | dict.insert(QStringLiteral("properties"), collectProperties(object)); executed 204 times by 1 test: dict.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "properties")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "properties" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()), collectProperties(object)); Executed by:
executed 204 times by 1 test: return qstring_literal_temp; Executed by:
| 204 | ||||||||||||
214 | - | |||||||||||||
215 | return dict; executed 310 times by 1 test: return dict; Executed by:
| 310 | ||||||||||||
216 | } | - | ||||||||||||
217 | - | |||||||||||||
218 | // TODO: Drop this method once we don't need to support namesAsObjects anymore | - | ||||||||||||
219 | QV4DataCollector::Ref QV4DataCollector::addFunctionRef(const QString &functionName) | - | ||||||||||||
220 | { | - | ||||||||||||
221 | Q_ASSERT(m_namesAsObjects); | - | ||||||||||||
222 | Ref ref = addRef(QV4::Primitive::emptyValue(), false); | - | ||||||||||||
223 | - | |||||||||||||
224 | QJsonObject dict; | - | ||||||||||||
225 | dict.insert(QStringLiteral("handle"), qint64(ref)); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
226 | dict.insert(QStringLiteral("type"), QStringLiteral("function")); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
227 | dict.insert(QStringLiteral("name"), functionName); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
228 | m_specialRefs.insert(ref, dict); | - | ||||||||||||
229 | m_collectedRefs.append(ref); | - | ||||||||||||
230 | - | |||||||||||||
231 | return ref; executed 100 times by 1 test: return ref; Executed by:
| 100 | ||||||||||||
232 | } | - | ||||||||||||
233 | - | |||||||||||||
234 | // TODO: Drop this method once we don't need to support namesAsObjects anymore | - | ||||||||||||
235 | QV4DataCollector::Ref QV4DataCollector::addScriptRef(const QString &scriptName) | - | ||||||||||||
236 | { | - | ||||||||||||
237 | Q_ASSERT(m_namesAsObjects); | - | ||||||||||||
238 | Ref ref = addRef(QV4::Primitive::emptyValue(), false); | - | ||||||||||||
239 | - | |||||||||||||
240 | QJsonObject dict; | - | ||||||||||||
241 | dict.insert(QStringLiteral("handle"), qint64(ref)); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
242 | dict.insert(QStringLiteral("type"), QStringLiteral("script")); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
243 | dict.insert(QStringLiteral("name"), scriptName); executed 100 times by 1 test: return qstring_literal_temp; Executed by:
| 100 | ||||||||||||
244 | m_specialRefs.insert(ref, dict); | - | ||||||||||||
245 | m_collectedRefs.append(ref); | - | ||||||||||||
246 | - | |||||||||||||
247 | return ref; executed 100 times by 1 test: return ref; Executed by:
| 100 | ||||||||||||
248 | } | - | ||||||||||||
249 | - | |||||||||||||
250 | bool QV4DataCollector::isValidRef(QV4DataCollector::Ref ref) const | - | ||||||||||||
251 | { | - | ||||||||||||
252 | QV4::Scope scope(engine()); | - | ||||||||||||
253 | QV4::ScopedObject array(scope, m_values.value()); | - | ||||||||||||
254 | return ref < array->getLength(); never executed: return ref < array->getLength(); | 0 | ||||||||||||
255 | } | - | ||||||||||||
256 | - | |||||||||||||
257 | bool QV4DataCollector::collectScope(QJsonObject *dict, int frameNr, int scopeNr) | - | ||||||||||||
258 | { | - | ||||||||||||
259 | QV4::Scope scope(engine()); | - | ||||||||||||
260 | - | |||||||||||||
261 | QV4::Scoped<QV4::ExecutionContext> ctxt(scope, findScope(findContext(frameNr), scopeNr)); | - | ||||||||||||
262 | if (!ctxt)
| 0-72 | ||||||||||||
263 | return false; never executed: return false; | 0 | ||||||||||||
264 | - | |||||||||||||
265 | QV4::ScopedObject scopeObject(scope, engine()->newObject()); | - | ||||||||||||
266 | if (ctxt->d()->type == QV4::Heap::ExecutionContext::Type_CallContext) {
| 0-72 | ||||||||||||
267 | QStringList names; | - | ||||||||||||
268 | Refs collectedRefs; | - | ||||||||||||
269 | - | |||||||||||||
270 | QV4::ScopedValue v(scope); | - | ||||||||||||
271 | QV4::Heap::InternalClass *ic = ctxt->internalClass(); | - | ||||||||||||
272 | for (uint i = 0; i < ic->size; ++i) {
| 72-224 | ||||||||||||
273 | QString name = ic->nameMap[i].toQString(); | - | ||||||||||||
274 | names.append(name); | - | ||||||||||||
275 | v = static_cast<QV4::Heap::CallContext *>(ctxt->d())->locals[i]; | - | ||||||||||||
276 | collectedRefs.append(collect(v)); | - | ||||||||||||
277 | } executed 224 times by 1 test: end of block Executed by:
| 224 | ||||||||||||
278 | - | |||||||||||||
279 | Q_ASSERT(names.size() == collectedRefs.size()); | - | ||||||||||||
280 | QV4::ScopedString propName(scope); | - | ||||||||||||
281 | for (int i = 0, ei = collectedRefs.size(); i != ei; ++i) {
| 72-224 | ||||||||||||
282 | propName = engine()->newString(names.at(i)); | - | ||||||||||||
283 | scopeObject->put(propName, (v = getValue(collectedRefs.at(i)))); | - | ||||||||||||
284 | } executed 224 times by 1 test: end of block Executed by:
| 224 | ||||||||||||
285 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||
286 | - | |||||||||||||
287 | Ref scopeObjectRef = addRef(scopeObject); | - | ||||||||||||
288 | if (m_redundantRefs) {
| 32-40 | ||||||||||||
289 | dict->insert(QStringLiteral("ref"), qint64(scopeObjectRef)); executed 40 times by 1 test: return qstring_literal_temp; Executed by:
| 40 | ||||||||||||
290 | m_collectedRefs.append(scopeObjectRef); | - | ||||||||||||
291 | } else { executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||
292 | *dict = lookupRef(scopeObjectRef, true); | - | ||||||||||||
293 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||
294 | - | |||||||||||||
295 | return true; executed 72 times by 1 test: return true; Executed by:
| 72 | ||||||||||||
296 | } | - | ||||||||||||
297 | - | |||||||||||||
298 | QJsonObject toRef(QV4DataCollector::Ref ref) { | - | ||||||||||||
299 | QJsonObject dict; | - | ||||||||||||
300 | dict.insert(QStringLiteral("ref"), qint64(ref)); executed 200 times by 1 test: return qstring_literal_temp; Executed by:
| 200 | ||||||||||||
301 | return dict; executed 200 times by 1 test: return dict; Executed by:
| 200 | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int frameNr) | - | ||||||||||||
305 | { | - | ||||||||||||
306 | QJsonObject frame; | - | ||||||||||||
307 | frame[QLatin1String("index")] = frameNr; | - | ||||||||||||
308 | frame[QLatin1String("debuggerFrame")] = false; | - | ||||||||||||
309 | if (m_namesAsObjects) {
| 0-100 | ||||||||||||
310 | frame[QLatin1String("func")] = toRef(addFunctionRef(stackFrame.function)); | - | ||||||||||||
311 | frame[QLatin1String("script")] = toRef(addScriptRef(stackFrame.source)); | - | ||||||||||||
312 | } else { executed 100 times by 1 test: end of block Executed by:
| 100 | ||||||||||||
313 | frame[QLatin1String("func")] = stackFrame.function; | - | ||||||||||||
314 | frame[QLatin1String("script")] = stackFrame.source; | - | ||||||||||||
315 | } never executed: end of block | 0 | ||||||||||||
316 | frame[QLatin1String("line")] = stackFrame.line - 1; | - | ||||||||||||
317 | if (stackFrame.column >= 0)
| 0-100 | ||||||||||||
318 | frame[QLatin1String("column")] = stackFrame.column; never executed: frame[QLatin1String("column")] = stackFrame.column; | 0 | ||||||||||||
319 | - | |||||||||||||
320 | QJsonArray scopes; | - | ||||||||||||
321 | QV4::Scope scope(engine()); | - | ||||||||||||
322 | QV4::ScopedContext ctxt(scope, findContext(frameNr)); | - | ||||||||||||
323 | while (ctxt) {
| 100-232 | ||||||||||||
324 | if (QV4::CallContext *cCtxt = ctxt->asCallContext()) {
| 72-160 | ||||||||||||
325 | if (cCtxt->d()->activation)
| 0-72 | ||||||||||||
326 | break; never executed: break; | 0 | ||||||||||||
327 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||
328 | ctxt = ctxt->d()->outer; | - | ||||||||||||
329 | } executed 232 times by 1 test: end of block Executed by:
| 232 | ||||||||||||
330 | - | |||||||||||||
331 | if (ctxt) {
| 0-100 | ||||||||||||
332 | QV4::ScopedValue o(scope, ctxt->d()->activation); | - | ||||||||||||
333 | frame[QLatin1String("receiver")] = toRef(collect(o)); | - | ||||||||||||
334 | } never executed: end of block | 0 | ||||||||||||
335 | - | |||||||||||||
336 | // Only type and index are used by Qt Creator, so we keep it easy: | - | ||||||||||||
337 | QVector<QV4::Heap::ExecutionContext::ContextType> scopeTypes = getScopeTypes(frameNr); | - | ||||||||||||
338 | for (int i = 0, ei = scopeTypes.count(); i != ei; ++i) {
| 100-232 | ||||||||||||
339 | int type = encodeScopeType(scopeTypes[i]); | - | ||||||||||||
340 | if (type == -1)
| 0-232 | ||||||||||||
341 | continue; never executed: continue; | 0 | ||||||||||||
342 | - | |||||||||||||
343 | QJsonObject scope; | - | ||||||||||||
344 | scope[QLatin1String("index")] = i; | - | ||||||||||||
345 | scope[QLatin1String("type")] = type; | - | ||||||||||||
346 | scopes.push_back(scope); | - | ||||||||||||
347 | } executed 232 times by 1 test: end of block Executed by:
| 232 | ||||||||||||
348 | - | |||||||||||||
349 | frame[QLatin1String("scopes")] = scopes; | - | ||||||||||||
350 | - | |||||||||||||
351 | return frame; executed 100 times by 1 test: return frame; Executed by:
| 100 | ||||||||||||
352 | } | - | ||||||||||||
353 | - | |||||||||||||
354 | // TODO: Drop this method once we don't need to support redundantRefs anymore | - | ||||||||||||
355 | QJsonArray QV4DataCollector::flushCollectedRefs() | - | ||||||||||||
356 | { | - | ||||||||||||
357 | Q_ASSERT(m_redundantRefs); | - | ||||||||||||
358 | QJsonArray refs; | - | ||||||||||||
359 | std::sort(m_collectedRefs.begin(), m_collectedRefs.end()); | - | ||||||||||||
360 | for (int i = 0, ei = m_collectedRefs.size(); i != ei; ++i) {
| 108-330 | ||||||||||||
361 | QV4DataCollector::Ref ref = m_collectedRefs.at(i); | - | ||||||||||||
362 | if (i > 0 && ref == m_collectedRefs.at(i - 1))
| 4-222 | ||||||||||||
363 | continue; executed 4 times by 1 test: continue; Executed by:
| 4 | ||||||||||||
364 | refs.append(lookupRef(ref, true)); | - | ||||||||||||
365 | } executed 326 times by 1 test: end of block Executed by:
| 326 | ||||||||||||
366 | - | |||||||||||||
367 | m_collectedRefs.clear(); | - | ||||||||||||
368 | return refs; executed 108 times by 1 test: return refs; Executed by:
| 108 | ||||||||||||
369 | } | - | ||||||||||||
370 | - | |||||||||||||
371 | void QV4DataCollector::clear() | - | ||||||||||||
372 | { | - | ||||||||||||
373 | m_values.set(engine(), engine()->newArrayObject()); | - | ||||||||||||
374 | m_collectedRefs.clear(); | - | ||||||||||||
375 | m_specialRefs.clear(); | - | ||||||||||||
376 | m_namesAsObjects = true; | - | ||||||||||||
377 | m_redundantRefs = true; | - | ||||||||||||
378 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
379 | - | |||||||||||||
380 | QV4DataCollector::Ref QV4DataCollector::addRef(QV4::Value value, bool deduplicate) | - | ||||||||||||
381 | { | - | ||||||||||||
382 | class ExceptionStateSaver | - | ||||||||||||
383 | { | - | ||||||||||||
384 | quint8 *hasExceptionLoc; | - | ||||||||||||
385 | quint8 hadException; | - | ||||||||||||
386 | - | |||||||||||||
387 | public: | - | ||||||||||||
388 | ExceptionStateSaver(QV4::ExecutionEngine *engine) | - | ||||||||||||
389 | : hasExceptionLoc(&engine->hasException) | - | ||||||||||||
390 | , hadException(false) | - | ||||||||||||
391 | { std::swap(*hasExceptionLoc, hadException); } executed 644 times by 1 test: end of block Executed by:
| 644 | ||||||||||||
392 | - | |||||||||||||
393 | ~ExceptionStateSaver() | - | ||||||||||||
394 | { std::swap(*hasExceptionLoc, hadException); } executed 644 times by 1 test: end of block Executed by:
| 644 | ||||||||||||
395 | }; | - | ||||||||||||
396 | - | |||||||||||||
397 | // if we wouldn't do this, the put won't work. | - | ||||||||||||
398 | ExceptionStateSaver resetExceptionState(engine()); | - | ||||||||||||
399 | QV4::Scope scope(engine()); | - | ||||||||||||
400 | QV4::ScopedObject array(scope, m_values.value()); | - | ||||||||||||
401 | if (deduplicate) {
| 200-444 | ||||||||||||
402 | for (Ref i = 0; i < array->getLength(); ++i) {
| 208-4858 | ||||||||||||
403 | if (array->get(i) == value.rawValue() && !m_specialRefs.contains(i))
| 24-4598 | ||||||||||||
404 | return i; executed 236 times by 1 test: return i; Executed by:
| 236 | ||||||||||||
405 | } executed 4622 times by 1 test: end of block Executed by:
| 4622 | ||||||||||||
406 | } executed 208 times by 1 test: end of block Executed by:
| 208 | ||||||||||||
407 | Ref ref = array->getLength(); | - | ||||||||||||
408 | array->put(ref, value); | - | ||||||||||||
409 | Q_ASSERT(array->getLength() - 1 == ref); | - | ||||||||||||
410 | return ref; executed 408 times by 1 test: return ref; Executed by:
| 408 | ||||||||||||
411 | } | - | ||||||||||||
412 | - | |||||||||||||
413 | QV4::ReturnedValue QV4DataCollector::getValue(Ref ref) | - | ||||||||||||
414 | { | - | ||||||||||||
415 | QV4::Scope scope(engine()); | - | ||||||||||||
416 | QV4::ScopedObject array(scope, m_values.value()); | - | ||||||||||||
417 | Q_ASSERT(ref < array->getLength()); | - | ||||||||||||
418 | return array->get(ref, nullptr); executed 534 times by 1 test: return array->get(ref, nullptr); Executed by:
| 534 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | // TODO: Drop this method once we don't need to support namesAsObjects anymore | - | ||||||||||||
422 | bool QV4DataCollector::lookupSpecialRef(Ref ref, QJsonObject *dict) | - | ||||||||||||
423 | { | - | ||||||||||||
424 | Q_ASSERT(m_namesAsObjects); | - | ||||||||||||
425 | SpecialRefs::const_iterator it = m_specialRefs.constFind(ref); | - | ||||||||||||
426 | if (it == m_specialRefs.cend())
| 116-310 | ||||||||||||
427 | return false; executed 310 times by 1 test: return false; Executed by:
| 310 | ||||||||||||
428 | - | |||||||||||||
429 | *dict = it.value(); | - | ||||||||||||
430 | return true; executed 116 times by 1 test: return true; Executed by:
| 116 | ||||||||||||
431 | } | - | ||||||||||||
432 | - | |||||||||||||
433 | QJsonArray QV4DataCollector::collectProperties(const QV4::Object *object) | - | ||||||||||||
434 | { | - | ||||||||||||
435 | QJsonArray res; | - | ||||||||||||
436 | - | |||||||||||||
437 | QV4::Scope scope(engine()); | - | ||||||||||||
438 | QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::EnumerableOnly); | - | ||||||||||||
439 | QV4::ScopedValue name(scope); | - | ||||||||||||
440 | QV4::ScopedValue value(scope); | - | ||||||||||||
441 | while (true) { | - | ||||||||||||
442 | QV4::Value v; | - | ||||||||||||
443 | name = it.nextPropertyNameAsString(&v); | - | ||||||||||||
444 | if (name->isNull())
| 204-374 | ||||||||||||
445 | break; executed 204 times by 1 test: break; Executed by:
| 204 | ||||||||||||
446 | QString key = name->toQStringNoThrow(); | - | ||||||||||||
447 | value = v; | - | ||||||||||||
448 | res.append(collectAsJson(key, value)); | - | ||||||||||||
449 | } executed 374 times by 1 test: end of block Executed by:
| 374 | ||||||||||||
450 | - | |||||||||||||
451 | return res; executed 204 times by 1 test: return res; Executed by:
| 204 | ||||||||||||
452 | } | - | ||||||||||||
453 | - | |||||||||||||
454 | QJsonObject QV4DataCollector::collectAsJson(const QString &name, const QV4::ScopedValue &value) | - | ||||||||||||
455 | { | - | ||||||||||||
456 | QJsonObject dict; | - | ||||||||||||
457 | if (!name.isNull())
| 0-374 | ||||||||||||
458 | dict.insert(QStringLiteral("name"), name); executed 374 times by 1 test: dict.insert(([]() noexcept -> QString { enum { Size = sizeof(u"" "name")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "name" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()), name); Executed by:
executed 374 times by 1 test: return qstring_literal_temp; Executed by:
| 374 | ||||||||||||
459 | if (value->isManaged() && !value->isString()) {
| 10-236 | ||||||||||||
460 | Ref ref = addRef(value); | - | ||||||||||||
461 | dict.insert(QStringLiteral("ref"), qint64(ref)); executed 128 times by 1 test: return qstring_literal_temp; Executed by:
| 128 | ||||||||||||
462 | if (m_redundantRefs)
| 38-90 | ||||||||||||
463 | m_collectedRefs.append(ref); executed 90 times by 1 test: m_collectedRefs.append(ref); Executed by:
| 90 | ||||||||||||
464 | } executed 128 times by 1 test: end of block Executed by:
| 128 | ||||||||||||
465 | - | |||||||||||||
466 | collectProperty(value, engine(), dict); | - | ||||||||||||
467 | return dict; executed 374 times by 1 test: return dict; Executed by:
| 374 | ||||||||||||
468 | } | - | ||||||||||||
469 | - | |||||||||||||
470 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |