From 5ed80a365b73c437ee330072c99c2ec0b1e471a9 Mon Sep 17 00:00:00 2001 From: Olivier Goffart <olivier.goffart@nokia.com> Date: Fri, 23 Jul 2010 11:07:45 +0200 Subject: [PATCH] QML JS Debugger: add 'this' in the locals --- src/tools/qml/qmlobserver/jsdebuggeragent.cpp | 32 ++++++++++++------- src/tools/qml/qmlobserver/jsdebuggeragent.h | 2 ++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp index bf54f101e07..71ce432010e 100644 --- a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp +++ b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp @@ -52,7 +52,8 @@ QT_BEGIN_NAMESPACE -struct JSAgentWatchData { +class JSAgentWatchData { +public: QByteArray exp; QString name; QString value; @@ -144,6 +145,20 @@ void JSDebuggerAgent::recordKnownObjects(const QList<JSAgentWatchData>& list) knownObjectIds << data.objectId; } +QList<JSAgentWatchData> JSDebuggerAgent::getLocals(QScriptContext *ctx) +{ + QList<JSAgentWatchData> locals; + if (ctx) { + QScriptValue activationObject = ctx->activationObject(); + QScriptValue thisObject = ctx->thisObject(); + locals = expandObject(activationObject); + if (thisObject.isObject() && thisObject.objectId() != engine()->globalObject().objectId()) + locals.prepend(JSAgentWatchData::fromScriptValue("this", thisObject)); + recordKnownObjects(locals); + knownObjectIds << activationObject.objectId(); + } + return locals; +} /*! Constructs a new agent for the given \a engine. The agent will @@ -359,10 +374,7 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message) deep++; } - QList<JSAgentWatchData> locals; - if (ctx) - locals = expandObject(ctx->activationObject()); - recordKnownObjects(locals); + QList<JSAgentWatchData> locals = getLocals(ctx); // Clear any exceptions occurred during locals evaluation. engine()->clearExceptions(); @@ -371,7 +383,7 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message) QDataStream rs(&reply, QIODevice::WriteOnly); rs << QByteArray("LOCALS") << frameId << locals; sendMessage(reply); - + state = oldState; } else if (command == "SET_PROPERTY") { State oldState = state; state = Stopped; @@ -436,13 +448,9 @@ void JSDebuggerAgent::stopped() QList<JSAgentWatchData> watches; foreach (const QString &expr, watchExpressions) watches << JSAgentWatchData::fromScriptValue(expr, engine()->evaluate(expr)); - - QScriptValue activationObject = engine()->currentContext()->activationObject(); - QList<JSAgentWatchData> locals = expandObject(activationObject); - recordKnownObjects(watches); - recordKnownObjects(locals); - knownObjectIds << activationObject.objectId(); + + QList<JSAgentWatchData> locals = getLocals(engine()->currentContext()); // Clear any exceptions occurred during locals evaluation. engine()->clearExceptions(); diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.h b/src/tools/qml/qmlobserver/jsdebuggeragent.h index a842bf3c4a8..ee8cd049cc0 100644 --- a/src/tools/qml/qmlobserver/jsdebuggeragent.h +++ b/src/tools/qml/qmlobserver/jsdebuggeragent.h @@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE class JSAgentWatchData; +class QScriptContext; class JSDebuggerAgent : public QDeclarativeDebugService , public QScriptEngineAgent { Q_OBJECT @@ -119,6 +120,7 @@ private: void recordKnownObjects(const QList<JSAgentWatchData> &); + QList<JSAgentWatchData> getLocals(QScriptContext *); QEventLoop loop; QHash <qint64, QString> filenames; -- GitLab