aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAurindam Jana <aurindam.jana@nokia.com>2011-09-13 12:05:21 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-17 00:06:43 +0200
commit912d7b38e10a536ebd3ad998a9a84d6ffac2b8bc (patch)
treeebd9bbc4ed134a63fba9d2558105d7f9635d71f1 /src
parent99b8e14a69bc33033d6ae6a9d49cd884edbdcaa8 (diff)
JSDebugging: Enable break on events.
The user can request Javascript break on event. The user can provide this info in the Breakpoints Window and provide the slot which will be called when the event occurs. For example: specify "onTriggered" if you need to break on Timer triggerred event. Change-Id: I09f869a5301a9c1f92a8b8c0f3df7f74b1027b4b Reviewed-on: http://codereview.qt-project.org/4751 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/debugger/qv8debugservice.cpp108
-rw-r--r--src/declarative/debugger/qv8debugservice_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp2
3 files changed, 100 insertions, 12 deletions
diff --git a/src/declarative/debugger/qv8debugservice.cpp b/src/declarative/debugger/qv8debugservice.cpp
index 7729e5bdf6..8486ddf49e 100644
--- a/src/declarative/debugger/qv8debugservice.cpp
+++ b/src/declarative/debugger/qv8debugservice.cpp
@@ -62,7 +62,8 @@ void DebugMessageHandler(const v8::Debug::Message& message)
return;
}
- QByteArray response(QV8Engine::toStringStatic(message.GetJSON()).toUtf8());
+ const QByteArray response(QV8Engine::toStringStatic(
+ message.GetJSON()).toUtf8());
QV8DebugService *service = QV8DebugService::instance();
service->debugMessageHandler(response);
@@ -105,10 +106,12 @@ public:
QEventLoop loop;
QHash<QString,QString> sourcePath;
QHash<QString,QByteArray> requestCache;
+ QHash<int,QString> eventList;
};
QV8DebugService::QV8DebugService(QObject *parent)
- : QDeclarativeDebugService(*(new QV8DebugServicePrivate()), QLatin1String("V8Debugger"), parent)
+ : QDeclarativeDebugService(*(new QV8DebugServicePrivate()),
+ QLatin1String("V8Debugger"), parent)
{
Q_D(QV8DebugService);
v8::Debug::SetMessageHandler2(DebugMessageHandler);
@@ -177,8 +180,10 @@ void QV8DebugService::appendSourcePath(QByteArray message)
msgMap = out.toVariant().toMap();
}
- QString sourcePath(msgMap.value(QLatin1String("body")).toMap().value(QLatin1String("script")).toMap().value(QLatin1String("name")).toString());
- QString fileName(QFileInfo(sourcePath).fileName());
+ const QString sourcePath(msgMap.value(QLatin1String("body")).toMap().value(
+ QLatin1String("script")).toMap().value(
+ QLatin1String("name")).toString());
+ const QString fileName(QFileInfo(sourcePath).fileName());
d->sourcePath.insert(fileName, sourcePath);
@@ -193,6 +198,20 @@ void QV8DebugService::appendSourcePath(QByteArray message)
}
}
+void QV8DebugService::signalEmitted(const char *signal)
+{
+ //This function is only called by QDeclarativeBoundSignal
+ //only if there is a slot connected to the signal. Hence, there
+ //is no need for additional check.
+ Q_D(QV8DebugService);
+
+ QString function(signal);
+ //Parse just the name and remove the class info
+ if (d->eventList.key(function.left(function.indexOf(QLatin1String("("))))) {
+ v8::Debug::DebugBreak();
+ }
+}
+
void QV8DebugService::messageReceived(const QByteArray &message)
{
Q_D(QV8DebugService);
@@ -217,7 +236,7 @@ void QV8DebugService::messageReceived(const QByteArray &message)
reqMap = out.toVariant().toMap();
}
- QString debugCommand(reqMap.value(QLatin1String("command")).toString());
+ const QString debugCommand(reqMap.value(QLatin1String("command")).toString());
if (debugCommand == QLatin1String("connect")) {
d->initialized = true;
@@ -226,11 +245,11 @@ void QV8DebugService::messageReceived(const QByteArray &message)
v8::Debug::DebugBreak();
} else {
- bool ok = true;
+ bool forwardRequestToV8 = true;
- if (debugCommand == QLatin1String("setbreakpoint")){
- QVariantMap arguments = reqMap.value(QLatin1String("arguments")).toMap();
- QString type(arguments.value(QLatin1String("type")).toString());
+ if (debugCommand == QLatin1String("setbreakpoint")) {
+ const QVariantMap arguments = reqMap.value(QLatin1String("arguments")).toMap();
+ const QString type(arguments.value(QLatin1String("type")).toString());
if (type == QLatin1String("script")) {
QString fileName(arguments.value(QLatin1String("target")).toString());
@@ -242,11 +261,76 @@ void QV8DebugService::messageReceived(const QByteArray &message)
} else {
//Store the setbreakpoint message till filepath is resolved
d->requestCache.insertMulti(fileName, request);
- ok = false;
+ forwardRequestToV8 = false;
+ }
+ } else if (type == QLatin1String("event")) {
+ //Do not send this request to v8
+ forwardRequestToV8 = false;
+
+ //Prepare the response string
+ //Create a json message using v8 debugging protocol
+ //and send it to client
+
+ // { "seq" : <number>,
+ // "type" : "response",
+ // "request_seq" : <number>,
+ // "command" : "setbreakpoint",
+ // "body" : { "type" : <"function" or "script">
+ // "breakpoint" : <break point number of the new break point>
+ // }
+ // "running" : <is the VM running after sending this response>
+ // "success" : true
+ // }
+ {
+ v8::Isolate::Scope i_scope(d->isolate);
+ const QString obj("{}");
+ QJSValue parser = d->engine->evaluate(QLatin1String("JSON.parse"));
+ QJSValue jsonVal = parser.call(QJSValue(), QJSValueList() << obj);
+ jsonVal.setProperty(QLatin1String("type"), QJSValue(QLatin1String("response")));
+
+ const int sequence = reqMap.value(QLatin1String("seq")).toInt();
+ jsonVal.setProperty(QLatin1String("request_seq"), QJSValue(sequence));
+ jsonVal.setProperty(QLatin1String("command"), QJSValue(debugCommand));
+
+ //Check that the function starts with 'on'
+ QString eventName(arguments.value(QLatin1String("target")).toString());
+
+
+ if (eventName.startsWith(QLatin1String("on"))) {
+ d->eventList.insert(-sequence, eventName.remove(0,2).toLower());
+
+ QJSValue args = parser.call(QJSValue(), QJSValueList() << obj);
+
+ args.setProperty(QLatin1String("type"), QJSValue(QLatin1String("event")));
+ args.setProperty(QLatin1String("breakpoint"), QJSValue(-sequence));
+
+ jsonVal.setProperty(QLatin1String("body"), args);
+ jsonVal.setProperty(QLatin1String("success"), QJSValue(true));
+
+ } else {
+ jsonVal.setProperty(QLatin1String("success"), QJSValue(false));
+ }
+
+
+ jsonVal.setProperty(QLatin1String("running"), QJSValue(!d->loop.isRunning()));
+
+ QJSValue stringify = d->engine->evaluate(QLatin1String("JSON.stringify"));
+ QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal);
+ debugMessageHandler(json.toString().toUtf8());
+
}
}
+ } else if (debugCommand == QLatin1String("clearbreakpoint")) {
+ //check if the breakpoint is a negative integer (event breakpoint)
+ const QVariantMap arguments = reqMap.value(QLatin1String("arguments")).toMap();
+ const int bp = arguments.value("breakpoint").toInt();
+
+ if (bp < 0) {
+ d->eventList.remove(bp);
+ forwardRequestToV8 = false;
+ }
}
- if (ok)
+ if (forwardRequestToV8)
sendDebugMessage(request);
}
}
@@ -258,7 +342,7 @@ void QV8DebugService::sendDebugMessage(const QByteArray &msg)
{
Q_D(QV8DebugService);
- QString message(msg);
+ const QString message(msg);
if (d->loop.isRunning()) {
d->loop.exit();
}
diff --git a/src/declarative/debugger/qv8debugservice_p.h b/src/declarative/debugger/qv8debugservice_p.h
index 7666066f50..09b8f66fb0 100644
--- a/src/declarative/debugger/qv8debugservice_p.h
+++ b/src/declarative/debugger/qv8debugservice_p.h
@@ -84,6 +84,8 @@ public:
void appendSourcePath(QByteArray message);
+ void signalEmitted(const char *signal);
+
protected:
void messageReceived(const QByteArray &);
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index 5accc003f5..1780fb7e28 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -50,6 +50,7 @@
#include "qdeclarativecontext.h"
#include "private/qdeclarativeglobal_p.h"
#include "private/qdeclarativedebugtrace_p.h"
+#include "private/qv8debugservice_p.h"
#include <QtCore/qstringbuilder.h>
#include <QtCore/qdebug.h>
@@ -173,6 +174,7 @@ int QDeclarativeBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
QDeclarativeDebugTrace::startRange(QDeclarativeDebugTrace::HandlingSignal);
QDeclarativeDebugTrace::rangeData(QDeclarativeDebugTrace::HandlingSignal, QLatin1String(m_signal.signature()) % QLatin1String(": ") % m_expression->expression());
QDeclarativeDebugTrace::rangeLocation(QDeclarativeDebugTrace::HandlingSignal, m_expression->sourceFile(), m_expression->lineNumber());
+ QV8DebugService::instance()->signalEmitted(m_signal.signature());
}
m_isEvaluating = true;
if (!m_paramsValid) {