1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSCriptTools 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 "qscriptdebuggerconsoleglobalobject_p.h"
41#include "qscriptdebuggercommandschedulerinterface_p.h"
42#include "qscriptdebuggercommandschedulerfrontend_p.h"
43#include "qscriptmessagehandlerinterface_p.h"
44#include "qscriptdebuggerconsole_p.h"
45#include "qscriptdebuggerconsolecommandmanager_p.h"
46
47#include <private/qobject_p.h>
48
49#include <QtScript/qscriptengine.h>
50
51QT_BEGIN_NAMESPACE
52
53class QScriptDebuggerConsoleGlobalObjectPrivate : public QObjectPrivate
54{
55 Q_DECLARE_PUBLIC(QScriptDebuggerConsoleGlobalObject)
56public:
57 QScriptDebuggerConsoleGlobalObjectPrivate();
58 ~QScriptDebuggerConsoleGlobalObjectPrivate();
59
60 QScriptDebuggerCommandSchedulerInterface *scheduler;
61 QScriptDebuggerResponseHandlerInterface *responseHandler;
62 QScriptMessageHandlerInterface *messageHandler;
63 QScriptDebuggerConsole *console;
64};
65
66QScriptDebuggerConsoleGlobalObjectPrivate::QScriptDebuggerConsoleGlobalObjectPrivate()
67{
68 scheduler = 0;
69 responseHandler = 0;
70 messageHandler = 0;
71 console = 0;
72}
73
74QScriptDebuggerConsoleGlobalObjectPrivate::~QScriptDebuggerConsoleGlobalObjectPrivate()
75{
76}
77
78QScriptDebuggerConsoleGlobalObject::QScriptDebuggerConsoleGlobalObject(QObject *parent)
79 : QObject(*new QScriptDebuggerConsoleGlobalObjectPrivate, parent)
80{
81}
82
83QScriptDebuggerConsoleGlobalObject::~QScriptDebuggerConsoleGlobalObject()
84{
85}
86
87QScriptDebuggerCommandSchedulerInterface *QScriptDebuggerConsoleGlobalObject::scheduler() const
88{
89 Q_D(const QScriptDebuggerConsoleGlobalObject);
90 return d->scheduler;
91}
92
93void QScriptDebuggerConsoleGlobalObject::setScheduler(QScriptDebuggerCommandSchedulerInterface *scheduler)
94{
95 Q_D(QScriptDebuggerConsoleGlobalObject);
96 d->scheduler = scheduler;
97}
98
99QScriptDebuggerResponseHandlerInterface *QScriptDebuggerConsoleGlobalObject::responseHandler() const
100{
101 Q_D(const QScriptDebuggerConsoleGlobalObject);
102 return d->responseHandler;
103}
104
105void QScriptDebuggerConsoleGlobalObject::setResponseHandler(
106 QScriptDebuggerResponseHandlerInterface *responseHandler)
107{
108 Q_D(QScriptDebuggerConsoleGlobalObject);
109 d->responseHandler = responseHandler;
110}
111
112QScriptMessageHandlerInterface *QScriptDebuggerConsoleGlobalObject::messageHandler() const
113{
114 Q_D(const QScriptDebuggerConsoleGlobalObject);
115 return d->messageHandler;
116}
117
118void QScriptDebuggerConsoleGlobalObject::setMessageHandler(QScriptMessageHandlerInterface *messageHandler)
119{
120 Q_D(QScriptDebuggerConsoleGlobalObject);
121 d->messageHandler = messageHandler;
122}
123
124QScriptDebuggerConsole *QScriptDebuggerConsoleGlobalObject::console() const
125{
126 Q_D(const QScriptDebuggerConsoleGlobalObject);
127 return d->console;
128}
129
130void QScriptDebuggerConsoleGlobalObject::setConsole(QScriptDebuggerConsole *console)
131{
132 Q_D(QScriptDebuggerConsoleGlobalObject);
133 d->console = console;
134}
135
136// ### the scheduleXXX functions could take a callback function as argument (rather than using the
137// global handleResponse() function)
138
139int QScriptDebuggerConsoleGlobalObject::scheduleInterrupt()
140{
141 Q_D(QScriptDebuggerConsoleGlobalObject);
142 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
143 return frontend.scheduleInterrupt();
144}
145
146int QScriptDebuggerConsoleGlobalObject::scheduleContinue()
147{
148 Q_D(QScriptDebuggerConsoleGlobalObject);
149 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
150 return frontend.scheduleContinue();
151}
152
153int QScriptDebuggerConsoleGlobalObject::scheduleStepInto(int count)
154{
155 Q_D(QScriptDebuggerConsoleGlobalObject);
156 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
157 return frontend.scheduleStepInto(count);
158}
159
160int QScriptDebuggerConsoleGlobalObject::scheduleStepOver(int count)
161{
162 Q_D(QScriptDebuggerConsoleGlobalObject);
163 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
164 return frontend.scheduleStepOver(count);
165}
166
167int QScriptDebuggerConsoleGlobalObject::scheduleStepOut()
168{
169 Q_D(QScriptDebuggerConsoleGlobalObject);
170 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
171 return frontend.scheduleStepOut();
172}
173
174int QScriptDebuggerConsoleGlobalObject::scheduleRunToLocation(const QString &fileName, int lineNumber)
175{
176 Q_D(QScriptDebuggerConsoleGlobalObject);
177 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
178 return frontend.scheduleRunToLocation(fileName, lineNumber);
179}
180
181int QScriptDebuggerConsoleGlobalObject::scheduleRunToLocation(qint64 scriptId, int lineNumber)
182{
183 Q_D(QScriptDebuggerConsoleGlobalObject);
184 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
185 return frontend.scheduleRunToLocation(scriptId, lineNumber);
186}
187
188int QScriptDebuggerConsoleGlobalObject::scheduleForceReturn(int contextIndex, const QScriptDebuggerValue &value)
189{
190 Q_D(QScriptDebuggerConsoleGlobalObject);
191 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
192 return frontend.scheduleForceReturn(contextIndex, value);
193}
194
195int QScriptDebuggerConsoleGlobalObject::scheduleSetBreakpoint(const QScriptBreakpointData &data)
196{
197 Q_D(QScriptDebuggerConsoleGlobalObject);
198 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
199 return frontend.scheduleSetBreakpoint(data);
200}
201
202int QScriptDebuggerConsoleGlobalObject::scheduleDeleteBreakpoint(int id)
203{
204 Q_D(QScriptDebuggerConsoleGlobalObject);
205 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
206 return frontend.scheduleDeleteBreakpoint(id);
207}
208
209int QScriptDebuggerConsoleGlobalObject::scheduleDeleteAllBreakpoints()
210{
211 Q_D(QScriptDebuggerConsoleGlobalObject);
212 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
213 return frontend.scheduleDeleteAllBreakpoints();
214}
215
216int QScriptDebuggerConsoleGlobalObject::scheduleGetBreakpoints()
217{
218 Q_D(QScriptDebuggerConsoleGlobalObject);
219 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
220 return frontend.scheduleGetBreakpoints();
221}
222
223int QScriptDebuggerConsoleGlobalObject::scheduleGetBreakpointData(int id)
224{
225 Q_D(QScriptDebuggerConsoleGlobalObject);
226 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
227 return frontend.scheduleGetBreakpointData(id);
228}
229
230int QScriptDebuggerConsoleGlobalObject::scheduleSetBreakpointData(int id, const QScriptBreakpointData &data)
231{
232 Q_D(QScriptDebuggerConsoleGlobalObject);
233 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
234 return frontend.scheduleSetBreakpointData(id, data);
235}
236
237int QScriptDebuggerConsoleGlobalObject::scheduleGetScripts()
238{
239 Q_D(QScriptDebuggerConsoleGlobalObject);
240 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
241 return frontend.scheduleGetScripts();
242}
243
244int QScriptDebuggerConsoleGlobalObject::scheduleGetScriptData(qint64 id)
245{
246 Q_D(QScriptDebuggerConsoleGlobalObject);
247 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
248 return frontend.scheduleGetScriptData(id);
249}
250
251int QScriptDebuggerConsoleGlobalObject::scheduleScriptsCheckpoint()
252{
253 Q_D(QScriptDebuggerConsoleGlobalObject);
254 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
255 return frontend.scheduleScriptsCheckpoint();
256}
257
258int QScriptDebuggerConsoleGlobalObject::scheduleGetScriptsDelta()
259{
260 Q_D(QScriptDebuggerConsoleGlobalObject);
261 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
262 return frontend.scheduleGetScriptsDelta();
263}
264
265int QScriptDebuggerConsoleGlobalObject::scheduleResolveScript(const QString &fileName)
266{
267 Q_D(QScriptDebuggerConsoleGlobalObject);
268 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
269 return frontend.scheduleResolveScript(fileName);
270}
271
272int QScriptDebuggerConsoleGlobalObject::scheduleGetBacktrace()
273{
274 Q_D(QScriptDebuggerConsoleGlobalObject);
275 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
276 return frontend.scheduleGetBacktrace();
277}
278
279int QScriptDebuggerConsoleGlobalObject::scheduleGetThisObject(int contextIndex)
280{
281 Q_D(QScriptDebuggerConsoleGlobalObject);
282 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
283 return frontend.scheduleGetThisObject(contextIndex);
284}
285
286int QScriptDebuggerConsoleGlobalObject::scheduleGetActivationObject(int contextIndex)
287{
288 Q_D(QScriptDebuggerConsoleGlobalObject);
289 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
290 return frontend.scheduleGetActivationObject(contextIndex);
291}
292
293int QScriptDebuggerConsoleGlobalObject::scheduleGetContextCount()
294{
295 Q_D(QScriptDebuggerConsoleGlobalObject);
296 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
297 return frontend.scheduleGetContextCount();
298}
299
300int QScriptDebuggerConsoleGlobalObject::scheduleGetContextInfo(int contextIndex)
301{
302 Q_D(QScriptDebuggerConsoleGlobalObject);
303 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
304 return frontend.scheduleGetContextInfo(contextIndex);
305}
306
307int QScriptDebuggerConsoleGlobalObject::scheduleNewScriptValueIterator(const QScriptDebuggerValue &object)
308{
309 Q_D(QScriptDebuggerConsoleGlobalObject);
310 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
311 return frontend.scheduleNewScriptValueIterator(object);
312}
313
314int QScriptDebuggerConsoleGlobalObject::scheduleGetPropertiesByIterator(int id, int count)
315{
316 Q_D(QScriptDebuggerConsoleGlobalObject);
317 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
318 return frontend.scheduleGetPropertiesByIterator(id, count);
319}
320
321int QScriptDebuggerConsoleGlobalObject::scheduleDeleteScriptValueIterator(int id)
322{
323 Q_D(QScriptDebuggerConsoleGlobalObject);
324 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
325 return frontend.scheduleDeleteScriptValueIterator(id);
326}
327
328int QScriptDebuggerConsoleGlobalObject::scheduleEvaluate(int contextIndex, const QString &program,
329 const QString &fileName,
330 int lineNumber)
331{
332 Q_D(QScriptDebuggerConsoleGlobalObject);
333 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
334 return frontend.scheduleEvaluate(contextIndex, program, fileName, lineNumber);
335}
336
337int QScriptDebuggerConsoleGlobalObject::scheduleScriptValueToString(const QScriptDebuggerValue &value)
338{
339 Q_D(QScriptDebuggerConsoleGlobalObject);
340 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
341 return frontend.scheduleScriptValueToString(value);
342}
343
344int QScriptDebuggerConsoleGlobalObject::scheduleClearExceptions()
345{
346 Q_D(QScriptDebuggerConsoleGlobalObject);
347 QScriptDebuggerCommandSchedulerFrontend frontend(d->scheduler, d->responseHandler);
348 return frontend.scheduleClearExceptions();
349}
350
351int QScriptDebuggerConsoleGlobalObject::scheduleCommand(const QScriptDebuggerCommand &command)
352{
353 Q_D(QScriptDebuggerConsoleGlobalObject);
354 return d->scheduler->scheduleCommand(command, responseHandler: d->responseHandler);
355}
356
357void QScriptDebuggerConsoleGlobalObject::warning(const QString &text,
358 const QString &fileName,
359 int lineNumber, int columnNumber)
360{
361 Q_D(QScriptDebuggerConsoleGlobalObject);
362 Q_ASSERT(d->messageHandler != 0);
363 d->messageHandler->message(type: QtWarningMsg, text, fileName, lineNumber, columnNumber);
364}
365
366void QScriptDebuggerConsoleGlobalObject::message(const QString &text,
367 const QString &fileName,
368 int lineNumber, int columnNumber)
369{
370 Q_D(QScriptDebuggerConsoleGlobalObject);
371 Q_ASSERT(d->messageHandler != 0);
372 d->messageHandler->message(type: QtDebugMsg, text, fileName, lineNumber, columnNumber);
373}
374
375void QScriptDebuggerConsoleGlobalObject::error(const QString &text,
376 const QString &fileName,
377 int lineNumber, int columnNumber)
378{
379 Q_D(QScriptDebuggerConsoleGlobalObject);
380 Q_ASSERT(d->messageHandler != 0);
381 d->messageHandler->message(type: QtCriticalMsg, text, fileName, lineNumber, columnNumber);
382}
383
384int QScriptDebuggerConsoleGlobalObject::getCurrentFrameIndex() const
385{
386 Q_D(const QScriptDebuggerConsoleGlobalObject);
387 return d->console->currentFrameIndex();
388}
389
390void QScriptDebuggerConsoleGlobalObject::setCurrentFrameIndex(int index)
391{
392 Q_D(QScriptDebuggerConsoleGlobalObject);
393 d->console->setCurrentFrameIndex(index);
394}
395
396int QScriptDebuggerConsoleGlobalObject::getCurrentLineNumber() const
397{
398 Q_D(const QScriptDebuggerConsoleGlobalObject);
399 return d->console->currentLineNumber();
400}
401
402void QScriptDebuggerConsoleGlobalObject::setCurrentLineNumber(int lineNumber)
403{
404 Q_D(QScriptDebuggerConsoleGlobalObject);
405 d->console->setCurrentLineNumber(lineNumber);
406}
407
408qint64 QScriptDebuggerConsoleGlobalObject::getCurrentScriptId() const
409{
410 Q_D(const QScriptDebuggerConsoleGlobalObject);
411 return d->console->currentScriptId();
412}
413
414void QScriptDebuggerConsoleGlobalObject::setCurrentScriptId(qint64 id)
415{
416 Q_D(QScriptDebuggerConsoleGlobalObject);
417 d->console->setCurrentScriptId(id);
418}
419
420qint64 QScriptDebuggerConsoleGlobalObject::getSessionId() const
421{
422 Q_D(const QScriptDebuggerConsoleGlobalObject);
423 return d->console->sessionId();
424}
425
426QScriptDebuggerConsoleCommandGroupMap QScriptDebuggerConsoleGlobalObject::getCommandGroups() const
427{
428 Q_D(const QScriptDebuggerConsoleGlobalObject);
429 return d->console->commandManager()->commandGroups();
430}
431
432QScriptDebuggerConsoleCommand *QScriptDebuggerConsoleGlobalObject::findCommand(const QString &name) const
433{
434 Q_D(const QScriptDebuggerConsoleGlobalObject);
435 return d->console->commandManager()->findCommand(name);
436}
437
438QScriptDebuggerConsoleCommandList QScriptDebuggerConsoleGlobalObject::getCommandsInGroup(const QString &name) const
439{
440 Q_D(const QScriptDebuggerConsoleGlobalObject);
441 return d->console->commandManager()->commandsInGroup(name);
442}
443
444QStringList QScriptDebuggerConsoleGlobalObject::getCommandCompletions(const QString &prefix) const
445{
446 Q_D(const QScriptDebuggerConsoleGlobalObject);
447 return d->console->commandManager()->completions(prefix);
448}
449
450bool QScriptDebuggerConsoleGlobalObject::checkSyntax(const QString &program)
451{
452 return (QScriptEngine::checkSyntax(program).state() == QScriptSyntaxCheckResult::Valid);
453}
454
455void QScriptDebuggerConsoleGlobalObject::setEvaluateAction(int action)
456{
457 Q_D(QScriptDebuggerConsoleGlobalObject);
458 d->console->setEvaluateAction(action);
459}
460
461QT_END_NAMESPACE
462

source code of qtscript/src/scripttools/debugging/qscriptdebuggerconsoleglobalobject.cpp