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 "qscriptdebuggercommand_p.h" |
41 | #include "qscriptbreakpointdata_p.h" |
42 | #include "qscriptdebuggervalue_p.h" |
43 | |
44 | #include <QtCore/qhash.h> |
45 | #include <QtCore/qdatastream.h> |
46 | #include <QtCore/qstringlist.h> |
47 | |
48 | Q_DECLARE_METATYPE(QScriptBreakpointData) |
49 | Q_DECLARE_METATYPE(QScriptDebuggerValue) |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | /*! |
54 | \since 4.5 |
55 | \class QScriptDebuggerCommand |
56 | \internal |
57 | |
58 | \brief The QScriptDebuggerCommand class represents a command issued to a QScriptDebuggerFrontend. |
59 | |
60 | A debugger command is described by a command type and zero or more |
61 | attributes. Such commands are generated internally by the |
62 | QScriptDebuggerFrontend class (through the scheduleXXX commands). A |
63 | command is typically passed on to a QScriptDebuggerCommandExecutor |
64 | that applies the command to a QScriptDebuggerBackend. |
65 | */ |
66 | |
67 | class QScriptDebuggerCommandPrivate |
68 | { |
69 | public: |
70 | QScriptDebuggerCommandPrivate(); |
71 | ~QScriptDebuggerCommandPrivate(); |
72 | |
73 | QScriptDebuggerCommand::Type type; |
74 | QHash<QScriptDebuggerCommand::Attribute, QVariant> attributes; |
75 | }; |
76 | |
77 | QScriptDebuggerCommandPrivate::QScriptDebuggerCommandPrivate() |
78 | : type(QScriptDebuggerCommand::None) |
79 | { |
80 | } |
81 | |
82 | QScriptDebuggerCommandPrivate::~QScriptDebuggerCommandPrivate() |
83 | { |
84 | } |
85 | |
86 | /*! |
87 | Constructs a QScriptDebuggerCommand of type None. |
88 | */ |
89 | QScriptDebuggerCommand::QScriptDebuggerCommand() |
90 | : d_ptr(new QScriptDebuggerCommandPrivate) |
91 | { |
92 | d_ptr->type = None; |
93 | } |
94 | |
95 | /*! |
96 | Constructs a QScriptDebuggerCommand of the given \a type, with no |
97 | attributes defined. |
98 | */ |
99 | QScriptDebuggerCommand::QScriptDebuggerCommand(Type type) |
100 | : d_ptr(new QScriptDebuggerCommandPrivate) |
101 | { |
102 | d_ptr->type = type; |
103 | } |
104 | |
105 | /*! |
106 | Constructs a QScriptDebuggerCommand that is a copy of the \a other |
107 | command. |
108 | */ |
109 | QScriptDebuggerCommand::QScriptDebuggerCommand(const QScriptDebuggerCommand &other) |
110 | : d_ptr(new QScriptDebuggerCommandPrivate) |
111 | { |
112 | *d_ptr = *other.d_ptr; |
113 | } |
114 | |
115 | /*! |
116 | Destroys this QScriptDebuggerCommand. |
117 | */ |
118 | QScriptDebuggerCommand::~QScriptDebuggerCommand() |
119 | { |
120 | } |
121 | |
122 | /*! |
123 | Assigns the \a other value to this QScriptDebuggerCommand. |
124 | */ |
125 | QScriptDebuggerCommand &QScriptDebuggerCommand::operator=(const QScriptDebuggerCommand &other) |
126 | { |
127 | *d_ptr = *other.d_ptr; |
128 | return *this; |
129 | } |
130 | |
131 | /*! |
132 | Returns the type of this command. |
133 | */ |
134 | QScriptDebuggerCommand::Type QScriptDebuggerCommand::type() const |
135 | { |
136 | Q_D(const QScriptDebuggerCommand); |
137 | return d->type; |
138 | } |
139 | |
140 | /*! |
141 | Returns the value of the given \a attribute, or \a defaultValue |
142 | if the attribute is not defined. |
143 | */ |
144 | QVariant QScriptDebuggerCommand::attribute(Attribute attribute, |
145 | const QVariant &defaultValue) const |
146 | { |
147 | Q_D(const QScriptDebuggerCommand); |
148 | return d->attributes.value(akey: attribute, adefaultValue: defaultValue); |
149 | } |
150 | |
151 | /*! |
152 | Sets the \a value of the given \a attribute. |
153 | */ |
154 | void QScriptDebuggerCommand::setAttribute(Attribute attribute, |
155 | const QVariant &value) |
156 | { |
157 | Q_D(QScriptDebuggerCommand); |
158 | if (!value.isValid()) |
159 | d->attributes.remove(akey: attribute); |
160 | else |
161 | d->attributes[attribute] = value; |
162 | } |
163 | |
164 | QHash<QScriptDebuggerCommand::Attribute, QVariant> QScriptDebuggerCommand::attributes() const |
165 | { |
166 | Q_D(const QScriptDebuggerCommand); |
167 | return d->attributes; |
168 | } |
169 | |
170 | /*! |
171 | Returns the FileName attribute of this command converted to a string. |
172 | This function is provided for convenience. |
173 | |
174 | \sa attribute() |
175 | */ |
176 | QString QScriptDebuggerCommand::fileName() const |
177 | { |
178 | Q_D(const QScriptDebuggerCommand); |
179 | return d->attributes.value(akey: FileName).toString(); |
180 | } |
181 | |
182 | void QScriptDebuggerCommand::setFileName(const QString &fileName) |
183 | { |
184 | Q_D(QScriptDebuggerCommand); |
185 | d->attributes[FileName] = fileName; |
186 | } |
187 | |
188 | /*! |
189 | Returns the LineNumber attribute of this command converted to an int. |
190 | This function is provided for convenience. |
191 | |
192 | \sa attribute() |
193 | */ |
194 | int QScriptDebuggerCommand::lineNumber() const |
195 | { |
196 | Q_D(const QScriptDebuggerCommand); |
197 | return d->attributes.value(akey: LineNumber, adefaultValue: -1).toInt(); |
198 | } |
199 | |
200 | void QScriptDebuggerCommand::setLineNumber(int lineNumber) |
201 | { |
202 | Q_D(QScriptDebuggerCommand); |
203 | d->attributes[LineNumber] = lineNumber; |
204 | } |
205 | |
206 | /*! |
207 | Returns the ScriptID attribute of this command converted to a qint64. |
208 | This function is provided for convenience. |
209 | |
210 | \sa attribute() |
211 | */ |
212 | qint64 QScriptDebuggerCommand::scriptId() const |
213 | { |
214 | Q_D(const QScriptDebuggerCommand); |
215 | return d->attributes.value(akey: ScriptID, adefaultValue: -1).toLongLong(); |
216 | } |
217 | |
218 | void QScriptDebuggerCommand::setScriptId(qint64 id) |
219 | { |
220 | Q_D(QScriptDebuggerCommand); |
221 | d->attributes[ScriptID] = id; |
222 | } |
223 | |
224 | QString QScriptDebuggerCommand::program() const |
225 | { |
226 | Q_D(const QScriptDebuggerCommand); |
227 | return d->attributes.value(akey: Program).toString(); |
228 | } |
229 | |
230 | void QScriptDebuggerCommand::setProgram(const QString &program) |
231 | { |
232 | Q_D(QScriptDebuggerCommand); |
233 | d->attributes[Program] = program; |
234 | } |
235 | |
236 | int QScriptDebuggerCommand::breakpointId() const |
237 | { |
238 | Q_D(const QScriptDebuggerCommand); |
239 | return d->attributes.value(akey: BreakpointID, adefaultValue: -1).toInt(); |
240 | } |
241 | |
242 | void QScriptDebuggerCommand::setBreakpointId(int id) |
243 | { |
244 | Q_D(QScriptDebuggerCommand); |
245 | d->attributes[BreakpointID] = id; |
246 | } |
247 | |
248 | QScriptBreakpointData QScriptDebuggerCommand::breakpointData() const |
249 | { |
250 | Q_D(const QScriptDebuggerCommand); |
251 | return qvariant_cast<QScriptBreakpointData>(v: d->attributes.value(akey: BreakpointData)); |
252 | } |
253 | |
254 | void QScriptDebuggerCommand::setBreakpointData(const QScriptBreakpointData &data) |
255 | { |
256 | Q_D(QScriptDebuggerCommand); |
257 | d->attributes[BreakpointData] = QVariant::fromValue(value: data); |
258 | } |
259 | |
260 | QScriptDebuggerValue QScriptDebuggerCommand::scriptValue() const |
261 | { |
262 | Q_D(const QScriptDebuggerCommand); |
263 | return qvariant_cast<QScriptDebuggerValue>(v: d->attributes.value(akey: ScriptValue)); |
264 | } |
265 | |
266 | void QScriptDebuggerCommand::setScriptValue(const QScriptDebuggerValue &value) |
267 | { |
268 | Q_D(QScriptDebuggerCommand); |
269 | d->attributes[ScriptValue] = QVariant::fromValue(value); |
270 | } |
271 | |
272 | int QScriptDebuggerCommand::contextIndex() const |
273 | { |
274 | Q_D(const QScriptDebuggerCommand); |
275 | return d->attributes.value(akey: ContextIndex, adefaultValue: -1).toInt(); |
276 | } |
277 | |
278 | void QScriptDebuggerCommand::setContextIndex(int index) |
279 | { |
280 | Q_D(QScriptDebuggerCommand); |
281 | d->attributes[ContextIndex] = index; |
282 | } |
283 | |
284 | int QScriptDebuggerCommand::iteratorId() const |
285 | { |
286 | Q_D(const QScriptDebuggerCommand); |
287 | return d->attributes.value(akey: IteratorID, adefaultValue: -1).toInt(); |
288 | } |
289 | |
290 | void QScriptDebuggerCommand::setIteratorId(int id) |
291 | { |
292 | Q_D(QScriptDebuggerCommand); |
293 | d->attributes[IteratorID] = id; |
294 | } |
295 | |
296 | QString QScriptDebuggerCommand::name() const |
297 | { |
298 | Q_D(const QScriptDebuggerCommand); |
299 | return d->attributes.value(akey: Name).toString(); |
300 | } |
301 | |
302 | void QScriptDebuggerCommand::setName(const QString &name) |
303 | { |
304 | Q_D(QScriptDebuggerCommand); |
305 | d->attributes[Name] = name; |
306 | } |
307 | |
308 | QScriptDebuggerValue QScriptDebuggerCommand::subordinateScriptValue() const |
309 | { |
310 | Q_D(const QScriptDebuggerCommand); |
311 | return qvariant_cast<QScriptDebuggerValue>(v: d->attributes.value(akey: SubordinateScriptValue)); |
312 | } |
313 | |
314 | void QScriptDebuggerCommand::setSubordinateScriptValue(const QScriptDebuggerValue &value) |
315 | { |
316 | Q_D(QScriptDebuggerCommand); |
317 | d->attributes[SubordinateScriptValue] = QVariant::fromValue(value); |
318 | } |
319 | |
320 | int QScriptDebuggerCommand::snapshotId() const |
321 | { |
322 | Q_D(const QScriptDebuggerCommand); |
323 | return d->attributes.value(akey: SnapshotID, adefaultValue: -1).toInt(); |
324 | } |
325 | |
326 | void QScriptDebuggerCommand::setSnapshotId(int id) |
327 | { |
328 | Q_D(QScriptDebuggerCommand); |
329 | d->attributes[SnapshotID] = id; |
330 | } |
331 | |
332 | /*! |
333 | Returns true if this QScriptDebuggerCommand is equal to the \a other |
334 | command, otherwise returns false. |
335 | */ |
336 | bool QScriptDebuggerCommand::operator==(const QScriptDebuggerCommand &other) const |
337 | { |
338 | Q_D(const QScriptDebuggerCommand); |
339 | const QScriptDebuggerCommandPrivate *od = other.d_func(); |
340 | if (d == od) |
341 | return true; |
342 | if (!d || !od) |
343 | return false; |
344 | return ((d->type == od->type) |
345 | && (d->attributes == od->attributes)); |
346 | } |
347 | |
348 | /*! |
349 | Returns true if this QScriptDebuggerCommand is not equal to the \a |
350 | other command, otherwise returns false. |
351 | */ |
352 | bool QScriptDebuggerCommand::operator!=(const QScriptDebuggerCommand &other) const |
353 | { |
354 | return !(*this == other); |
355 | } |
356 | |
357 | QScriptDebuggerCommand QScriptDebuggerCommand::interruptCommand() |
358 | { |
359 | QScriptDebuggerCommand cmd(Interrupt); |
360 | return cmd; |
361 | } |
362 | |
363 | QScriptDebuggerCommand QScriptDebuggerCommand::continueCommand() |
364 | { |
365 | QScriptDebuggerCommand cmd(Continue); |
366 | return cmd; |
367 | } |
368 | |
369 | QScriptDebuggerCommand QScriptDebuggerCommand::stepIntoCommand(int count) |
370 | { |
371 | QScriptDebuggerCommand cmd(StepInto); |
372 | cmd.setAttribute(attribute: StepCount, value: count); |
373 | return cmd; |
374 | } |
375 | |
376 | QScriptDebuggerCommand QScriptDebuggerCommand::stepOverCommand(int count) |
377 | { |
378 | QScriptDebuggerCommand cmd(StepOver); |
379 | cmd.setAttribute(attribute: StepCount, value: count); |
380 | return cmd; |
381 | } |
382 | |
383 | QScriptDebuggerCommand QScriptDebuggerCommand::stepOutCommand() |
384 | { |
385 | QScriptDebuggerCommand cmd(StepOut); |
386 | return cmd; |
387 | } |
388 | |
389 | QScriptDebuggerCommand QScriptDebuggerCommand::runToLocationCommand(const QString &fileName, int lineNumber) |
390 | { |
391 | QScriptDebuggerCommand cmd(RunToLocation); |
392 | cmd.setFileName(fileName); |
393 | cmd.setLineNumber(lineNumber); |
394 | return cmd; |
395 | } |
396 | |
397 | QScriptDebuggerCommand QScriptDebuggerCommand::runToLocationCommand(qint64 scriptId, int lineNumber) |
398 | { |
399 | QScriptDebuggerCommand cmd(RunToLocationByID); |
400 | cmd.setScriptId(scriptId); |
401 | cmd.setLineNumber(lineNumber); |
402 | return cmd; |
403 | } |
404 | |
405 | QScriptDebuggerCommand QScriptDebuggerCommand::forceReturnCommand(int contextIndex, const QScriptDebuggerValue &value) |
406 | { |
407 | QScriptDebuggerCommand cmd(ForceReturn); |
408 | cmd.setContextIndex(contextIndex); |
409 | cmd.setScriptValue(value); |
410 | return cmd; |
411 | } |
412 | |
413 | QScriptDebuggerCommand QScriptDebuggerCommand::resumeCommand() |
414 | { |
415 | QScriptDebuggerCommand cmd(Resume); |
416 | return cmd; |
417 | } |
418 | |
419 | QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointCommand(const QString &fileName, int lineNumber) |
420 | { |
421 | QScriptDebuggerCommand cmd(SetBreakpoint); |
422 | cmd.setBreakpointData(QScriptBreakpointData(fileName, lineNumber)); |
423 | return cmd; |
424 | } |
425 | |
426 | QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointCommand(const QScriptBreakpointData &data) |
427 | { |
428 | QScriptDebuggerCommand cmd(SetBreakpoint); |
429 | cmd.setBreakpointData(data); |
430 | return cmd; |
431 | } |
432 | |
433 | QScriptDebuggerCommand QScriptDebuggerCommand::deleteBreakpointCommand(int id) |
434 | { |
435 | QScriptDebuggerCommand cmd(DeleteBreakpoint); |
436 | cmd.setBreakpointId(id); |
437 | return cmd; |
438 | } |
439 | |
440 | QScriptDebuggerCommand QScriptDebuggerCommand::deleteAllBreakpointsCommand() |
441 | { |
442 | QScriptDebuggerCommand cmd(DeleteAllBreakpoints); |
443 | return cmd; |
444 | } |
445 | |
446 | QScriptDebuggerCommand QScriptDebuggerCommand::getBreakpointsCommand() |
447 | { |
448 | QScriptDebuggerCommand cmd(GetBreakpoints); |
449 | return cmd; |
450 | } |
451 | |
452 | QScriptDebuggerCommand QScriptDebuggerCommand::getBreakpointDataCommand(int id) |
453 | { |
454 | QScriptDebuggerCommand cmd(GetBreakpointData); |
455 | cmd.setBreakpointId(id); |
456 | return cmd; |
457 | } |
458 | |
459 | QScriptDebuggerCommand QScriptDebuggerCommand::setBreakpointDataCommand(int id, const QScriptBreakpointData &data) |
460 | { |
461 | QScriptDebuggerCommand cmd(SetBreakpointData); |
462 | cmd.setBreakpointId(id); |
463 | cmd.setBreakpointData(data); |
464 | return cmd; |
465 | } |
466 | |
467 | QScriptDebuggerCommand QScriptDebuggerCommand::getScriptsCommand() |
468 | { |
469 | QScriptDebuggerCommand cmd(GetScripts); |
470 | return cmd; |
471 | } |
472 | |
473 | QScriptDebuggerCommand QScriptDebuggerCommand::getScriptDataCommand(qint64 id) |
474 | { |
475 | QScriptDebuggerCommand cmd(GetScriptData); |
476 | cmd.setScriptId(id); |
477 | return cmd; |
478 | } |
479 | |
480 | QScriptDebuggerCommand QScriptDebuggerCommand::scriptsCheckpointCommand() |
481 | { |
482 | QScriptDebuggerCommand cmd(ScriptsCheckpoint); |
483 | return cmd; |
484 | } |
485 | |
486 | QScriptDebuggerCommand QScriptDebuggerCommand::getScriptsDeltaCommand() |
487 | { |
488 | QScriptDebuggerCommand cmd(GetScriptsDelta); |
489 | return cmd; |
490 | } |
491 | |
492 | QScriptDebuggerCommand QScriptDebuggerCommand::resolveScriptCommand(const QString &fileName) |
493 | { |
494 | QScriptDebuggerCommand cmd(ResolveScript); |
495 | cmd.setFileName(fileName); |
496 | return cmd; |
497 | } |
498 | |
499 | QScriptDebuggerCommand QScriptDebuggerCommand::getBacktraceCommand() |
500 | { |
501 | QScriptDebuggerCommand cmd(GetBacktrace); |
502 | return cmd; |
503 | } |
504 | |
505 | QScriptDebuggerCommand QScriptDebuggerCommand::getContextCountCommand() |
506 | { |
507 | QScriptDebuggerCommand cmd(GetContextCount); |
508 | return cmd; |
509 | } |
510 | |
511 | QScriptDebuggerCommand QScriptDebuggerCommand::getContextStateCommand(int contextIndex) |
512 | { |
513 | QScriptDebuggerCommand cmd(GetContextState); |
514 | cmd.setContextIndex(contextIndex); |
515 | return cmd; |
516 | } |
517 | |
518 | QScriptDebuggerCommand QScriptDebuggerCommand::getContextInfoCommand(int contextIndex) |
519 | { |
520 | QScriptDebuggerCommand cmd(GetContextInfo); |
521 | cmd.setContextIndex(contextIndex); |
522 | return cmd; |
523 | } |
524 | |
525 | QScriptDebuggerCommand QScriptDebuggerCommand::getContextIdCommand(int contextIndex) |
526 | { |
527 | QScriptDebuggerCommand cmd(GetContextID); |
528 | cmd.setContextIndex(contextIndex); |
529 | return cmd; |
530 | } |
531 | |
532 | QScriptDebuggerCommand QScriptDebuggerCommand::getThisObjectCommand(int contextIndex) |
533 | { |
534 | QScriptDebuggerCommand cmd(GetThisObject); |
535 | cmd.setContextIndex(contextIndex); |
536 | return cmd; |
537 | } |
538 | |
539 | QScriptDebuggerCommand QScriptDebuggerCommand::getActivationObjectCommand(int contextIndex) |
540 | { |
541 | QScriptDebuggerCommand cmd(GetActivationObject); |
542 | cmd.setContextIndex(contextIndex); |
543 | return cmd; |
544 | } |
545 | |
546 | QScriptDebuggerCommand QScriptDebuggerCommand::getScopeChainCommand(int contextIndex) |
547 | { |
548 | QScriptDebuggerCommand cmd(GetScopeChain); |
549 | cmd.setContextIndex(contextIndex); |
550 | return cmd; |
551 | } |
552 | |
553 | QScriptDebuggerCommand QScriptDebuggerCommand::contextsCheckpoint() |
554 | { |
555 | QScriptDebuggerCommand cmd(ContextsCheckpoint); |
556 | return cmd; |
557 | } |
558 | |
559 | QScriptDebuggerCommand QScriptDebuggerCommand::getPropertyExpressionValue( |
560 | int contextIndex, int lineNumber, const QStringList &path) |
561 | { |
562 | QScriptDebuggerCommand cmd(GetPropertyExpressionValue); |
563 | cmd.setContextIndex(contextIndex); |
564 | cmd.setLineNumber(lineNumber); |
565 | cmd.setAttribute(attribute: UserAttribute, value: path); |
566 | return cmd; |
567 | } |
568 | |
569 | QScriptDebuggerCommand QScriptDebuggerCommand::getCompletions( |
570 | int contextIndex, const QStringList &path) |
571 | { |
572 | QScriptDebuggerCommand cmd(GetCompletions); |
573 | cmd.setContextIndex(contextIndex); |
574 | cmd.setAttribute(attribute: UserAttribute, value: path); |
575 | return cmd; |
576 | } |
577 | |
578 | QScriptDebuggerCommand QScriptDebuggerCommand::newScriptObjectSnapshotCommand() |
579 | { |
580 | QScriptDebuggerCommand cmd(NewScriptObjectSnapshot); |
581 | return cmd; |
582 | } |
583 | |
584 | QScriptDebuggerCommand QScriptDebuggerCommand::scriptObjectSnapshotCaptureCommand(int id, const QScriptDebuggerValue &object) |
585 | { |
586 | Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue); |
587 | QScriptDebuggerCommand cmd(ScriptObjectSnapshotCapture); |
588 | cmd.setSnapshotId(id); |
589 | cmd.setScriptValue(object); |
590 | return cmd; |
591 | } |
592 | |
593 | QScriptDebuggerCommand QScriptDebuggerCommand::deleteScriptObjectSnapshotCommand(int id) |
594 | { |
595 | QScriptDebuggerCommand cmd(DeleteScriptObjectSnapshot); |
596 | cmd.setSnapshotId(id); |
597 | return cmd; |
598 | } |
599 | |
600 | QScriptDebuggerCommand QScriptDebuggerCommand::newScriptValueIteratorCommand(const QScriptDebuggerValue &object) |
601 | { |
602 | QScriptDebuggerCommand cmd(NewScriptValueIterator); |
603 | Q_ASSERT(object.type() == QScriptDebuggerValue::ObjectValue); |
604 | cmd.setScriptValue(object); |
605 | return cmd; |
606 | } |
607 | |
608 | QScriptDebuggerCommand QScriptDebuggerCommand::getPropertiesByIteratorCommand(int id, int count) |
609 | { |
610 | Q_UNUSED(count); |
611 | QScriptDebuggerCommand cmd(GetPropertiesByIterator); |
612 | cmd.setIteratorId(id); |
613 | return cmd; |
614 | } |
615 | |
616 | QScriptDebuggerCommand QScriptDebuggerCommand::deleteScriptValueIteratorCommand(int id) |
617 | { |
618 | QScriptDebuggerCommand cmd(DeleteScriptValueIterator); |
619 | cmd.setIteratorId(id); |
620 | return cmd; |
621 | } |
622 | |
623 | QScriptDebuggerCommand QScriptDebuggerCommand::evaluateCommand( |
624 | int contextIndex, const QString &program, const QString &fileName, int lineNumber) |
625 | { |
626 | QScriptDebuggerCommand cmd(Evaluate); |
627 | cmd.setContextIndex(contextIndex); |
628 | cmd.setProgram(program); |
629 | cmd.setFileName(fileName); |
630 | cmd.setLineNumber(lineNumber); |
631 | return cmd; |
632 | } |
633 | |
634 | QScriptDebuggerCommand QScriptDebuggerCommand::scriptValueToStringCommand(const QScriptDebuggerValue &value) |
635 | { |
636 | QScriptDebuggerCommand cmd(ScriptValueToString); |
637 | cmd.setScriptValue(value); |
638 | return cmd; |
639 | } |
640 | |
641 | QScriptDebuggerCommand QScriptDebuggerCommand::setScriptValuePropertyCommand( |
642 | const QScriptDebuggerValue &object, const QString &name, |
643 | const QScriptDebuggerValue &value) |
644 | { |
645 | QScriptDebuggerCommand cmd(SetScriptValueProperty); |
646 | cmd.setScriptValue(object); |
647 | cmd.setName(name); |
648 | cmd.setSubordinateScriptValue(value); |
649 | return cmd; |
650 | } |
651 | |
652 | QScriptDebuggerCommand QScriptDebuggerCommand::clearExceptionsCommand() |
653 | { |
654 | QScriptDebuggerCommand cmd(ClearExceptions); |
655 | return cmd; |
656 | } |
657 | |
658 | /*! |
659 | \relates QScriptDebuggerCommand |
660 | |
661 | Writes the given \a command to the specified \a stream. |
662 | */ |
663 | QDataStream &operator<<(QDataStream &out, const QScriptDebuggerCommand &command) |
664 | { |
665 | const QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); |
666 | out << (quint32)d->type; |
667 | out << (qint32)d->attributes.size(); |
668 | QHash<QScriptDebuggerCommand::Attribute, QVariant>::const_iterator it; |
669 | for (it = d->attributes.constBegin(); it != d->attributes.constEnd(); ++it) { |
670 | out << (quint32)it.key(); |
671 | out << it.value(); |
672 | } |
673 | return out; |
674 | } |
675 | |
676 | /*! |
677 | \relates QScriptDebuggerCommand |
678 | |
679 | Reads a QScriptDebuggerCommand from the specified \a stream into the |
680 | given \a command. |
681 | */ |
682 | QDataStream &operator>>(QDataStream &in, QScriptDebuggerCommand &command) |
683 | { |
684 | QScriptDebuggerCommandPrivate *d = command.d_ptr.data(); |
685 | |
686 | quint32 type; |
687 | in >> type; |
688 | d->type = QScriptDebuggerCommand::Type(type); |
689 | |
690 | qint32 attribCount; |
691 | in >> attribCount; |
692 | QHash<QScriptDebuggerCommand::Attribute, QVariant> attribs; |
693 | for (qint32 i = 0; i < attribCount; ++i) { |
694 | quint32 key; |
695 | in >> key; |
696 | QVariant value; |
697 | in >> value; |
698 | attribs[QScriptDebuggerCommand::Attribute(key)] = value; |
699 | } |
700 | d->attributes = attribs; |
701 | |
702 | return in; |
703 | } |
704 | |
705 | QT_END_NAMESPACE |
706 | |