Index: trunk/src/scripttools/debugging/qscriptdebuggerconsole.cpp
===================================================================
--- trunk/src/scripttools/debugging/qscriptdebuggerconsole.cpp	(revision 651)
+++ trunk/src/scripttools/debugging/qscriptdebuggerconsole.cpp	(revision 846)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -45,4 +45,8 @@
 #include "qscriptdebuggerscriptedconsolecommand_p.h"
 #include "qscriptmessagehandlerinterface_p.h"
+#include "qscriptbreakpointdata_p.h"
+#include "qscriptdebuggerresponse_p.h"
+#include "qscriptdebuggervalueproperty_p.h"
+#include "qscriptscriptdata_p.h"
 
 #include <QtCore/qdir.h>
@@ -51,7 +55,203 @@
 #include <QtCore/qstringlist.h>
 #include <QtCore/qdebug.h>
+#include <QtScript/qscriptcontextinfo.h>
 #include <QtScript/qscriptengine.h>
 
+Q_DECLARE_METATYPE(QScriptDebuggerResponse)
+Q_DECLARE_METATYPE(QScriptBreakpointData)
+Q_DECLARE_METATYPE(QScriptBreakpointMap)
+Q_DECLARE_METATYPE(QScriptScriptData)
+Q_DECLARE_METATYPE(QScriptScriptMap)
+Q_DECLARE_METATYPE(QScriptContextInfo)
+Q_DECLARE_METATYPE(QScriptDebuggerValue)
+Q_DECLARE_METATYPE(QScriptDebuggerValueProperty)
+Q_DECLARE_METATYPE(QScriptDebuggerValuePropertyList)
+Q_DECLARE_METATYPE(QScriptDebuggerConsoleCommand*)
+Q_DECLARE_METATYPE(QScriptDebuggerConsoleCommandList)
+Q_DECLARE_METATYPE(QScriptDebuggerConsoleCommandGroupData)
+Q_DECLARE_METATYPE(QScriptDebuggerConsoleCommandGroupMap)
+
 QT_BEGIN_NAMESPACE
+
+static QScriptValue debuggerResponseToScriptValue(QScriptEngine *eng, const QScriptDebuggerResponse &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("result"), qScriptValueFromValue(eng, in.result()));
+    out.setProperty(QString::fromLatin1("error"), QScriptValue(eng, in.error()));
+    out.setProperty(QString::fromLatin1("async"), QScriptValue(eng, in.async()));
+    return out;
+}
+
+static void debuggerResponseFromScriptValue(const QScriptValue &, QScriptDebuggerResponse &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue breakpointDataToScriptValue(QScriptEngine *eng, const QScriptBreakpointData &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("scriptId"), QScriptValue(eng, qsreal(in.scriptId())));
+    out.setProperty(QString::fromLatin1("fileName"), QScriptValue(eng, in.fileName()));
+    out.setProperty(QString::fromLatin1("lineNumber"), QScriptValue(eng, in.lineNumber()));
+    out.setProperty(QString::fromLatin1("enabled"), QScriptValue(eng, in.isEnabled()));
+    out.setProperty(QString::fromLatin1("singleShot"), QScriptValue(eng, in.isSingleShot()));
+    out.setProperty(QString::fromLatin1("ignoreCount"), QScriptValue(eng, in.ignoreCount()));
+    out.setProperty(QString::fromLatin1("condition"), QScriptValue(eng, in.condition()));
+    return out;
+}
+
+static void breakpointDataFromScriptValue(const QScriptValue &in, QScriptBreakpointData &out)
+{
+    QScriptValue scriptId = in.property(QString::fromLatin1("scriptId"));
+    if (scriptId.isValid())
+        out.setScriptId((qint64)scriptId.toNumber());
+    out.setFileName(in.property(QString::fromLatin1("fileName")).toString());
+    out.setLineNumber(in.property(QString::fromLatin1("lineNumber")).toInt32());
+    QScriptValue enabled = in.property(QString::fromLatin1("enabled"));
+    if (enabled.isValid())
+        out.setEnabled(enabled.toBoolean());
+    QScriptValue singleShot = in.property(QString::fromLatin1("singleShot"));
+    if (singleShot.isValid())
+        out.setSingleShot(singleShot.toBoolean());
+    out.setIgnoreCount(in.property(QString::fromLatin1("ignoreCount")).toInt32());
+    out.setCondition(in.property(QString::fromLatin1("condition")).toString());
+}
+
+static QScriptValue breakpointMapToScriptValue(QScriptEngine *eng, const QScriptBreakpointMap &in)
+{
+    QScriptValue out = eng->newObject();
+    QScriptBreakpointMap::const_iterator it;
+    for (it = in.constBegin(); it != in.constEnd(); ++it) {
+        out.setProperty(QString::number(it.key()), qScriptValueFromValue(eng, it.value()));
+    }
+    return out;
+}
+
+static void breakpointMapFromScriptValue(const QScriptValue &, QScriptBreakpointMap &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue scriptDataToScriptValue(QScriptEngine *eng, const QScriptScriptData &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("contents"), QScriptValue(eng, in.contents()));
+    out.setProperty(QString::fromLatin1("fileName"), QScriptValue(eng, in.fileName()));
+    out.setProperty(QString::fromLatin1("baseLineNumber"), QScriptValue(eng, in.baseLineNumber()));
+    return out;
+}
+
+static void scriptDataFromScriptValue(const QScriptValue &in, QScriptScriptData &out)
+{
+    QString contents = in.property(QString::fromLatin1("contents")).toString();
+    QString fileName = in.property(QString::fromLatin1("fileName")).toString();
+    int baseLineNumber = in.property(QString::fromLatin1("baseLineNumber")).toInt32();
+    QScriptScriptData tmp(contents, fileName, baseLineNumber);
+    out = tmp;
+}
+
+static QScriptValue scriptMapToScriptValue(QScriptEngine *eng, const QScriptScriptMap &in)
+{
+    QScriptValue out = eng->newObject();
+    QScriptScriptMap::const_iterator it;
+    for (it = in.constBegin(); it != in.constEnd(); ++it) {
+        out.setProperty(QString::number(it.key()), qScriptValueFromValue(eng, it.value()));
+    }
+    return out;
+}
+
+static void scriptMapFromScriptValue(const QScriptValue &, QScriptScriptMap &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue consoleCommandToScriptValue(
+    QScriptEngine *eng, QScriptDebuggerConsoleCommand* const &in)
+{
+    if (!in)
+        return eng->undefinedValue();
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("name"), QScriptValue(eng, in->name()));
+    out.setProperty(QString::fromLatin1("group"), QScriptValue(eng, in->group()));
+    out.setProperty(QString::fromLatin1("shortDescription"), QScriptValue(eng, in->shortDescription()));
+    out.setProperty(QString::fromLatin1("longDescription"), QScriptValue(eng, in->longDescription()));
+    out.setProperty(QString::fromLatin1("aliases"), qScriptValueFromValue(eng, in->aliases()));
+    out.setProperty(QString::fromLatin1("seeAlso"), qScriptValueFromValue(eng, in->seeAlso()));
+    return out;
+}
+
+static void consoleCommandFromScriptValue(
+    const QScriptValue &, QScriptDebuggerConsoleCommand* &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue consoleCommandGroupDataToScriptValue(
+    QScriptEngine *eng, const QScriptDebuggerConsoleCommandGroupData &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("longDescription"), QScriptValue(eng, in.longDescription()));
+    out.setProperty(QString::fromLatin1("shortDescription"), QScriptValue(eng, in.shortDescription()));
+    return out;
+}
+
+static void consoleCommandGroupDataFromScriptValue(
+    const QScriptValue &, QScriptDebuggerConsoleCommandGroupData &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue consoleCommandGroupMapToScriptValue(
+    QScriptEngine *eng, const QScriptDebuggerConsoleCommandGroupMap &in)
+{
+    QScriptValue out = eng->newObject();
+    QScriptDebuggerConsoleCommandGroupMap::const_iterator it;
+    for (it = in.constBegin(); it != in.constEnd(); ++it) {
+        out.setProperty(it.key(), qScriptValueFromValue(eng, it.value()));
+    }
+    return out;
+}
+
+static void consoleCommandGroupMapFromScriptValue(
+    const QScriptValue &, QScriptDebuggerConsoleCommandGroupMap &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue contextInfoToScriptValue(QScriptEngine *eng, const QScriptContextInfo &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("scriptId"), QScriptValue(eng, qsreal(in.scriptId())));
+    out.setProperty(QString::fromLatin1("fileName"), QScriptValue(eng, in.fileName()));
+    out.setProperty(QString::fromLatin1("lineNumber"), QScriptValue(eng, in.lineNumber()));
+    out.setProperty(QString::fromLatin1("columnNumber"), QScriptValue(eng, in.columnNumber()));
+    out.setProperty(QString::fromLatin1("functionName"), QScriptValue(eng, in.functionName()));
+    return out;
+}
+
+static void contextInfoFromScriptValue(const QScriptValue &, QScriptContextInfo &)
+{
+    Q_ASSERT(0);
+}
+
+static QScriptValue debuggerScriptValuePropertyToScriptValue(QScriptEngine *eng, const QScriptDebuggerValueProperty &in)
+{
+    QScriptValue out = eng->newObject();
+    out.setProperty(QString::fromLatin1("name"), QScriptValue(eng, in.name()));
+    out.setProperty(QString::fromLatin1("value"), qScriptValueFromValue(eng, in.value()));
+    out.setProperty(QString::fromLatin1("valueAsString"), QScriptValue(eng, in.valueAsString()));
+    out.setProperty(QString::fromLatin1("flags"), QScriptValue(eng, static_cast<int>(in.flags())));
+    return out;
+}
+
+static void debuggerScriptValuePropertyFromScriptValue(const QScriptValue &in, QScriptDebuggerValueProperty &out)
+{
+    QString name = in.property(QString::fromLatin1("name")).toString();
+    QScriptDebuggerValue value = qscriptvalue_cast<QScriptDebuggerValue>(in.property(QString::fromLatin1("value")));
+    QString valueAsString = in.property(QString::fromLatin1("valueAsString")).toString();
+    int flags = in.property(QString::fromLatin1("flags")).toInt32();
+    QScriptDebuggerValueProperty tmp(name, value, valueAsString, QScriptValue::PropertyFlags(flags));
+    out = tmp;
+}
 
 /*!
@@ -77,4 +277,5 @@
         QScriptDebuggerCommandSchedulerInterface *commandScheduler);
 
+    QScriptEngine *commandEngine;
     QScriptDebuggerConsoleCommandManager *commandManager;
     QString commandPrefix;
@@ -100,4 +301,21 @@
     commandPrefix = QLatin1String(".");
     commandManager = new QScriptDebuggerConsoleCommandManager();
+
+    commandEngine = new QScriptEngine;
+    qScriptRegisterMetaType<QScriptBreakpointData>(commandEngine, breakpointDataToScriptValue, breakpointDataFromScriptValue);
+    qScriptRegisterMetaType<QScriptBreakpointMap>(commandEngine, breakpointMapToScriptValue, breakpointMapFromScriptValue);
+    qScriptRegisterMetaType<QScriptScriptData>(commandEngine, scriptDataToScriptValue, scriptDataFromScriptValue);
+    qScriptRegisterMetaType<QScriptScriptMap>(commandEngine, scriptMapToScriptValue, scriptMapFromScriptValue);
+    qScriptRegisterMetaType<QScriptContextInfo>(commandEngine, contextInfoToScriptValue, contextInfoFromScriptValue);
+    qScriptRegisterMetaType<QScriptDebuggerValueProperty>(commandEngine, debuggerScriptValuePropertyToScriptValue, debuggerScriptValuePropertyFromScriptValue);
+    qScriptRegisterSequenceMetaType<QScriptDebuggerValuePropertyList>(commandEngine);
+    qScriptRegisterMetaType<QScriptDebuggerResponse>(commandEngine, debuggerResponseToScriptValue, debuggerResponseFromScriptValue);
+    qScriptRegisterMetaType<QScriptDebuggerConsoleCommand*>(commandEngine, consoleCommandToScriptValue, consoleCommandFromScriptValue);
+    qScriptRegisterSequenceMetaType<QScriptDebuggerConsoleCommandList>(commandEngine);
+    qScriptRegisterMetaType<QScriptDebuggerConsoleCommandGroupData>(commandEngine, consoleCommandGroupDataToScriptValue, consoleCommandGroupDataFromScriptValue);
+    qScriptRegisterMetaType<QScriptDebuggerConsoleCommandGroupMap>(commandEngine, consoleCommandGroupMapToScriptValue, consoleCommandGroupMapFromScriptValue);
+// ### can't do this, if it's an object ID the conversion will be incorrect since
+// ### the object ID refers to an object in a different engine!
+//    qScriptRegisterMetaType(commandEngine, debuggerScriptValueToScriptValue, debuggerScriptValueFromScriptValue);
 }
 
@@ -105,4 +323,5 @@
 {
     delete commandManager;
+    delete commandEngine;
 }
 
@@ -127,5 +346,5 @@
         QScriptDebuggerScriptedConsoleCommand *command;
         command = QScriptDebuggerScriptedConsoleCommand::parse(
-            program, fileName, messageHandler);
+            program, fileName, commandEngine, messageHandler);
         if (!command)
             continue;
