aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2011-10-05 09:20:51 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-05 12:36:15 +0200
commit507a7a4e80c60fe90fb976aa60eda6881efd1016 (patch)
tree9705a5e94b54afa6b4f1a34b72d4ed286a2550a1 /src
parent1a36b216b19919f4489881bc5807b14cdb74c167 (diff)
V8Debugger: Code beautification
Convert to from QString to QByteArray only when necessary. Also move private methods into private class. Change-Id: Iac28990f16c588e0172356c9395b7771f01f4817 Reviewed-on: http://codereview.qt-project.org/6022 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/debugger/qv8debugservice.cpp67
-rw-r--r--src/declarative/debugger/qv8debugservice_p.h13
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp2
3 files changed, 38 insertions, 44 deletions
diff --git a/src/declarative/debugger/qv8debugservice.cpp b/src/declarative/debugger/qv8debugservice.cpp
index 8486ddf49e..157bb8cf84 100644
--- a/src/declarative/debugger/qv8debugservice.cpp
+++ b/src/declarative/debugger/qv8debugservice.cpp
@@ -62,8 +62,8 @@ void DebugMessageHandler(const v8::Debug::Message& message)
return;
}
- const QByteArray response(QV8Engine::toStringStatic(
- message.GetJSON()).toUtf8());
+ const QString response(QV8Engine::toStringStatic(
+ message.GetJSON()));
QV8DebugService *service = QV8DebugService::instance();
service->debugMessageHandler(response);
@@ -99,13 +99,16 @@ public:
isolate->Dispose();
}
+ void sendDebugMessage(const QString &message);
+ static QByteArray packMessage(const QString &message);
+
bool initialized;
QJSEngine *engine;
v8::Isolate *isolate;
QList<QDeclarativeEngine *> engines;
QEventLoop loop;
QHash<QString,QString> sourcePath;
- QHash<QString,QByteArray> requestCache;
+ QHash<QString,QString> requestCache;
QHash<int,QString> eventList;
};
@@ -150,9 +153,9 @@ void QV8DebugService::removeEngine(QDeclarativeEngine *engine)
d->engines.removeAll(engine);
}
-void QV8DebugService::debugMessageHandler(QByteArray message)
+void QV8DebugService::debugMessageHandler(const QString &message)
{
- sendMessage(packMessage(message));
+ sendMessage(QV8DebugServicePrivate::packMessage(message));
}
void QV8DebugService::executionStopped()
@@ -164,7 +167,7 @@ void QV8DebugService::executionStopped()
}
}
-void QV8DebugService::appendSourcePath(QByteArray message)
+void QV8DebugService::appendSourcePath(const QString &message)
{
Q_D(QV8DebugService);
@@ -174,9 +177,8 @@ void QV8DebugService::appendSourcePath(QByteArray message)
receive any messages related to this operation */
{
v8::Isolate::Scope i_scope(d->isolate);
- QString req(message);
QJSValue parser = d->engine->evaluate(QLatin1String("JSON.parse"));
- QJSValue out = parser.call(QJSValue(), QJSValueList() << QJSValue(req));
+ QJSValue out = parser.call(QJSValue(), QJSValueList() << QJSValue(message));
msgMap = out.toVariant().toMap();
}
@@ -189,25 +191,24 @@ void QV8DebugService::appendSourcePath(QByteArray message)
//Check if there are any pending breakpoint requests for this file
if (d->requestCache.contains(fileName)) {
- QList<QByteArray> list = d->requestCache.values(fileName);
+ QList<QString> list = d->requestCache.values(fileName);
d->requestCache.remove(fileName);
- foreach (QByteArray request, list) {
- request.replace(fileName.toUtf8(), sourcePath.toUtf8());
- sendDebugMessage(request);
+ foreach (QString request, list) {
+ request.replace(fileName, sourcePath);
+ d->sendDebugMessage(request);
}
}
}
-void QV8DebugService::signalEmitted(const char *signal)
+void QV8DebugService::signalEmitted(const QString &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("("))))) {
+ if (d->eventList.key(signal.left(signal.indexOf(QLatin1String("("))))) {
v8::Debug::DebugBreak();
}
}
@@ -221,8 +222,12 @@ void QV8DebugService::messageReceived(const QByteArray &message)
ds >> command;
if (command == "V8DEBUG") {
- QByteArray request;
- ds >> request;
+ QString request;
+ {
+ QByteArray requestArray;
+ ds >> requestArray;
+ request = QString::fromUtf8(requestArray);
+ }
QVariantMap reqMap;
/* Parse the byte string in a separate isolate
@@ -230,9 +235,8 @@ void QV8DebugService::messageReceived(const QByteArray &message)
receive any messages related to this operation */
{
v8::Isolate::Scope i_scope(d->isolate);
- QString req(request);
QJSValue parser = d->engine->evaluate(QLatin1String("JSON.parse"));
- QJSValue out = parser.call(QJSValue(), QJSValueList() << QJSValue(req));
+ QJSValue out = parser.call(QJSValue(), QJSValueList() << QJSValue(request));
reqMap = out.toVariant().toMap();
}
@@ -257,7 +261,7 @@ void QV8DebugService::messageReceived(const QByteArray &message)
//Check if the filepath has been cached
if (d->sourcePath.contains(fileName)) {
QString filePath = d->sourcePath.value(fileName);
- request.replace(fileName.toUtf8(), filePath.toUtf8());
+ request.replace(fileName, filePath);
} else {
//Store the setbreakpoint message till filepath is resolved
d->requestCache.insertMulti(fileName, request);
@@ -282,8 +286,8 @@ void QV8DebugService::messageReceived(const QByteArray &message)
// "success" : true
// }
{
- v8::Isolate::Scope i_scope(d->isolate);
- const QString obj("{}");
+ v8::Isolate::Scope(d->isolate);
+ const QString obj(QLatin1String("{}"));
QJSValue parser = d->engine->evaluate(QLatin1String("JSON.parse"));
QJSValue jsonVal = parser.call(QJSValue(), QJSValueList() << obj);
jsonVal.setProperty(QLatin1String("type"), QJSValue(QLatin1String("response")));
@@ -316,14 +320,14 @@ void QV8DebugService::messageReceived(const QByteArray &message)
QJSValue stringify = d->engine->evaluate(QLatin1String("JSON.stringify"));
QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal);
- debugMessageHandler(json.toString().toUtf8());
+ debugMessageHandler(json.toString());
}
}
} 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();
+ const int bp = arguments.value(QLatin1String("breakpoint")).toInt();
if (bp < 0) {
d->eventList.remove(bp);
@@ -331,30 +335,27 @@ void QV8DebugService::messageReceived(const QByteArray &message)
}
}
if (forwardRequestToV8)
- sendDebugMessage(request);
+ d->sendDebugMessage(request);
}
}
QDeclarativeDebugService::messageReceived(message);
}
-void QV8DebugService::sendDebugMessage(const QByteArray &msg)
+void QV8DebugServicePrivate::sendDebugMessage(const QString &message)
{
- Q_D(QV8DebugService);
+ if (loop.isRunning())
+ loop.exit();
- const QString message(msg);
- if (d->loop.isRunning()) {
- d->loop.exit();
- }
v8::Debug::SendCommand(message.utf16(), message.size());
}
-QByteArray QV8DebugService::packMessage(QByteArray &message)
+QByteArray QV8DebugServicePrivate::packMessage(const QString &message)
{
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
QByteArray cmd("V8DEBUG");
- rs << cmd << message;
+ rs << cmd << message.toUtf8();
return reply;
}
diff --git a/src/declarative/debugger/qv8debugservice_p.h b/src/declarative/debugger/qv8debugservice_p.h
index 09b8f66fb0..861e5f5c05 100644
--- a/src/declarative/debugger/qv8debugservice_p.h
+++ b/src/declarative/debugger/qv8debugservice_p.h
@@ -53,8 +53,6 @@
// We mean it.
//
-#include <QtCore/QPointer>
-
#include "private/qdeclarativedebugservice_p.h"
QT_BEGIN_HEADER
@@ -64,7 +62,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QDeclarativeEngine;
-class QJSEngine;
class QV8DebugServicePrivate;
class QV8DebugService : public QDeclarativeDebugService
@@ -79,21 +76,17 @@ public:
void addEngine(QDeclarativeEngine *);
void removeEngine(QDeclarativeEngine *);
- void debugMessageHandler(QByteArray message);
+ void debugMessageHandler(const QString &message);
void executionStopped();
- void appendSourcePath(QByteArray message);
+ void appendSourcePath(const QString &message);
- void signalEmitted(const char *signal);
+ void signalEmitted(const QString &signal);
protected:
void messageReceived(const QByteArray &);
private:
- void sendDebugMessage(const QByteArray &msg);
- QByteArray packMessage(QByteArray &message);
-
-private:
Q_DISABLE_COPY(QV8DebugService)
Q_DECLARE_PRIVATE(QV8DebugService)
};
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index 1780fb7e28..11dec91158 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -174,7 +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());
+ QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.signature()));
}
m_isEvaluating = true;
if (!m_paramsValid) {