Script engine: Fix locals/QT_NO_CAST_FROM_ASCII

This commit is contained in:
Friedemann Kleint
2010-01-18 12:34:59 +01:00
committed by Tim Jenssen
parent f717f51bac
commit a704b974b5
5 changed files with 108 additions and 88 deletions

View File

@@ -123,6 +123,20 @@ void MessageManagerPrototype::printToOutputPane(const QString &text, bool bringT
mm->printToOutputPane(text, bringToForeground); mm->printToOutputPane(text, bringToForeground);
} }
void MessageManagerPrototype::printToOutputPanePopup(const QString &text)
{
MessageManager *mm = qscriptvalue_cast<MessageManager *>(thisObject());
QTC_ASSERT(mm, return);
mm->printToOutputPanePopup(text);
}
void MessageManagerPrototype::printToOutputPane(const QString &text)
{
MessageManager *mm = qscriptvalue_cast<MessageManager *>(thisObject());
QTC_ASSERT(mm, return);
mm->printToOutputPane(text);
}
QString MessageManagerPrototype::toString() const QString MessageManagerPrototype::toString() const
{ {
return QLatin1String("MessageManager"); return QLatin1String("MessageManager");

View File

@@ -87,7 +87,10 @@ public:
public slots: public slots:
void displayStatusBarMessage(const QString &text, int ms = 0); void displayStatusBarMessage(const QString &text, int ms = 0);
void printToOutputPane(const QString &text, bool bringToForeground = true); void printToOutputPane(const QString &text, bool bringToForeground);
void printToOutputPanePopup(const QString &text); // pops up
void printToOutputPane(const QString &text);
QString toString() const; QString toString() const;
}; };

View File

@@ -235,13 +235,13 @@ ScriptManager::QScriptEnginePtr ScriptManagerPrivate::ensureEngineInitialized()
{ {
if (!m_engine.isNull()) if (!m_engine.isNull())
return m_engine; return m_engine;
m_engine = QScriptEnginePtr(new QScriptEngine(this)); m_engine = QScriptEnginePtr(new QScriptEngine);
// register QObjects that occur as properties // register QObjects that occur as properties
SharedTools::registerQObject<QMainWindow>(m_engine.data()); SharedTools::registerQObject<QMainWindow>(m_engine.data());
SharedTools::registerQObject<QStatusBar>(m_engine.data()); SharedTools::registerQObject<QStatusBar>(m_engine.data());
SharedTools::registerQObject<QSettings>(m_engine.data()); SharedTools::registerQObject<QSettings>(m_engine.data());
// WB interfaces // WB interfaces
// SharedTools::registerQObjectInterface<Core::MessageManager, MessageManagerPrototype>(m_engine); SharedTools::registerQObjectInterface<Core::MessageManager, MessageManagerPrototype>(m_engine.data());
// SharedTools::registerQObjectInterface<Core::IFile, FilePrototype>(m_engine); // SharedTools::registerQObjectInterface<Core::IFile, FilePrototype>(m_engine);
// qScriptRegisterSequenceMetaType<QList<Core::IFile *> >(m_engine); // qScriptRegisterSequenceMetaType<QList<Core::IFile *> >(m_engine);

View File

@@ -27,6 +27,8 @@
** **
**************************************************************************/ **************************************************************************/
#define QT_NO_CAST_FROM_ASCII
#include "scriptengine.h" #include "scriptengine.h"
#include "debuggerdialogs.h" #include "debuggerdialogs.h"
@@ -52,7 +54,6 @@
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtGui/QAction>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QToolTip> #include <QtGui/QToolTip>
@@ -286,8 +287,8 @@ bool ScriptEngine::importExtensions()
extensions.append(QLatin1String(qtExtensionsC[e])); extensions.append(QLatin1String(qtExtensionsC[e]));
if (m_scriptEngine->importedExtensions().contains(extensions.front())) if (m_scriptEngine->importedExtensions().contains(extensions.front()))
return true; return true;
QDir dir("/home/apoenitz/dev/qtscriptgenerator"); QDir dir(QLatin1String("/home/apoenitz/dev/qtscriptgenerator"));
if (!dir.cd("plugins")) { if (!dir.cd(QLatin1String("plugins"))) {
fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n"); fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
return false; return false;
} }
@@ -313,7 +314,7 @@ bool ScriptEngine::importExtensions()
"Make sure that the bindings have been built, " "Make sure that the bindings have been built, "
"and that this executable and the plugins are " "and that this executable and the plugins are "
"using compatible Qt libraries.", "using compatible Qt libraries.",
qPrintable(failExtensions.join(", ")), qPrintable(dir.absolutePath())); qPrintable(failExtensions.join(QLatin1String(", "))), qPrintable(dir.absolutePath()));
} }
} }
return failExtensions.isEmpty(); return failExtensions.isEmpty();
@@ -495,7 +496,7 @@ void ScriptEngine::setToolTipExpression(const QPoint &mousePos,
*/ */
QToolTip::hideText(); QToolTip::hideText();
if (exp.isEmpty() || exp.startsWith("#")) { if (exp.isEmpty() || exp.startsWith(QLatin1Char('#'))) {
QToolTip::hideText(); QToolTip::hideText();
return; return;
} }
@@ -505,18 +506,18 @@ void ScriptEngine::setToolTipExpression(const QPoint &mousePos,
return; return;
} }
if (exp.startsWith('"') && exp.endsWith('"')) { if (exp.startsWith(QLatin1Char('"')) && exp.endsWith(QLatin1Char('"'))) {
QToolTip::showText(m_toolTipPos, tr("String literal %1").arg(exp)); QToolTip::showText(m_toolTipPos, tr("String literal %1").arg(exp));
return; return;
} }
if (exp.startsWith("++") || exp.startsWith("--")) if (exp.startsWith(QLatin1String("++")) || exp.startsWith(QLatin1String("--")))
exp = exp.mid(2); exp.remove(0, 2);
if (exp.endsWith("++") || exp.endsWith("--")) if (exp.endsWith(QLatin1String("++")) || exp.endsWith(QLatin1String("--")))
exp = exp.mid(2); exp.remove(0, 2);
if (exp.startsWith("<") || exp.startsWith("[")) if (exp.startsWith(QLatin1Char('<')) || exp.startsWith(QLatin1Char('[')))
return; return;
if (hasSideEffects(exp)) { if (hasSideEffects(exp)) {
@@ -549,8 +550,8 @@ void ScriptEngine::setToolTipExpression(const QPoint &mousePos,
void ScriptEngine::assignValueInDebugger(const QString &expression, void ScriptEngine::assignValueInDebugger(const QString &expression,
const QString &value) const QString &value)
{ {
XSDEBUG("ASSIGNING: " << expression + '=' + value); XSDEBUG("ASSIGNING: " << (expression + QLatin1Char('=') + value));
m_scriptEngine->evaluate(expression + '=' + value); m_scriptEngine->evaluate(expression + QLatin1Char('=') + value);
updateLocals(); updateLocals();
} }
@@ -652,16 +653,17 @@ void ScriptEngine::updateLocals()
manager()->stackHandler()->setFrames(stackFrames); manager()->stackHandler()->setFrames(stackFrames);
// //
// Build locals // Build locals, deactivate agent meanwhile.
// //
m_scriptEngine->setAgent(0);
WatchData data; WatchData data;
data.iname = "local"; data.iname = "local";
data.name = "local"; data.name = QString::fromLatin1(data.iname);
data.scriptValue = context->activationObject(); data.scriptValue = context->activationObject();
manager()->watchHandler()->beginCycle(); manager()->watchHandler()->beginCycle();
updateSubItem(data); updateSubItem(data);
manager()->watchHandler()->endCycle(); manager()->watchHandler()->endCycle();
// FIXME: Use an extra thread. This here is evil // FIXME: Use an extra thread. This here is evil
m_stopped = true; m_stopped = true;
showStatusMessage(tr("Stopped."), 5000); showStatusMessage(tr("Stopped."), 5000);
@@ -669,116 +671,122 @@ void ScriptEngine::updateLocals()
//SDEBUG("LOOPING"); //SDEBUG("LOOPING");
QApplication::processEvents(); QApplication::processEvents();
} }
//SDEBUG("RUNNING AGAIN"); setState(InferiorRunningRequested);
setState(InferiorRunning);
// Clear any exceptions occurred during locals evaluation.
m_scriptEngine->clearExceptions();
m_scriptEngine->setAgent(m_scriptAgent.data());
SDEBUG("Continuing");
} }
void ScriptEngine::updateWatchData(const WatchData &data) void ScriptEngine::updateWatchData(const WatchData &data)
{ {
updateSubItem(data); updateSubItem(data);
//manager()->watchHandler()->rebuildModel(); }
static inline QString msgDebugInsert(const WatchData &d0, const QList<WatchData>& children)
{
QString rc;
QTextStream str(&rc);
str << "INSERTING " << d0.toString() << '\n';
foreach(const WatchData &c, children)
str << " " << c.toString() << '\n';
return rc;
} }
void ScriptEngine::updateSubItem(const WatchData &data0) void ScriptEngine::updateSubItem(const WatchData &data0)
{ {
WatchData data = data0; WatchData data = data0;
//SDEBUG("\nUPDATE SUBITEM: " << data.toString()); QList<WatchData> children;
SDEBUG("\nUPDATE SUBITEM: " << data.toString() << data.scriptValue.toString());
QTC_ASSERT(data.isValid(), return); QTC_ASSERT(data.isValid(), return);
if (data.isTypeNeeded() || data.isValueNeeded()) { if (data.isTypeNeeded() || data.isValueNeeded()) {
QScriptValue ob = data.scriptValue; const QScriptValue &ob = data.scriptValue;
if (ob.isArray()) { if (ob.isArray()) {
data.setType("Array"); data.setType(QLatin1String("Array"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isBool()) { } else if (ob.isBool()) {
data.setType("Bool"); data.setType(QLatin1String("Bool"), false);
data.setValue(ob.toBool() ? "true" : "false"); data.setValue(ob.toBool() ? QLatin1String("true") : QLatin1String("false"));
data.setHasChildren(false); data.setHasChildren(false);
} else if (ob.isDate()) { } else if (ob.isDate()) {
data.setType("Date"); data.setType(QLatin1String("Date"), false);
data.setValue(ob.toDateTime().toString().toUtf8()); data.setValue(ob.toDateTime().toString());
data.setHasChildren(false); data.setHasChildren(false);
} else if (ob.isError()) { } else if (ob.isError()) {
data.setType("Error"); data.setType(QLatin1String("Error"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isFunction()) { } else if (ob.isFunction()) {
data.setType("Function"); data.setType(QLatin1String("Function"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isNull()) { } else if (ob.isNull()) {
data.setType("<null>"); const QString nullValue = QLatin1String("<null>");
data.setValue("<null>"); data.setType(nullValue, false);
data.setValue(nullValue);
} else if (ob.isNumber()) { } else if (ob.isNumber()) {
data.setType("Number"); data.setType(QLatin1String("Number"), false);
data.setValue(QString::number(ob.toNumber()).toUtf8()); data.setValue(QString::number(ob.toNumber()));
data.setHasChildren(false); data.setHasChildren(false);
} else if (ob.isObject()) { } else if (ob.isObject()) {
data.setType("Object"); data.setType(QLatin1String("Object"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isQMetaObject()) { } else if (ob.isQMetaObject()) {
data.setType("QMetaObject"); data.setType(QLatin1String("QMetaObject"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isQObject()) { } else if (ob.isQObject()) {
data.setType("QObject"); data.setType(QLatin1String("QObject"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isRegExp()) { } else if (ob.isRegExp()) {
data.setType("RegExp"); data.setType(QLatin1String("RegExp"), false);
data.setValue(ob.toRegExp().pattern().toUtf8()); data.setValue(ob.toRegExp().pattern());
} else if (ob.isString()) { } else if (ob.isString()) {
data.setType("String"); data.setType(QLatin1String("String"), false);
data.setValue(ob.toString().toUtf8()); data.setValue(ob.toString());
} else if (ob.isVariant()) { } else if (ob.isVariant()) {
data.setType("Variant"); data.setType(QLatin1String("Variant"), false);
data.setValue(" "); data.setValue(QString(QLatin1Char(' ')));
} else if (ob.isUndefined()) { } else if (ob.isUndefined()) {
data.setType("<undefined>"); data.setType(QLatin1String("<undefined>"), false);
data.setValue("<unknown>"); data.setValue(QLatin1String("<unknown>"));
data.setHasChildren(false); data.setHasChildren(false);
} else { } else {
data.setType("<unknown>"); const QString unknown = QLatin1String("<unknown>");
data.setValue("<unknown>"); data.setType(unknown, false);
data.setValue(unknown);
data.setHasChildren(false); data.setHasChildren(false);
} }
manager()->watchHandler()->insertData(data);
return;
} }
if (data.isChildrenNeeded()) { if (data.isChildrenNeeded()) {
int numChild = 0;
QScriptValueIterator it(data.scriptValue); QScriptValueIterator it(data.scriptValue);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
WatchData data1; WatchData data1;
data1.iname = data.iname + "." + it.name().toLatin1(); data1.iname = data.iname + '.' + it.name().toLatin1();
data1.exp = it.name().toLatin1(); data1.exp = it.name().toLatin1();
data1.name = it.name(); data1.name = it.name();
data1.scriptValue = it.value(); data1.scriptValue = it.value();
if (manager()->watchHandler()->isExpandedIName(data1.iname)) if (manager()->watchHandler()->isExpandedIName(data1.iname)) {
data1.setChildrenNeeded(); data1.setChildrenNeeded();
else } else {
data1.setChildrenUnneeded(); data1.setChildrenUnneeded();
manager()->watchHandler()->insertData(data1);
++numChild;
} }
//SDEBUG(" ... CHILDREN: " << numChild); children.push_back(data1);
data.setHasChildren(numChild > 0); }
data.setHasChildren(!children.isEmpty());
data.setChildrenUnneeded(); data.setChildrenUnneeded();
manager()->watchHandler()->insertData(data);
return;
} }
if (data.isHasChildrenNeeded()) { if (data.isHasChildrenNeeded()) {
int numChild = 0;
QScriptValueIterator it(data.scriptValue); QScriptValueIterator it(data.scriptValue);
while (it.hasNext()) { data.setHasChildren(it.hasNext());
it.next();
++numChild;
}
data.setHasChildren(numChild > 0);
//SDEBUG(" ... CHILDCOUNT: " << numChild);
manager()->watchHandler()->insertData(data);
return;
} }
QTC_ASSERT(false, return); SDEBUG(msgDebugInsert(data, children));
manager()->watchHandler()->insertData(data);
if (!children.isEmpty())
manager()->watchHandler()->insertBulkData(children);
} }
void ScriptEngine::showDebuggerOutput(int channel, const QString &m) void ScriptEngine::showDebuggerOutput(int channel, const QString &m)

View File

@@ -30,33 +30,28 @@
#ifndef DEBUGGER_SCRIPTENGINE_H #ifndef DEBUGGER_SCRIPTENGINE_H
#define DEBUGGER_SCRIPTENGINE_H #define DEBUGGER_SCRIPTENGINE_H
#include <QtCore/QByteArray> #include "idebuggerengine.h"
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QProcess>
#include <QtCore/QPoint>
#include <QtCore/QSet>
#include <QtCore/QVariant>
#include <QtCore/QSharedPointer> #include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer> #include <QtCore/QScopedPointer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QSplitter;
class QScriptEngine; class QScriptEngine;
class QScriptValue; class QScriptValue;
QT_END_NAMESPACE QT_END_NAMESPACE
#include "idebuggerengine.h"
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
class ScriptAgent; class ScriptAgent;
class WatchData; class WatchData;
/* A debugger engine for a QScriptEngine implemented using a QScriptEngineAgent.
* listening on script events. The engine has a special execution model:
* The script is executed in the foreground, while the debugger runs in
* processEvents() triggered by QScriptEngine::setProcessEventsInterval().
* Stopping is emulated by manually calling processEvents() from the debugger engine. */
class ScriptEngine : public IDebuggerEngine class ScriptEngine : public IDebuggerEngine
{ {
Q_OBJECT Q_OBJECT