OpenCoverage

qv4debugjob.cpp

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qv4debugjob.h"-
41-
42#include <private/qv4script_p.h>-
43#include <private/qqmlcontext_p.h>-
44#include <private/qv4qmlcontext_p.h>-
45#include <private/qv4qobjectwrapper_p.h>-
46#include <private/qqmldebugservice_p.h>-
47#include <private/qv4jscall_p.h>-
48-
49#include <QtQml/qqmlengine.h>-
50-
51QT_BEGIN_NAMESPACE-
52-
53QV4DebugJob::~QV4DebugJob()-
54{-
55}-
56-
57JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context,-
58 const QString &script) :-
59 engine(engine), frameNr(frameNr), context(context), script(script),-
60 resultIsException(false)-
61{}
executed 50 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
50
62-
63void JavaScriptJob::run()-
64{-
65 QV4::Scope scope(engine);-
66-
67 QV4::ScopedContext ctx(scope, engine->currentStackFrame ? engine->currentContext()-
68 : engine->scriptContext());-
69 QObject scopeObject;-
70-
71 QV4::CppStackFrame *frame = engine->currentStackFrame;-
72-
73 for (int i = 0; frame && i < frameNr; ++i)
frameDescription
TRUEevaluated 62 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
i < frameNrDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-62
74 frame = frame->parent;
executed 12 times by 1 test: frame = frame->parent;
Executed by:
  • tst_qv4debugger
12
75 if (frameNr > 0 && frame)
frameNr > 0Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 38 times by 1 test
Evaluated by:
  • tst_qv4debugger
frameDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-38
76 ctx = static_cast<QV4::ExecutionContext *>(&frame->jsFrame->context);
executed 12 times by 1 test: ctx = static_cast<QV4::ExecutionContext *>(&frame->jsFrame->context);
Executed by:
  • tst_qv4debugger
12
77-
78 if (context >= 0) {
context >= 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 42 times by 1 test
Evaluated by:
  • tst_qv4debugger
8-42
79 QQmlContext *extraContext = qmlContext(QQmlDebugService::objectForId(context));-
80 if (extraContext)
extraContextDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-8
81 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), &scopeObject);
never executed: ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), &scopeObject);
0
82 } else if (frameNr < 0) { // Use QML context if available
executed 8 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
frameNr < 0Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_qv4debugger
8-32
83 QQmlEngine *qmlEngine = engine->qmlEngine();-
84 if (qmlEngine) {
qmlEngineDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 30 times by 1 test
Evaluated by:
  • tst_qv4debugger
2-30
85 QQmlContext *qmlRootContext = qmlEngine->rootContext();-
86 QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(qmlRootContext);-
87-
88 QV4::ScopedObject withContext(scope, engine->newObject());-
89 QV4::ScopedString k(scope);-
90 QV4::ScopedValue v(scope);-
91 for (int ii = 0; ii < ctxtPriv->instances.count(); ++ii) {
ii < ctxtPriv-...tances.count()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-2
92 QObject *object = ctxtPriv->instances.at(ii);-
93 if (QQmlContext *context = qmlContext(object)) {
QQmlContext *c...ontext(object)Description
TRUEnever evaluated
FALSEnever evaluated
0
94 if (QQmlContextData *cdata = QQmlContextData::get(context)) {
QQmlContextDat...::get(context)Description
TRUEnever evaluated
FALSEnever evaluated
0
95 v = QV4::QObjectWrapper::wrap(engine, object);-
96 k = engine->newString(cdata->findObjectId(object));-
97 withContext->put(k, v);-
98 }
never executed: end of block
0
99 }
never executed: end of block
0
100 }
never executed: end of block
0
101 if (!engine->qmlContext())
!engine->qmlContext()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-2
102 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext), &scopeObject);
never executed: ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext), &scopeObject);
0
103 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
2
104 }
executed 32 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
32
105-
106 QV4::Script script(ctx, QV4::Compiler::ContextType::Eval, this->script);-
107 if (const QV4::Function *function = frame ? frame->v4Function : engine->globalCode)
const QV4::Fun...ne->globalCodeDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
frameDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-50
108 script.strictMode = function->isStrict();
executed 50 times by 1 test: script.strictMode = function->isStrict();
Executed by:
  • tst_qv4debugger
50
109-
110 // In order for property lookups in QML to work, we need to disable fast v4 lookups. That-
111 // is a side-effect of inheritContext.-
112 script.inheritContext = true;-
113 script.parse();-
114 QV4::ScopedValue result(scope);-
115 if (!scope.engine->hasException) {
!scope.engine->hasExceptionDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-50
116 if (frame) {
frameDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-50
117 QV4::ScopedValue thisObject(scope, frame->thisObject());-
118 result = script.run(thisObject);-
119 } else {
executed 50 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
50
120 result = script.run();-
121 }
never executed: end of block
0
122 }-
123 if (scope.engine->hasException) {
scope.engine->hasExceptionDescription
TRUEnever evaluated
FALSEevaluated 50 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-50
124 result = scope.engine->catchException();-
125 resultIsException = true;-
126 }
never executed: end of block
0
127 handleResult(result);-
128}
executed 50 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
50
129-
130bool JavaScriptJob::hasExeption() const-
131{-
132 return resultIsException;
executed 18 times by 1 test: return resultIsException;
Executed by:
  • tst_qv4debugger
18
133}-
134-
135BacktraceJob::BacktraceJob(QV4DataCollector *collector, int fromFrame, int toFrame) :-
136 CollectJob(collector), fromFrame(fromFrame), toFrame(toFrame)-
137{-
138}
never executed: end of block
0
139-
140void BacktraceJob::run()-
141{-
142 QJsonArray frameArray;-
143 QVector<QV4::StackFrame> frames = collector->engine()->stackTrace(toFrame);-
144 for (int i = fromFrame; i < toFrame && i < frames.size(); ++i)
i < toFrameDescription
TRUEnever evaluated
FALSEnever evaluated
i < frames.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
145 frameArray.push_back(collector->buildFrame(frames[i], i));
never executed: frameArray.push_back(collector->buildFrame(frames[i], i));
0
146 if (frameArray.isEmpty()) {
frameArray.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
147 result.insert(QStringLiteral("totalFrames"), 0);
never executed: return qstring_literal_temp;
0
148 } else {
never executed: end of block
0
149 result.insert(QStringLiteral("fromFrame"), fromFrame);
never executed: return qstring_literal_temp;
0
150 result.insert(QStringLiteral("toFrame"), fromFrame + frameArray.size());
never executed: return qstring_literal_temp;
0
151 result.insert(QStringLiteral("frames"), frameArray);
never executed: return qstring_literal_temp;
0
152 }
never executed: end of block
0
153 flushRedundantRefs();-
154}
never executed: end of block
0
155-
156FrameJob::FrameJob(QV4DataCollector *collector, int frameNr) :-
157 CollectJob(collector), frameNr(frameNr), success(false)-
158{-
159}
executed 100 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
100
160-
161void FrameJob::run()-
162{-
163 QVector<QV4::StackFrame> frames = collector->engine()->stackTrace(frameNr + 1);-
164 if (frameNr >= frames.length()) {
frameNr >= frames.length()Description
TRUEnever evaluated
FALSEevaluated 100 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-100
165 success = false;-
166 } else {
never executed: end of block
0
167 result = collector->buildFrame(frames[frameNr], frameNr);-
168 flushRedundantRefs();-
169 success = true;-
170 }
executed 100 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
100
171}-
172-
173bool FrameJob::wasSuccessful() const-
174{-
175 return success;
never executed: return success;
0
176}-
177-
178ScopeJob::ScopeJob(QV4DataCollector *collector, int frameNr, int scopeNr) :-
179 CollectJob(collector), frameNr(frameNr), scopeNr(scopeNr), success(false)-
180{-
181}
executed 72 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
72
182-
183void ScopeJob::run()-
184{-
185 QJsonObject object;-
186 success = collector->collectScope(&object, frameNr, scopeNr);-
187-
188 if (success) {
successDescription
TRUEevaluated 72 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEnever evaluated
0-72
189 QVector<QV4::Heap::ExecutionContext::ContextType> scopeTypes =-
190 collector->getScopeTypes(frameNr);-
191 result[QLatin1String("type")] = QV4DataCollector::encodeScopeType(scopeTypes[scopeNr]);-
192 } else {
executed 72 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
72
193 result[QLatin1String("type")] = -1;-
194 }
never executed: end of block
0
195 result[QLatin1String("index")] = scopeNr;-
196 result[QLatin1String("frameIndex")] = frameNr;-
197 result[QLatin1String("object")] = object;-
198 flushRedundantRefs();-
199}
executed 72 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
72
200-
201bool ScopeJob::wasSuccessful() const-
202{-
203 return success;
never executed: return success;
0
204}-
205-
206ValueLookupJob::ValueLookupJob(const QJsonArray &handles, QV4DataCollector *collector) :-
207 CollectJob(collector), handles(handles) {}
never executed: end of block
0
208-
209void ValueLookupJob::run()-
210{-
211 // Open a QML context if we don't have one, yet. We might run into QML objects when looking up-
212 // refs and that will crash without a valid QML context. Mind that engine->qmlContext() is only-
213 // set if the engine is currently executing QML code.-
214 QScopedPointer<QObject> scopeObject;-
215 QV4::ExecutionEngine *engine = collector->engine();-
216 QV4::Scope scope(engine);-
217 QV4::Heap::ExecutionContext *qmlContext = nullptr;-
218 if (engine->qmlEngine() && !engine->qmlContext()) {
engine->qmlEngine()Description
TRUEnever evaluated
FALSEnever evaluated
!engine->qmlContext()Description
TRUEnever evaluated
FALSEnever evaluated
0
219 scopeObject.reset(new QObject);-
220 qmlContext = QV4::QmlContext::create(engine->currentContext(),-
221 QQmlContextData::get(engine->qmlEngine()->rootContext()),-
222 scopeObject.data());-
223 }
never executed: end of block
0
224 QV4::ScopedStackFrame frame(scope, qmlContext);-
225 for (const QJsonValue &handle : handles) {-
226 QV4DataCollector::Ref ref = handle.toInt();-
227 if (!collector->isValidRef(ref)) {
!collector->isValidRef(ref)Description
TRUEnever evaluated
FALSEnever evaluated
0
228 exception = QString::fromLatin1("Invalid Ref: %1").arg(ref);-
229 break;
never executed: break;
0
230 }-
231 result[QString::number(ref)] = collector->lookupRef(ref, true);-
232 }
never executed: end of block
0
233 flushRedundantRefs();-
234}
never executed: end of block
0
235-
236const QString &ValueLookupJob::exceptionMessage() const-
237{-
238 return exception;
never executed: return exception;
0
239}-
240-
241ExpressionEvalJob::ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr,-
242 int context, const QString &expression,-
243 QV4DataCollector *collector) :-
244 JavaScriptJob(engine, frameNr, context, expression), collector(collector)-
245{-
246}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
18
247-
248void ExpressionEvalJob::handleResult(QV4::ScopedValue &value)-
249{-
250 if (hasExeption())
hasExeption()Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_qv4debugger
0-18
251 exception = value->toQStringNoThrow();
never executed: exception = value->toQStringNoThrow();
0
252 result = collector->lookupRef(collector->collect(value), true);-
253 if (collector->redundantRefs())
collector->redundantRefs()Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_qv4debugger
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qv4debugger
8-10
254 collectedRefs = collector->flushCollectedRefs();
executed 10 times by 1 test: collectedRefs = collector->flushCollectedRefs();
Executed by:
  • tst_qv4debugger
10
255}
executed 18 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
18
256-
257const QString &ExpressionEvalJob::exceptionMessage() const-
258{-
259 return exception;
never executed: return exception;
0
260}-
261-
262const QJsonObject &ExpressionEvalJob::returnValue() const-
263{-
264 return result;
executed 18 times by 1 test: return result;
Executed by:
  • tst_qv4debugger
18
265}-
266-
267// TODO: Drop this method once we don't need to support redundantRefs anymore-
268const QJsonArray &ExpressionEvalJob::refs() const-
269{-
270 Q_ASSERT(collector->redundantRefs());-
271 return collectedRefs;
never executed: return collectedRefs;
0
272}-
273-
274GatherSourcesJob::GatherSourcesJob(QV4::ExecutionEngine *engine)-
275 : engine(engine)-
276{}
never executed: end of block
0
277-
278void GatherSourcesJob::run()-
279{-
280 for (QV4::CompiledData::CompilationUnit *unit : engine->compilationUnits) {-
281 QString fileName = unit->fileName();-
282 if (!fileName.isEmpty())
!fileName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
283 sources.append(fileName);
never executed: sources.append(fileName);
0
284 }
never executed: end of block
0
285}
never executed: end of block
0
286-
287const QStringList &GatherSourcesJob::result() const-
288{-
289 return sources;
never executed: return sources;
0
290}-
291-
292EvalJob::EvalJob(QV4::ExecutionEngine *engine, const QString &script) :-
293 JavaScriptJob(engine, /*frameNr*/-1, /*context*/ -1, script), result(false)-
294{}
executed 32 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
32
295-
296void EvalJob::handleResult(QV4::ScopedValue &result)-
297{-
298 this->result = result->toBoolean();-
299}
executed 32 times by 1 test: end of block
Executed by:
  • tst_qv4debugger
32
300-
301bool EvalJob::resultAsBoolean() const-
302{-
303 return result;
executed 32 times by 1 test: return result;
Executed by:
  • tst_qv4debugger
32
304}-
305-
306QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0