scriptengine.cpp 20.6 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
7
8
**
** Contact:  Qt Software Information (qt-info@nokia.com)
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
**
25
26
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
con's avatar
con committed
27
**
28
**************************************************************************/
con's avatar
con committed
29
30
31

#include "scriptengine.h"

32
#include "debuggerdialogs.h"
hjk's avatar
hjk committed
33
#include "breakhandler.h"
con's avatar
con committed
34
35
36
37
38
39
40
#include "debuggerconstants.h"
#include "debuggermanager.h"
#include "disassemblerhandler.h"
#include "moduleshandler.h"
#include "registerhandler.h"
#include "stackhandler.h"
#include "watchhandler.h"
hjk's avatar
hjk committed
41
#include "watchutils.h"
42
#include "moduleshandler.h"
con's avatar
con committed
43

hjk's avatar
hjk committed
44
#include <utils/qtcassert.h>
con's avatar
con committed
45

46
47
48
49
50
#include <qtscripteditor/qtscripteditorconstants.h>

#include <texteditor/itexteditor.h>
#include <coreplugin/ifile.h>

con's avatar
con committed
51
52
53
54
55
56
57
#include <QtCore/QDateTime>
#include <QtCore/QDebug>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>

#include <QtGui/QAction>
58
#include <QtGui/QApplication>
con's avatar
con committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <QtGui/QToolTip>

#include <QtScript/QScriptContext>
#include <QtScript/QScriptClassPropertyIterator>
#include <QtScript/QScriptContextInfo>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptEngineAgent>
#include <QtScript/QScriptValue>
#include <QtScript/QScriptValueIterator>

using namespace Debugger;
using namespace Debugger::Internal;
using namespace Debugger::Constants;

hjk's avatar
hjk committed
73
74
75
76
77
78
//#define DEBUG_SCRIPT 1
#if DEBUG_SCRIPT
#   define SDEBUG(s) qDebug() << s
#else
#   define SDEBUG(s)
#endif
79
# define XSDEBUG(s) qDebug() << s
con's avatar
con committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

///////////////////////////////////////////////////////////////////////
//
// ScriptEngine
//
///////////////////////////////////////////////////////////////////////

class Debugger::Internal::ScriptAgent : public QScriptEngineAgent
{
public:
    ScriptAgent(ScriptEngine *debugger, QScriptEngine *script);
    ~ScriptAgent() {}

    void contextPop();
    void contextPush();
    void exceptionCatch(qint64 scriptId, const QScriptValue &exception);
    void exceptionThrow(qint64 scriptId, const QScriptValue & exception,
        bool hasHandler);
    void functionEntry(qint64 scriptId);
    void functionExit(qint64 scriptId, const QScriptValue &returnValue);
    void positionChange(qint64 scriptId, int lineNumber, int columnNumber);
    void scriptLoad(qint64 id, const QString &program, const QString &fileName,
        int baseLineNumber);
    void scriptUnload(qint64 id);

private:
    void maybeBreakNow(bool byFunction);

    ScriptEngine *q; 
};

ScriptAgent::ScriptAgent(ScriptEngine *debugger, QScriptEngine *script)
  : QScriptEngineAgent(script), q(debugger)
{}

void ScriptAgent::contextPop()
{
hjk's avatar
hjk committed
117
    SDEBUG("ScriptAgent::contextPop: ");
con's avatar
con committed
118
119
120
121
}

void ScriptAgent::contextPush()
{
hjk's avatar
hjk committed
122
    SDEBUG("ScriptAgent::contextPush: ");
con's avatar
con committed
123
124
125
126
}

void ScriptAgent::exceptionCatch(qint64 scriptId, const QScriptValue & exception)
{
hjk's avatar
hjk committed
127
128
129
    Q_UNUSED(scriptId);
    Q_UNUSED(exception);
    SDEBUG("ScriptAgent::exceptionCatch: " << scriptId << &exception);
con's avatar
con committed
130
131
132
133
134
}

void ScriptAgent::exceptionThrow(qint64 scriptId, const QScriptValue &exception,
    bool hasHandler)
{
hjk's avatar
hjk committed
135
136
137
138
139
    Q_UNUSED(scriptId);
    Q_UNUSED(exception);
    Q_UNUSED(hasHandler);
    SDEBUG("ScriptAgent::exceptionThrow: " << scriptId << &exception
        << hasHandler);
con's avatar
con committed
140
141
142
143
144
145
146
147
148
149
}

void ScriptAgent::functionEntry(qint64 scriptId)
{
    Q_UNUSED(scriptId);
    q->maybeBreakNow(true);
}

void ScriptAgent::functionExit(qint64 scriptId, const QScriptValue &returnValue)
{
hjk's avatar
hjk committed
150
151
152
    Q_UNUSED(scriptId);
    Q_UNUSED(returnValue);
    SDEBUG("ScriptAgent::functionExit: " << scriptId << &returnValue);
con's avatar
con committed
153
154
155
156
}

void ScriptAgent::positionChange(qint64 scriptId, int lineNumber, int columnNumber)
{
hjk's avatar
hjk committed
157
    SDEBUG("ScriptAgent::position: " << lineNumber);
con's avatar
con committed
158
159
160
161
162
163
164
165
166
167
168
169
170
    Q_UNUSED(scriptId);
    Q_UNUSED(lineNumber);
    Q_UNUSED(columnNumber);
    q->maybeBreakNow(false);
}

void ScriptAgent::scriptLoad(qint64 scriptId, const QString &program,
    const QString &fileName, int baseLineNumber)
{
    Q_UNUSED(scriptId);
    Q_UNUSED(program);
    Q_UNUSED(fileName);
    Q_UNUSED(baseLineNumber);
hjk's avatar
hjk committed
171
172
    SDEBUG("ScriptAgent::scriptLoad: " << program << fileName
      << baseLineNumber);
con's avatar
con committed
173
174
175
176
177
}

void ScriptAgent::scriptUnload(qint64 scriptId)
{
    Q_UNUSED(scriptId);
hjk's avatar
hjk committed
178
    SDEBUG("ScriptAgent::scriptUnload: " << scriptId);
con's avatar
con committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
}


///////////////////////////////////////////////////////////////////////
//
// ScriptEngine
//
///////////////////////////////////////////////////////////////////////

ScriptEngine::ScriptEngine(DebuggerManager *parent)
{
    q = parent;
    qq = parent->engineInterface();
    m_scriptEngine = new QScriptEngine(this);
    m_scriptAgent = new ScriptAgent(this, m_scriptEngine);
    m_scriptEngine->setAgent(m_scriptAgent);
    m_scriptEngine->setProcessEventsInterval(1 /*ms*/);
}

ScriptEngine::~ScriptEngine()
{
}

void ScriptEngine::executeDebuggerCommand(const QString &command)
{
    Q_UNUSED(command);
205
    XSDEBUG("FIXME:  ScriptEngine::executeDebuggerCommand()");
con's avatar
con committed
206
207
208
209
210
211
212
213
214
}

void ScriptEngine::shutdown()
{
    exitDebugger(); 
}

void ScriptEngine::exitDebugger()
{
hjk's avatar
hjk committed
215
    SDEBUG("ScriptEngine::exitDebugger()");
con's avatar
con committed
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    m_stopped = false;
    m_stopOnNextLine = false;
    m_scriptEngine->abortEvaluation();
    qq->notifyInferiorExited();
}

bool ScriptEngine::startDebugger()
{
    m_stopped = false;
    m_stopOnNextLine = false;
    m_scriptEngine->abortEvaluation();
    QFileInfo fi(q->m_executable);
    m_scriptFileName = fi.absoluteFilePath();
    QFile scriptFile(m_scriptFileName);
    if (!scriptFile.open(QIODevice::ReadOnly))
        return false;
    QTextStream stream(&scriptFile);
    m_scriptContents = stream.readAll();
    scriptFile.close();
    attemptBreakpointSynchronization();
hjk's avatar
hjk committed
236
237
    qq->notifyInferiorRunningRequested();
    QTimer::singleShot(0, this, SLOT(runInferior()));
con's avatar
con committed
238
239
240
241
242
    return true;
}

void ScriptEngine::continueInferior()
{
hjk's avatar
hjk committed
243
    SDEBUG("ScriptEngine::continueInferior()");
con's avatar
con committed
244
245
246
247
248
249
    m_stopped = false;
    m_stopOnNextLine = false;
}

void ScriptEngine::runInferior()
{
250
251
252
253
254
255
256
257
258
259
260
261
262
263
    //QDir dir(QApplication::applicationDirPath());
    //if (dir.dirName() == QLatin1String("debug") || dir.dirName() == QLatin1String("release"))
    //    dir.cdUp();
    //dir.cdUp();
    //dir.cdUp();
    QDir dir("/home/apoenitz/dev/qtscriptgenerator");
    if (!dir.cd("plugins")) {
        fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
        return;
    }
    QStringList paths = qApp->libraryPaths();
    paths <<  dir.absolutePath();
    qApp->setLibraryPaths(paths);

hjk's avatar
hjk committed
264
    SDEBUG("ScriptEngine::runInferior()");
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
    QStringList extensions;
    extensions << "qt.core"
               << "qt.gui"
               << "qt.xml"
               << "qt.svg"
               << "qt.network"
               << "qt.sql"
               << "qt.opengl"
               << "qt.webkit"
               << "qt.xmlpatterns"
               << "qt.uitools";
    QStringList failExtensions;
    foreach (const QString &ext, extensions) {
        QScriptValue ret = m_scriptEngine->importExtension(ext);
        if (ret.isError())
            failExtensions.append(ext);
    }
    if (!failExtensions.isEmpty()) {
        if (failExtensions.size() == extensions.size()) {
            qWarning("Failed to import Qt bindings!\n"
                     "Plugins directory searched: %s/script\n"
                     "Make sure that the bindings have been built, "
                     "and that this executable and the plugins are "
                     "using compatible Qt libraries.", qPrintable(dir.absolutePath()));
        } else {
            qWarning("Failed to import some Qt bindings: %s\n"
                     "Plugins directory searched: %s/script\n"
                     "Make sure that the bindings have been built, "
                     "and that this executable and the plugins are "
                     "using compatible Qt libraries.",
                     qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath()));
        }
    }

con's avatar
con committed
299
300
301
302
303
304
305
    QScriptValue result = m_scriptEngine->evaluate(m_scriptContents, m_scriptFileName);
}

void ScriptEngine::interruptInferior()
{
    m_stopped = false;
    m_stopOnNextLine = true;
306
    XSDEBUG("ScriptEngine::interruptInferior()");
con's avatar
con committed
307
308
309
310
}

void ScriptEngine::stepExec()
{
311
    //SDEBUG("ScriptEngine::stepExec()");
con's avatar
con committed
312
313
314
315
316
317
    m_stopped = false;
    m_stopOnNextLine = true;
}

void ScriptEngine::stepIExec()
{
318
    //SDEBUG("ScriptEngine::stepIExec()");
con's avatar
con committed
319
320
321
322
323
324
    m_stopped = false;
    m_stopOnNextLine = true;
}

void ScriptEngine::stepOutExec()
{
325
    //SDEBUG("ScriptEngine::stepOutExec()");
con's avatar
con committed
326
327
328
329
330
331
    m_stopped = false;
    m_stopOnNextLine = true;
}

void ScriptEngine::nextExec()
{
332
    //SDEBUG("ScriptEngine::nextExec()");
con's avatar
con committed
333
334
335
336
337
338
    m_stopped = false;
    m_stopOnNextLine = true;
}

void ScriptEngine::nextIExec()
{
339
    //SDEBUG("ScriptEngine::nextIExec()");
con's avatar
con committed
340
341
342
343
344
345
346
347
    m_stopped = false;
    m_stopOnNextLine = true;
}

void ScriptEngine::runToLineExec(const QString &fileName, int lineNumber)
{
    Q_UNUSED(fileName);
    Q_UNUSED(lineNumber);
hjk's avatar
hjk committed
348
    SDEBUG("FIXME:  ScriptEngine::runToLineExec()");
con's avatar
con committed
349
350
351
352
353
}

void ScriptEngine::runToFunctionExec(const QString &functionName)
{
    Q_UNUSED(functionName);
354
    XSDEBUG("FIXME:  ScriptEngine::runToFunctionExec()");
con's avatar
con committed
355
356
357
358
359
360
}

void ScriptEngine::jumpToLineExec(const QString &fileName, int lineNumber)
{
    Q_UNUSED(fileName);
    Q_UNUSED(lineNumber);
361
    XSDEBUG("FIXME:  ScriptEngine::jumpToLineExec()");
con's avatar
con committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
}

void ScriptEngine::activateFrame(int index)
{
    Q_UNUSED(index);
}

void ScriptEngine::selectThread(int index)
{
    Q_UNUSED(index);
}

void ScriptEngine::attemptBreakpointSynchronization()
{
    BreakHandler *handler = qq->breakHandler();
    bool updateNeeded = false;
    for (int index = 0; index != handler->size(); ++index) {
        BreakpointData *data = handler->at(index);
        if (data->pending) {
            data->pending = false; // FIXME
            updateNeeded = true;
        }
        if (data->bpNumber.isEmpty()) {
            data->bpNumber = QString::number(index + 1);
            updateNeeded = true;
        }
        if (!data->fileName.isEmpty() && data->markerFileName.isEmpty()) {
            data->markerFileName = data->fileName;
            data->markerLineNumber = data->lineNumber.toInt();
            updateNeeded = true;
        }
    }
    if (updateNeeded)
        handler->updateMarkers();
}

void ScriptEngine::reloadDisassembler()
{
}

void ScriptEngine::loadSymbols(const QString &moduleName)
{
    Q_UNUSED(moduleName);
}

void ScriptEngine::loadAllSymbols()
{
}

void ScriptEngine::reloadModules()
{
}

415
416
417
418
QList<Symbol> ScriptEngine::moduleSymbols(const QString & /*moduleName*/)
{
    return QList<Symbol>();
}
con's avatar
con committed
419
420
421
422
423
424
425
426
427
428
429
430


//////////////////////////////////////////////////////////////////////
//
// Tooltip specific stuff
//
//////////////////////////////////////////////////////////////////////

static WatchData m_toolTip;
static QPoint m_toolTipPos;
static QHash<QString, WatchData> m_toolTipCache;

431
void ScriptEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos)
con's avatar
con committed
432
{
433
434
435
    Q_UNUSED(mousePos);
    Q_UNUSED(editor);
    Q_UNUSED(cursorPos);
con's avatar
con committed
436
437

    if (q->status() != DebuggerInferiorStopped) {
hjk's avatar
hjk committed
438
        //SDEBUG("SUPPRESSING DEBUGGER TOOLTIP, INFERIOR NOT STOPPED");
con's avatar
con committed
439
440
        return;
    }
441
442
443
444
    // Check mime type and get expression (borrowing some C++ - functions)
    const QString javaScriptMimeType = QLatin1String(QtScriptEditor::Constants::C_QTSCRIPTEDITOR_MIMETYPE);
    if (!editor->file() || editor->file()->mimeType() != javaScriptMimeType)
        return;
con's avatar
con committed
445

446
447
448
    int line;
    int column;
    QString exp = cppExpressionAt(editor, cursorPos, &line, &column);
con's avatar
con committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465

/*
    if (m_toolTipCache.contains(exp)) {
        const WatchData & data = m_toolTipCache[exp];
        q->watchHandler()->removeChildren(data.iname);
        insertData(data);
        return;
    }
*/

    QToolTip::hideText();
    if (exp.isEmpty() || exp.startsWith("#"))  {
        QToolTip::hideText();
        return;
    }

    if (!hasLetterOrNumber(exp)) {
466
        QToolTip::showText(m_toolTipPos, tr("'%1' contains no identifier").arg(exp));
con's avatar
con committed
467
468
469
470
        return;
    }

    if (exp.startsWith('"') && exp.endsWith('"'))  {
471
        QToolTip::showText(m_toolTipPos, tr("String literal %1").arg(exp));
con's avatar
con committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
        return;
    }

    if (exp.startsWith("++") || exp.startsWith("--"))
        exp = exp.mid(2);

    if (exp.endsWith("++") || exp.endsWith("--"))
        exp = exp.mid(2);

    if (exp.startsWith("<") || exp.startsWith("["))
        return;

    if (hasSideEffects(exp)) {
        QToolTip::showText(m_toolTipPos,
486
487
            tr("Cowardly refusing to evaluate expression '%1' "
               "with potential side effects").arg(exp));
con's avatar
con committed
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
        return;
    }

#if 0
    //if (m_manager->status() != DebuggerInferiorStopped)
    //    return;

    // FIXME: 'exp' can contain illegal characters
    m_toolTip = WatchData();
    m_toolTip.exp = exp;
    m_toolTip.name = exp;
    m_toolTip.iname = tooltipIName;
    insertData(m_toolTip);
#endif
}


//////////////////////////////////////////////////////////////////////
//
// Watch specific stuff
//
//////////////////////////////////////////////////////////////////////

void ScriptEngine::assignValueInDebugger(const QString &expression,
    const QString &value)
{
514
515
516
    XSDEBUG("ASSIGNING: " << expression + '=' + value);
    m_scriptEngine->evaluate(expression + '=' + value);
    updateLocals();
con's avatar
con committed
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
}

void ScriptEngine::maybeBreakNow(bool byFunction)
{
    QScriptContext *context = m_scriptEngine->currentContext();
    QScriptContextInfo info(context);

    //
    // Update breakpoints
    //
    QString functionName = info.functionName();
    QString fileName = info.fileName();
    int lineNumber = info.lineNumber();
    if (byFunction)
        lineNumber = info.functionStartLineNumber();

    BreakHandler *handler = qq->breakHandler();

    if (m_stopOnNextLine) {
        m_stopOnNextLine = false;
    } else {
        int index = 0;
        for (; index != handler->size(); ++index) {
            BreakpointData *data = handler->at(index);
            if (byFunction) {
                if (!functionName.isEmpty() && data->funcName == functionName)
                    break;
            } else {
                if (info.lineNumber() == data->lineNumber.toInt()
                        && fileName == data->fileName)
                    break;
            }
        }

        if (index == handler->size())
            return;

        // we just run into a breakpoint
hjk's avatar
hjk committed
555
        //SDEBUG("RESOLVING BREAKPOINT AT " << fileName << lineNumber);
con's avatar
con committed
556
557
558
559
560
561
562
563
564
565
566
567
        BreakpointData *data = handler->at(index);
        data->bpLineNumber = QString::number(lineNumber);
        data->bpFileName = fileName;
        data->bpFuncName = functionName;
        data->markerLineNumber = lineNumber;
        data->markerFileName = fileName;
        data->pending = false;
        data->updateMarker();
    }

    qq->notifyInferiorStopped();
    q->gotoLocation(fileName, lineNumber, true);
568
569
    updateLocals();
}
con's avatar
con committed
570

571
572
573
void ScriptEngine::updateLocals()
{
    QScriptContext *context = m_scriptEngine->currentContext();
con's avatar
con committed
574
    qq->watchHandler()->reinitializeWatchers();
hjk's avatar
hjk committed
575
    //SDEBUG("UPDATE LOCALS");
con's avatar
con committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

    //
    // Build stack
    //  
    QList<StackFrame> stackFrames;
    int i = 0;
    for (QScriptContext *c = context; c; c = c->parentContext(), ++i) {
        QScriptContextInfo info(c);
        StackFrame frame;
        frame.level = i;
        frame.file = info.fileName();
        frame.function = info.functionName();
        frame.from = QString::number(info.functionStartLineNumber());
        frame.to = QString::number(info.functionEndLineNumber());
        frame.line = info.lineNumber();
    
        if (frame.function.isEmpty())
            frame.function = "<global scope>";
        //frame.address = ...;
        stackFrames.append(frame);
    }
    qq->stackHandler()->setFrames(stackFrames);

    //
    // Build locals
    //
    WatchData data;
    data.iname = "local";
    data.name = "local";
    data.scriptValue = context->activationObject();
    qq->watchHandler()->insertData(data);
    updateWatchModel();

    // FIXME: Use an extra thread. This here is evil
    m_stopped = true;
    while (m_stopped) {
hjk's avatar
hjk committed
612
        //SDEBUG("LOOPING");
con's avatar
con committed
613
614
        QApplication::processEvents();
    }
hjk's avatar
hjk committed
615
    //SDEBUG("RUNNING AGAIN");
con's avatar
con committed
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
}

void ScriptEngine::updateWatchModel()
{
    while (true) {
        QList<WatchData> list = qq->watchHandler()->takeCurrentIncompletes();
        if (list.isEmpty())
            break;
        foreach (const WatchData &data, list)
            updateSubItem(data);
    }
    qq->watchHandler()->rebuildModel();
    q->showStatusMessage(tr("Stopped."), 5000);
}

void ScriptEngine::updateSubItem(const WatchData &data0)
{
    WatchData data = data0;
hjk's avatar
hjk committed
634
    //SDEBUG("\nUPDATE SUBITEM: " << data.toString());
hjk's avatar
hjk committed
635
    QTC_ASSERT(data.isValid(), return);
con's avatar
con committed
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698

    if (data.isTypeNeeded() || data.isValueNeeded()) {
        QScriptValue ob = data.scriptValue;
        if (ob.isArray()) {
            data.setType("Array");
            data.setValue(" ");
        } else if (ob.isBool()) {
            data.setType("Bool");
            data.setValue(ob.toBool() ? "true" : "false");
            data.setChildCount(0);
        } else if (ob.isDate()) {
            data.setType("Date");
            data.setValue(ob.toDateTime().toString().toUtf8());
            data.setChildCount(0);
        } else if (ob.isError()) {
            data.setType("Error");
            data.setValue(" ");
        } else if (ob.isFunction()) {
            data.setType("Function");
            data.setValue(" ");
        } else if (ob.isNull()) {
            data.setType("<null>");
            data.setValue("<null>");
        } else if (ob.isNumber()) {
            data.setType("Number");
            data.setValue(QString::number(ob.toNumber()).toUtf8());
            data.setChildCount(0);
        } else if (ob.isObject()) {
            data.setType("Object");
            data.setValue(" ");
        } else if (ob.isQMetaObject()) {
            data.setType("QMetaObject");
            data.setValue(" ");
        } else if (ob.isQObject()) {
            data.setType("QObject");
            data.setValue(" ");
        } else if (ob.isRegExp()) {
            data.setType("RegExp");
            data.setValue(ob.toRegExp().pattern().toUtf8());
        } else if (ob.isString()) {
            data.setType("String");
            data.setValue(ob.toString().toUtf8());
        } else if (ob.isVariant()) {
            data.setType("Variant");
            data.setValue(" ");
        } else if (ob.isUndefined()) {
            data.setType("<undefined>");
            data.setValue("<unknown>");
        } else {
            data.setType("<unknown>");
            data.setValue("<unknown>");
        }
        qq->watchHandler()->insertData(data);
        return;
    }

    if (data.isChildrenNeeded()) {
        int numChild = 0;
        QScriptValueIterator it(data.scriptValue);
        while (it.hasNext()) {
            it.next();
            WatchData data1;
            data1.iname = data.iname + "." + it.name();
699
            data1.exp = it.name();
con's avatar
con committed
700
701
702
703
704
705
706
707
708
            data1.name = it.name();
            data1.scriptValue = it.value();
            if (qq->watchHandler()->isExpandedIName(data1.iname))
                data1.setChildrenNeeded();
            else
                data1.setChildrenUnneeded();
            qq->watchHandler()->insertData(data1);
            ++numChild;
        }
hjk's avatar
hjk committed
709
        //SDEBUG("  ... CHILDREN: " << numChild);
con's avatar
con committed
710
711
712
713
714
715
716
717
718
719
720
721
722
723
        data.setChildCount(numChild);
        data.setChildrenUnneeded();
        qq->watchHandler()->insertData(data);
        return;
    }

    if (data.isChildCountNeeded()) {
        int numChild = 0;
        QScriptValueIterator it(data.scriptValue);
        while (it.hasNext()) {
            it.next();
            ++numChild;
        }
        data.setChildCount(numChild);
hjk's avatar
hjk committed
724
        //SDEBUG("  ... CHILDCOUNT: " << numChild);
con's avatar
con committed
725
726
727
728
        qq->watchHandler()->insertData(data);
        return;
    }

hjk's avatar
hjk committed
729
    QTC_ASSERT(false, return);
con's avatar
con committed
730
731
}

732
IDebuggerEngine *createScriptEngine(DebuggerManager *parent, QList<Core::IOptionsPage*> *)
con's avatar
con committed
733
734
735
736
{
    return new ScriptEngine(parent);
}