1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QV4DEBUGJOB_H |
5 | #define QV4DEBUGJOB_H |
6 | |
7 | #include "qv4datacollector.h" |
8 | #include <private/qv4engine_p.h> |
9 | |
10 | #include <QtCore/qjsonarray.h> |
11 | #include <QtCore/qjsonobject.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QV4DataCollector; |
16 | class QV4DebugJob |
17 | { |
18 | public: |
19 | virtual ~QV4DebugJob(); |
20 | virtual void run() = 0; |
21 | }; |
22 | |
23 | class JavaScriptJob : public QV4DebugJob |
24 | { |
25 | QV4::ExecutionEngine *engine; |
26 | int frameNr; |
27 | int context; |
28 | const QString &script; |
29 | bool resultIsException; |
30 | |
31 | public: |
32 | JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context, const QString &script); |
33 | void run() override; |
34 | bool hasExeption() const; |
35 | |
36 | protected: |
37 | virtual void handleResult(QV4::ScopedValue &result) = 0; |
38 | }; |
39 | |
40 | class CollectJob : public QV4DebugJob |
41 | { |
42 | protected: |
43 | QV4DataCollector *collector; |
44 | QJsonObject result; |
45 | |
46 | public: |
47 | CollectJob(QV4DataCollector *collector) : collector(collector) {} |
48 | const QJsonObject &returnValue() const { return result; } |
49 | }; |
50 | |
51 | class BacktraceJob: public CollectJob |
52 | { |
53 | int fromFrame; |
54 | int toFrame; |
55 | public: |
56 | BacktraceJob(QV4DataCollector *collector, int fromFrame, int toFrame); |
57 | void run() override; |
58 | }; |
59 | |
60 | class FrameJob: public CollectJob |
61 | { |
62 | int frameNr; |
63 | bool success; |
64 | |
65 | public: |
66 | FrameJob(QV4DataCollector *collector, int frameNr); |
67 | void run() override; |
68 | bool wasSuccessful() const; |
69 | }; |
70 | |
71 | class ScopeJob: public CollectJob |
72 | { |
73 | int frameNr; |
74 | int scopeNr; |
75 | bool success; |
76 | |
77 | public: |
78 | ScopeJob(QV4DataCollector *collector, int frameNr, int scopeNr); |
79 | void run() override; |
80 | bool wasSuccessful() const; |
81 | }; |
82 | |
83 | class ValueLookupJob: public CollectJob |
84 | { |
85 | const QJsonArray handles; |
86 | QString exception; |
87 | |
88 | public: |
89 | ValueLookupJob(const QJsonArray &handles, QV4DataCollector *collector); |
90 | void run() override; |
91 | const QString &exceptionMessage() const; |
92 | }; |
93 | |
94 | class ExpressionEvalJob: public JavaScriptJob |
95 | { |
96 | QV4DataCollector *collector; |
97 | QString exception; |
98 | QJsonObject result; |
99 | |
100 | public: |
101 | ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, int context, |
102 | const QString &expression, QV4DataCollector *collector); |
103 | void handleResult(QV4::ScopedValue &value) override; |
104 | const QString &exceptionMessage() const; |
105 | const QJsonObject &returnValue() const; |
106 | }; |
107 | |
108 | class GatherSourcesJob: public QV4DebugJob |
109 | { |
110 | QV4::ExecutionEngine *engine; |
111 | QStringList sources; |
112 | |
113 | public: |
114 | GatherSourcesJob(QV4::ExecutionEngine *engine); |
115 | void run() override; |
116 | const QStringList &result() const; |
117 | }; |
118 | |
119 | class EvalJob: public JavaScriptJob |
120 | { |
121 | bool result; |
122 | |
123 | public: |
124 | EvalJob(QV4::ExecutionEngine *engine, const QString &script); |
125 | |
126 | void handleResult(QV4::ScopedValue &result) override; |
127 | bool resultAsBoolean() const; |
128 | }; |
129 | |
130 | QT_END_NAMESPACE |
131 | |
132 | #endif // QV4DEBUGJOB_H |
133 | |
134 | |