From 4e2924fbc30905a136cc54f229f1906b11602c3e Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Fri, 2 Dec 2011 14:52:21 +0100 Subject: [PATCH] QV8DebugService: Simplify the service code Removed all parsing functionality. The service only acts as a delegate to v8 debugger. Apart from that, it calls the v8 debug static APIs when requested by client. Change-Id: I2917c2d080e5b409a4b5f39d386279c33634cade Reviewed-by: Kai Koehne --- src/declarative/debugger/qv8debugservice.cpp | 458 ++++----------- src/declarative/debugger/qv8debugservice_p.h | 21 +- src/declarative/qml/qdeclarativeengine.cpp | 2 +- .../data/breakpointRelocation.qml | 53 ++ .../qdeclarativedebugjs/data/changeBreakpoint.qml | 60 ++ .../qdeclarativedebugjs/data/condition.qml | 54 ++ .../qdeclarativedebugjs/data/createComponent.qml | 54 ++ .../qdeclarativedebugjs/data/exception.qml | 51 ++ .../qdeclarativedebugjs/data/loadjsfile.qml | 48 ++ .../qdeclarativedebugjs/data/oncompleted.qml | 53 ++ .../qdeclarativedebugjs/data/stepAction.qml | 57 ++ .../debugger/qdeclarativedebugjs/data/test.qml | 42 +- .../debugger/qdeclarativedebugjs/data/timer.qml | 2 +- .../qdeclarativedebugjs/qdeclarativedebugjs.pro | 10 +- .../tst_qdeclarativedebugjs.cpp | 629 +++++++++++---------- 15 files changed, 885 insertions(+), 709 deletions(-) create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/breakpointRelocation.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/changeBreakpoint.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/condition.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/createComponent.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/exception.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/loadjsfile.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/oncompleted.qml create mode 100644 tests/auto/declarative/debugger/qdeclarativedebugjs/data/stepAction.qml diff --git a/src/declarative/debugger/qv8debugservice.cpp b/src/declarative/debugger/qv8debugservice.cpp index cfe4573..39c991f 100644 --- a/src/declarative/debugger/qv8debugservice.cpp +++ b/src/declarative/debugger/qv8debugservice.cpp @@ -43,59 +43,18 @@ #include "qdeclarativedebugservice_p_p.h" #include #include +#include #include #include #include -#define DEBUGGER_SCRIPT "(function(){"\ - "var DebuggerScript = {};"\ - "DebuggerScript.getScriptName = function(eventData){"\ - "return eventData.script_.script_.nameOrSourceURL();"\ - "};"\ - "DebuggerScript.getScripts = function(){"\ - "var result = [];"\ - "var scripts = Debug.scripts();"\ - "for (var i = 0; i < scripts.length; ++i) {"\ - "var script = scripts[i];"\ - "if (script.type == Debug.ScriptType.Native) continue;"\ - "result.push(script.nameOrSourceURL());"\ - "}"\ - "return result;"\ - "};"\ - "return DebuggerScript;"\ - "})();" - -#define DEBUGGER_UTILITY "(function(){"\ - "var DebuggerUtility = {};"\ - "DebuggerUtility.parseRequest = function(request){"\ - "return JSON.parse(request);"\ - "};"\ - "DebuggerUtility.stringifyRequest = function(request){"\ - "return JSON.stringify(request);"\ - "};"\ - "return DebuggerUtility;"\ - "})();" - const char *V8_DEBUGGER_KEY_CONNECT = "connect"; const char *V8_DEBUGGER_KEY_INTERRUPT = "interrupt"; const char *V8_DEBUGGER_KEY_DISCONNECT = "disconnect"; -const char *V8_DEBUGGER_KEY_CLEARBREAKPOINT = "clearbreakpoint"; -const char *V8_DEBUGGER_KEY_CHANGEBREAKPOINT = "changebreakpoint"; -const char *V8_DEBUGGER_KEY_SETBREAKPOINT = "setbreakpoint"; -const char *V8_DEBUGGER_KEY_TARGET = "target"; -const char *V8_DEBUGGER_KEY_SCRIPT = "script"; -const char *V8_DEBUGGER_KEY_COMMAND = "command"; -const char *V8_DEBUGGER_KEY_SEQ = "seq"; -const char *V8_DEBUGGER_KEY_REQUEST_SEQ = "request_seq"; -const char *V8_DEBUGGER_KEY_SUCCESS = "success"; -const char *V8_DEBUGGER_KEY_BREAKPOINT = "breakpoint"; -const char *V8_DEBUGGER_KEY_ARGUMENTS = "arguments"; -const char *V8_DEBUGGER_KEY_ENABLED = "enabled"; -const char *V8_DEBUGGER_KEY_TYPE = "type"; -const char *V8_DEBUGGER_KEY_EVENT = "event"; -const char *V8_DEBUGGER_KEY_BODY = "body"; -const char *V8_DEBUGGER_KEY_RUNNING = "running"; +const char *V8_DEBUGGER_KEY_REQUEST = "v8request"; +const char *V8_DEBUGGER_KEY_V8MESSAGE = "v8message"; +const char *V8_DEBUGGER_KEY_BREAK_ON_SIGNAL = "breakonsignal"; QT_BEGIN_NAMESPACE @@ -111,22 +70,19 @@ Q_GLOBAL_STATIC(QV8DebugService, v8ServiceInstance) // running, we therefore need a plain pointer. static QV8DebugService *v8ServiceInstancePtr = 0; +void DebugMessageDispatchHandler() +{ + QMetaObject::invokeMethod(v8ServiceInstancePtr, "processDebugMessages", Qt::QueuedConnection); +} + void DebugMessageHandler(const v8::Debug::Message& message) { v8::DebugEvent event = message.GetEvent(); if (event != v8::Break && event != v8::Exception && - event != v8::AfterCompile && event != v8::BeforeCompile) { - return; - } - - const QString response(QJSConverter::toString(message.GetJSON())); - - v8ServiceInstancePtr->debugMessageHandler(response, message.WillStartRunning()); - - if (event == v8::AfterCompile) { - v8ServiceInstancePtr->appendSourcePath(message.GetEventData()); - } //TODO::v8::Exception + event != v8::AfterCompile && event != v8::BeforeCompile) + return; + v8ServiceInstancePtr->debugMessageHandler(QJSConverter::toString(message.GetJSON())); } class QV8DebugServicePrivate : public QDeclarativeDebugServicePrivate @@ -134,43 +90,19 @@ class QV8DebugServicePrivate : public QDeclarativeDebugServicePrivate public: QV8DebugServicePrivate() : connectReceived(false) - , scheduleBreak(false) - , debuggerThreadIsolate(0) - , isRunning(true) + , engine(0) { } - ~QV8DebugServicePrivate() - { - debuggerScript.Dispose(); - debuggerUtility.Dispose(); - debuggerUtilityContext.Dispose(); - if (debuggerThreadIsolate) - debuggerThreadIsolate->Dispose(); - } - void initializeDebuggerThread(); - void sendDebugMessage(const QString &message); - void updateSourcePath(const QString &sourcePath); - static QByteArray packMessage(const QString &message); - QString createResponse(const QVariantMap &response) const; - v8::Handle createV8Object(const QVariantMap &map) const; + static QByteArray packMessage(const QString &type, const QString &message = QString()); bool connectReceived; - bool scheduleBreak; - v8::Isolate *debuggerThreadIsolate; - v8::Persistent debuggerScript; - v8::Persistent debuggerUtility; - v8::Persistent debuggerUtilityContext; - // keep messageReceived() from running until initialize() has finished QMutex initializeMutex; - - bool isRunning; - QHash sourcePath; - QHash requestCache; - QHash handlersList; + QStringList breakOnSignals; + const QV8Engine *engine; }; QV8DebugService::QV8DebugService(QObject *parent) @@ -182,7 +114,7 @@ QV8DebugService::QV8DebugService(QObject *parent) // wait for statusChanged() -> initialize() d->initializeMutex.lock(); if (registerService() == Enabled) { - initialize(false); + init(); // ,block mode, client attached while (!d->connectReceived) { waitForMessage(); @@ -201,41 +133,32 @@ QV8DebugService *QV8DebugService::instance() return v8ServiceInstance(); } -void QV8DebugService::initialize() +void QV8DebugService::initialize(const QV8Engine *engine) { // just make sure that the service is properly registered - v8ServiceInstance(); + v8ServiceInstance()->setEngine(engine); } -void QV8DebugService::debugMessageHandler(const QString &message, bool willStartRunning) +void QV8DebugService::setEngine(const QV8Engine *engine) { Q_D(QV8DebugService); - d->isRunning = willStartRunning; - if (d->scheduleBreak) - scheduledDebugBreak(); - - sendMessage(QV8DebugServicePrivate::packMessage(message)); + d->engine = engine; } - -void QV8DebugService::appendSourcePath(const v8::Handle &eventData) +//V8 DEBUG SERVICE PROTOCOL +//
+//
: "V8DEBUG" +// : ("connect", "disconnect", "interrupt", "v8request", "v8message", "breakonsignal") +// : For _v8request_ and _v8message_ it is the JSON request string. +// For _breakonsignal_ it is +// Empty string for the other types +void QV8DebugService::debugMessageHandler(const QString &message) { - Q_D(QV8DebugService); - - Q_ASSERT(!d->debuggerScript.IsEmpty()); - v8::HandleScope handleScope; - v8::Local debuggerContext = v8::Debug::GetDebugContext(); - v8::Context::Scope contextScope(debuggerContext); - v8::Handle getScriptNameFn = - v8::Local::Cast(d->debuggerScript->Get(v8::String::New("getScriptName"))); - v8::Handle argv[] = { eventData }; - v8::Handle scriptName = getScriptNameFn->Call(d->debuggerScript, 1, argv); - Q_ASSERT(scriptName->IsString()); - - d->updateSourcePath(QJSConverter::toString(scriptName->ToString())); + sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_V8MESSAGE), message)); } + void QV8DebugService::signalEmitted(const QString &signal) { //This function is only called by QDeclarativeBoundSignal @@ -246,61 +169,31 @@ void QV8DebugService::signalEmitted(const QString &signal) //Parse just the name and remove the class info //Normalize to Lower case. QString signalName = signal.left(signal.indexOf(QLatin1String("("))).toLower(); - foreach (const SignalHandlerData &data, d->handlersList) { - if (data.functionName == signalName - && data.enabled) { - d->scheduleBreak = true; + + foreach (const QString &signal, d->breakOnSignals) { + if (signal == signalName) { + scheduledDebugBreak(true); + break; } } - if (d->scheduleBreak) - scheduledDebugBreak(); } -void QV8DebugService::initialize(bool getCompiledScripts) +// executed in the gui thread +void QV8DebugService::init() { Q_D(QV8DebugService); - if (d->debuggerScript.IsEmpty()) { - v8::HandleScope handleScope; - v8::Local debuggerContext = v8::Debug::GetDebugContext(); - v8::Context::Scope contextScope(debuggerContext); - v8::Handle script = v8::Script::New(v8::String::New(DEBUGGER_SCRIPT), 0, 0, v8::Handle(), v8::Script::NativeMode); - d->debuggerScript = v8::Persistent::New(v8::Local::Cast(script->Run())); - } v8::Debug::SetMessageHandler2(DebugMessageHandler); - - if (getCompiledScripts) { - v8::HandleScope handleScope; - v8::Local debuggerContext = v8::Debug::GetDebugContext(); - v8::Context::Scope contextScope(debuggerContext); - v8::Handle getScriptsFn = - v8::Local::Cast(d->debuggerScript->Get(v8::String::New("getScripts"))); - v8::Handle result = getScriptsFn->Call(d->debuggerScript, 0, 0); - if (result.IsEmpty()) - return; - - Q_ASSERT(!result->IsUndefined() && result->IsArray()); - v8::Handle scripts = v8::Handle::Cast(result); - uint len = scripts->Length(); - for (uint i = 0; i < len; ++i) { - d->updateSourcePath(QJSConverter::toString(scripts->Get(i)->ToString())); - } - } - + v8::Debug::SetDebugMessageDispatchHandler(DebugMessageDispatchHandler); d->initializeMutex.unlock(); } -void QV8DebugService::scheduledDebugBreak() +// executed in the gui thread +void QV8DebugService::scheduledDebugBreak(bool schedule) { - Q_D(QV8DebugService); - if (d->scheduleBreak) { + if (schedule) v8::Debug::DebugBreak(); - d->scheduleBreak = false; - } -} - -void QV8DebugService::cancelDebugBreak() -{ - v8::Debug::CancelDebugBreak(); + else + v8::Debug::CancelDebugBreak(); } // executed in the debugger thread @@ -308,15 +201,20 @@ void QV8DebugService::statusChanged(QDeclarativeDebugService::Status newStatus) { Q_D(QV8DebugService); if (newStatus == Enabled) { - if (!d->debuggerThreadIsolate) - d->initializeDebuggerThread(); - // execute in GUI thread d->initializeMutex.lock(); - QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection, Q_ARG(bool, true)); + QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection); } } + +//V8 DEBUG SERVICE PROTOCOL +//
+//
: "V8DEBUG" +// : ("connect", "disconnect", "interrupt", "v8request", "v8message", "breakonsignal") +// : For _v8request_ and _v8message_ it is the JSON request string. +// For _breakonsignal_ it is +// Empty string for the other types // executed in the debugger thread void QV8DebugService::messageReceived(const QByteArray &message) { @@ -326,231 +224,65 @@ void QV8DebugService::messageReceived(const QByteArray &message) QByteArray command; ds >> command; - QMutexLocker locker(&d->initializeMutex); - if (command == "V8DEBUG") { - if (!d->debuggerThreadIsolate) - d->initializeDebuggerThread(); - - - QString request; - { - QByteArray requestArray; - ds >> requestArray; - request = QString::fromUtf8(requestArray); + QByteArray type; + QByteArray data; + ds >> type >> data; + + if (type == V8_DEBUGGER_KEY_CONNECT) { + QMutexLocker locker(&d->initializeMutex); + d->connectReceived = true; + sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_CONNECT))); + + } else if (type == V8_DEBUGGER_KEY_INTERRUPT) { + // break has to be executed in gui thread + QMetaObject::invokeMethod(this, "scheduledDebugBreak", Qt::QueuedConnection, Q_ARG(bool, true)); + sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_INTERRUPT))); + + } else if (type == V8_DEBUGGER_KEY_DISCONNECT) { + // cancel break has to be executed in gui thread + QMetaObject::invokeMethod(this, "scheduledDebugBreak", Qt::QueuedConnection, Q_ARG(bool, false)); + sendDebugMessage(QString::fromUtf8(data)); + + } else if (type == V8_DEBUGGER_KEY_REQUEST) { + sendDebugMessage(QString::fromUtf8(data)); + + } else if (type == V8_DEBUGGER_KEY_BREAK_ON_SIGNAL) { + QDataStream rs(data); + QByteArray signal; + bool enabled; + rs >> signal >> enabled; + //Normalize to lower case. + QString signalName(QString::fromUtf8(signal).toLower()); + if (enabled) + d->breakOnSignals.append(signalName); + else + d->breakOnSignals.removeOne(signalName); + sendMessage(QV8DebugServicePrivate::packMessage(QLatin1String(V8_DEBUGGER_KEY_BREAK_ON_SIGNAL))); } - - bool forwardRequestToV8 = false; - Q_ASSERT(!d->debuggerUtility.IsEmpty()); - { - v8::Isolate::Scope i_scope(d->debuggerThreadIsolate); - - v8::HandleScope handleScope; - v8::Context::Scope contextScope(d->debuggerUtilityContext); - - v8::Handle parseFn = - v8::Local::Cast(d->debuggerUtility->Get(v8::String::New("parseRequest"))); - v8::Handle argv[] = { QJSConverter::toString(request) }; - v8::Handle result = parseFn->Call(d->debuggerUtility, 1, argv); - Q_ASSERT(result->IsObject()); - - v8::Handle requestObj = v8::Handle::Cast(result); - const QString debugCommand = QJSConverter::toString(requestObj->Get(v8::String::New(V8_DEBUGGER_KEY_COMMAND))->ToString()); - const int sequence = requestObj->Get(v8::String::New(V8_DEBUGGER_KEY_SEQ))->Int32Value(); - - if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_CONNECT)) { - d->connectReceived = true; - QVariantMap response; - response.insert(QLatin1String(V8_DEBUGGER_KEY_COMMAND), QVariant(debugCommand)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_REQUEST_SEQ), QVariant(sequence)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_SUCCESS), QVariant(true)); - sendMessage(QV8DebugServicePrivate::packMessage(d->createResponse(response))); - - } else if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_INTERRUPT)) { - // break has to be executed in gui thread - d->scheduleBreak = true; - QMetaObject::invokeMethod(this, "scheduledDebugBreak", Qt::QueuedConnection); - QVariantMap response; - response.insert(QLatin1String(V8_DEBUGGER_KEY_COMMAND), QVariant(debugCommand)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_REQUEST_SEQ), QVariant(sequence)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_SUCCESS), QVariant(true)); - sendMessage(QV8DebugServicePrivate::packMessage(d->createResponse(response))); - - } else if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_DISCONNECT)) { - // cancel break has to be executed in gui thread - QMetaObject::invokeMethod(this, "cancelDebugBreak", Qt::QueuedConnection); - forwardRequestToV8 = true; - - } else if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_CLEARBREAKPOINT)) { - //check if the breakpoint is a negative integer (event breakpoint) - v8::Handle argsObj = requestObj->Get(v8::String::New(V8_DEBUGGER_KEY_ARGUMENTS))->ToObject(); - const int bp = argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_BREAKPOINT))->Int32Value(); - - if (bp < 0) { - d->handlersList.remove(bp); - } else { - forwardRequestToV8 = true; - } - - } else if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_CHANGEBREAKPOINT)) { - //check if the breakpoint is a negative integer (event breakpoint) - v8::Handle argsObj = requestObj->Get(v8::String::New(V8_DEBUGGER_KEY_ARGUMENTS))->ToObject(); - const int bp = argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_BREAKPOINT))->Int32Value(); - - if (bp < 0) { - SignalHandlerData data = d->handlersList.value(bp); - data.enabled = argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_ENABLED))->BooleanValue(); - d->handlersList.insert(bp, data); - - } else { - forwardRequestToV8 = true; - } - - } else if (debugCommand == QLatin1String(V8_DEBUGGER_KEY_SETBREAKPOINT)) { - v8::Handle argsObj = requestObj->Get(v8::String::New(V8_DEBUGGER_KEY_ARGUMENTS))->ToObject(); - const QString type = QJSConverter::toString(argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_TYPE))->ToString()); - QString target = QJSConverter::toString(argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_TARGET))->ToString()); - - if (type == QLatin1String(V8_DEBUGGER_KEY_SCRIPT)) { - //check if the script associated with the breakpoint is cached - if (d->sourcePath.contains(target)) { - //replace fileName with correct filePath - request.replace(target, d->sourcePath.value(target)); - forwardRequestToV8 = true; - - } else { - //store the message till file is compiled - d->requestCache.insertMulti(target, request); - } - - } else if (type == QLatin1String(V8_DEBUGGER_KEY_EVENT)) { - //Handle this internally - bool success = true; - if (target.startsWith(QLatin1String("on"))) { - SignalHandlerData data; - //Only store the probable signal name. - //Normalize to lower case. - data.functionName = target.remove(0,2).toLower(); - data.enabled = argsObj->Get(v8::String::New(V8_DEBUGGER_KEY_ENABLED))->BooleanValue(); - d->handlersList.insert(-sequence, data); - } else { - success = false; - } - //TODO::have to send back response - QVariantMap body; - body.insert(QLatin1String(V8_DEBUGGER_KEY_TYPE), QVariant(QLatin1String(V8_DEBUGGER_KEY_EVENT))); - body.insert(QLatin1String(V8_DEBUGGER_KEY_BREAKPOINT), QVariant(-sequence)); - QVariantMap response; - response.insert(QLatin1String(V8_DEBUGGER_KEY_COMMAND), QVariant(debugCommand)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_REQUEST_SEQ), QVariant(sequence)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_SUCCESS), QVariant(success)); - response.insert(QLatin1String(V8_DEBUGGER_KEY_BODY), body); - - sendMessage(QV8DebugServicePrivate::packMessage(d->createResponse(response))); - } - } else { - //Forward all other requests - forwardRequestToV8 = true; - } - } - - if (forwardRequestToV8) - d->sendDebugMessage(request); } } -void QV8DebugServicePrivate::initializeDebuggerThread() -{ - Q_ASSERT(!debuggerThreadIsolate); - - //Create an isolate & engine in debugger thread - debuggerThreadIsolate = v8::Isolate::New(); - v8::Isolate::Scope i_scope(debuggerThreadIsolate); - if (debuggerUtility.IsEmpty()) { - v8::HandleScope handleScope; - debuggerUtilityContext = v8::Context::New(); - v8::Context::Scope contextScope(debuggerUtilityContext); - v8::Handle script = v8::Script::New(v8::String::New(DEBUGGER_UTILITY), 0, 0, v8::Handle(), v8::Script::NativeMode); - debuggerUtility = v8::Persistent::New(v8::Local::Cast(script->Run())); - } -} - -void QV8DebugServicePrivate::sendDebugMessage(const QString &message) +void QV8DebugService::sendDebugMessage(const QString &message) { v8::Debug::SendCommand(message.utf16(), message.size()); } -void QV8DebugServicePrivate::updateSourcePath(const QString &source) +void QV8DebugService::processDebugMessages() { - const QString fileName(QFileInfo(source).fileName()); - sourcePath.insert(fileName, source); - - //Check if there are any pending breakpoint requests for this file - if (requestCache.contains(fileName)) { - QList list = requestCache.values(fileName); - requestCache.remove(fileName); - foreach (QString request, list) { - request.replace(fileName, source); - sendDebugMessage(request); - } - } + Q_D(QV8DebugService); + v8::HandleScope handleScope; + v8::Context::Scope contextScope(d->engine->context()); + v8::Debug::ProcessDebugMessages(); } -QByteArray QV8DebugServicePrivate::packMessage(const QString &message) +QByteArray QV8DebugServicePrivate::packMessage(const QString &type, const QString &message) { QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); QByteArray cmd("V8DEBUG"); - rs << cmd << message.toUtf8(); + rs << cmd << type.toUtf8() << message.toUtf8(); return reply; } -QString QV8DebugServicePrivate::createResponse(const QVariantMap &response) const -{ - v8::HandleScope handleScope; - v8::Context::Scope contextScope(debuggerUtilityContext); - - v8::Handle respObj = createV8Object(response); - respObj->Set(v8::String::New(V8_DEBUGGER_KEY_TYPE), v8::String::New("response")); - respObj->Set(v8::String::New(V8_DEBUGGER_KEY_RUNNING), v8::Boolean::New(isRunning)); - v8::Handle stringifyFn = - v8::Local::Cast(debuggerUtility->Get(v8::String::New("stringifyRequest"))); - v8::Handle argv[] = { respObj }; - v8::Handle result = stringifyFn->Call(debuggerScript, 1, argv); - Q_ASSERT(result->IsString()); - - return QJSConverter::toString(result->ToString()); - -} - -v8::Handle QV8DebugServicePrivate::createV8Object(const QVariantMap &map) const -{ - v8::Handle obj = v8::Object::New(); - foreach (const QVariant &var, map) { - v8::Handle key = QJSConverter::toString(map.key(var)); - v8::Handle val; - switch (var.type()) { - case QVariant::Bool: - val = v8::Boolean::New(var.toBool()); - break; - case QVariant::Int: - val = v8::Int32::New(var.toInt()); - break; - case QVariant::String: - val = QJSConverter::toString(var.toString()); - break; - case QVariant::Map: - createV8Object(var.toMap()); - break; - default: - //Add other types when required. - //Not handled currently - break; - } - if (!val.IsEmpty()) - obj->Set(key, val); - } - return obj; -} - QT_END_NAMESPACE diff --git a/src/declarative/debugger/qv8debugservice_p.h b/src/declarative/debugger/qv8debugservice_p.h index 754ae53..9430f95 100644 --- a/src/declarative/debugger/qv8debugservice_p.h +++ b/src/declarative/debugger/qv8debugservice_p.h @@ -54,7 +54,6 @@ // #include "qdeclarativedebugservice_p.h" -#include QT_BEGIN_HEADER @@ -62,7 +61,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeEngine; +class QV8Engine; class QV8DebugServicePrivate; class QV8DebugService : public QDeclarativeDebugService @@ -73,24 +72,28 @@ public: ~QV8DebugService(); static QV8DebugService *instance(); - static void initialize(); + static void initialize(const QV8Engine *engine); - void debugMessageHandler(const QString &message, bool willStartRunning); - - void appendSourcePath(const v8::Handle &eventData); + void debugMessageHandler(const QString &message); void signalEmitted(const QString &signal); +public slots: + void processDebugMessages(); + private slots: - void scheduledDebugBreak(); - void cancelDebugBreak(); - void initialize(bool); + void scheduledDebugBreak(bool schedule); + void sendDebugMessage(const QString &message); + void init(); protected: void statusChanged(Status newStatus); void messageReceived(const QByteArray &); private: + void setEngine(const QV8Engine *engine); + +private: Q_DISABLE_COPY(QV8DebugService) Q_DECLARE_PRIVATE(QV8DebugService) }; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 49239ae..9f2f4a0 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -448,7 +448,7 @@ void QDeclarativeEnginePrivate::init() QDeclarativeEngineDebugService::isDebuggingEnabled()) { isDebugging = true; QDeclarativeEngineDebugService::instance()->addEngine(q); - QV8DebugService::initialize(); + QV8DebugService::initialize(v8engine()); QV8ProfilerService::initialize(); QDeclarativeDebugTrace::initialize(); } diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/breakpointRelocation.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/breakpointRelocation.qml new file mode 100644 index 0000000..d63e5f1 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/breakpointRelocation.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + Component.onCompleted: { + //Comment + + var b = 6; + } +} + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/changeBreakpoint.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/changeBreakpoint.qml new file mode 100644 index 0000000..682cf42 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/changeBreakpoint.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + id: item + property int d: 0 + + function doSomething() { + var a = 5; + var b = 6; + } + + Timer { + id: timer; interval: 1; running: true; repeat: true + onTriggered: doSomething(); + } + +} diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/condition.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/condition.qml new file mode 100644 index 0000000..5b7fb49 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/condition.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + id: item + property int a: 0 + Timer { + id: timer; interval: 1; repeat: true; running: true + onTriggered: a++ + } +} + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/createComponent.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/createComponent.qml new file mode 100644 index 0000000..f4ac843 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/createComponent.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE +Item { + Component.onCompleted: { + var component = Qt.createComponent("oncompleted.qml") + if (component.status === Component.Ready) { + component.createObject(); + } + } +} + + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/exception.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/exception.qml new file mode 100644 index 0000000..ac5bcfb --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/exception.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + id: root + + Component.onCompleted: dummy() +} + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/loadjsfile.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/loadjsfile.qml new file mode 100644 index 0000000..59001c8 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/loadjsfile.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "test.js" as Script + +//DO NOT CHANGE +Item { + Component.onCompleted: Script.printMessage("onCompleted"); +} diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/oncompleted.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/oncompleted.qml new file mode 100644 index 0000000..98d8b91 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/oncompleted.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + Component.onCompleted: { + console.log("Hello world") + } + id: root + property int a: 10 +} + diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/stepAction.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/stepAction.qml new file mode 100644 index 0000000..edb12f4 --- /dev/null +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/stepAction.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +//DO NOT CHANGE + +Item { + id: item + property int d: 0 + + function doSomething() { + var a = 5; + var b = 6; + } + + Component.onCompleted: doSomething() + +} diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml index 3bfeb10..ee1751e 100644 --- a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/test.qml @@ -40,45 +40,15 @@ ****************************************************************************/ import QtQuick 2.0 -import "test.js" as Script //DO NOT CHANGE -Rectangle { - id: root - width: 10; height: 10; - Component.onCompleted: { Script.printMessage("onCompleted"); doSomething(); } - - property int result: 0 - property int someValue: 10 - property bool raiseException: false - - function doSomething() { - var a = root.result; - var b = commonFunction(); - var c = [1,2,3]; - var d = Script.add(a,c[2]); - result += d; - doSomethingElse(); - } - - Timer { - id: timer; interval: 1 - onTriggered: { - doSomething(); - Script.printMessage("onTriggered"); - } - } - - function commonFunction() { - console.log("commonFunction"); - return 5; - } - - function doSomethingElse() { - result = Script.add(result,8); - if (raiseException) - dummy(); +Item { + Component.onCompleted: { + var a = [1, 2] + var b = {a: "hello", d: 1 } + var c + var d = 12 } } diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/timer.qml b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/timer.qml index d48153a..386885d 100644 --- a/tests/auto/declarative/debugger/qdeclarativedebugjs/data/timer.qml +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/data/timer.qml @@ -44,7 +44,7 @@ import QtQuick 2.0 //DO NOT CHANGE Item { Timer { - id: timer; interval: 1000; running: true; repeat: true; triggeredOnStart: true + id: timer; interval: 1; running: true; repeat: true; triggeredOnStart: true onTriggered: { console.log("timer"); } diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro b/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro index 4459738..8f61aae 100644 --- a/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/qdeclarativedebugjs.pro @@ -18,4 +18,12 @@ DEPLOYMENT += testDataFiles CONFIG += parallel_test OTHER_FILES += data/test.qml data/test.js \ - data/timer.qml + data/timer.qml \ + data/exception.qml \ + data/oncompleted.qml \ + data/loadjsfile.qml \ + data/condition.qml \ + data/changeBreakpoint.qml \ + data/stepAction.qml \ + data/breakpointRelocation.qml \ + data/createComponent.qml diff --git a/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index aa50d64..8b40b64 100644 --- a/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/debugger/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -53,6 +53,8 @@ #include "../shared/debugutil_p.h" #include "../../../shared/util.h" +const char *V8REQUEST = "v8request"; +const char *V8MESSAGE = "v8message"; const char *SEQ = "seq"; const char *TYPE = "type"; const char *COMMAND = "command"; @@ -113,6 +115,8 @@ const char *OUT = "out"; const char *FUNCTION = "function"; const char *SCRIPT = "script"; +const char *SCRIPTREGEXP = "scriptRegExp"; +const char *EVENT = "event"; const char *ALL = "all"; const char *UNCAUGHT = "uncaught"; @@ -125,6 +129,14 @@ const char *NORMALMODE = "-qmljsdebugger=port:3771"; const char *TEST_QMLFILE = "test.qml"; const char *TEST_JSFILE = "test.js"; const char *TIMER_QMLFILE = "timer.qml"; +const char *LOADJSFILE_QMLFILE = "loadjsfile.qml"; +const char *EXCEPTION_QMLFILE = "exception.qml"; +const char *ONCOMPLETED_QMLFILE = "oncompleted.qml"; +const char *CREATECOMPONENT_QMLFILE = "createComponent.qml"; +const char *CONDITION_QMLFILE = "condition.qml"; +const char *CHANGEBREAKPOINT_QMLFILE = "changeBreakpoint.qml"; +const char *STEPACTION_QMLFILE = "stepAction.qml"; +const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml"; #define VARIANTMAPINIT \ QString obj("{}"); \ @@ -158,6 +170,8 @@ private slots: void cleanup(); + void connect(); + void interrupt(); void getVersion(); void getVersionWhenAttaching(); @@ -170,12 +184,14 @@ private slots: void listBreakpoints(); void setBreakpointInScriptOnCompleted(); + void setBreakpointInScriptOnComponentCreated(); void setBreakpointInScriptOnTimerCallback(); void setBreakpointInScriptInDifferentFile(); void setBreakpointInScriptOnComment(); void setBreakpointInScriptOnEmptyLine(); void setBreakpointInScriptWithCondition(); //void setBreakpointInFunction(); //NOT SUPPORTED + void setBreakpointOnEvent(); void setBreakpointWhenAttaching(); void changeBreakpoint(); @@ -214,6 +230,7 @@ private: QDeclarativeDebugProcess *process; QJSDebugClient *client; QDeclarativeDebugConnection *connection; + QTime t; }; class QJSDebugClient : public QDeclarativeDebugClient @@ -248,7 +265,7 @@ public: stringify = jsEngine.evaluate(QLatin1String("JSON.stringify")); } - void startDebugging(); + void connect(); void interrupt(); void continueDebugging(StepAction stepAction, int stepCount = 1); @@ -278,21 +295,21 @@ protected: signals: void enabled(); - void breakpointSet(); + void connected(); + void interruptRequested(); void result(); void stopped(); private: void sendMessage(const QByteArray &); void flushSendBuffer(); - QByteArray packMessage(QByteArray message); + QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray()); private: QJSEngine jsEngine; int seq; QList sendBuffer; - public: QJSValue parser; QJSValue stringify; @@ -300,30 +317,14 @@ public: }; -void QJSDebugClient::startDebugging() +void QJSDebugClient::connect() { - // { "seq" : , - // "type" : "request", - // "command" : "connect", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(CONNECT))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(CONNECT)); } void QJSDebugClient::interrupt() { - // { "seq" : , - // "type" : "request", - // "command" : "interrupt", - // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(INTERRUPT))); - - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(INTERRUPT)); } void QJSDebugClient::continueDebugging(StepAction action, int count) @@ -356,7 +357,7 @@ void QJSDebugClient::continueDebugging(StepAction action, int count) } } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::evaluate(QString expr, bool global, bool disableBreak, int frame, const QVariantMap &/*addContext*/) @@ -395,7 +396,7 @@ void QJSDebugClient::evaluate(QString expr, bool global, bool disableBreak, int } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::lookup(QList handles, bool includeSource) @@ -428,7 +429,7 @@ void QJSDebugClient::lookup(QList handles, bool includeSource) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::backtrace(int fromFrame, int toFrame, bool bottom) @@ -460,7 +461,7 @@ void QJSDebugClient::backtrace(int fromFrame, int toFrame, bool bottom) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::frame(int number) @@ -484,7 +485,7 @@ void QJSDebugClient::frame(int number) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::scope(int number, int frameNumber) @@ -512,7 +513,7 @@ void QJSDebugClient::scope(int number, int frameNumber) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::scopes(int frameNumber) @@ -536,7 +537,7 @@ void QJSDebugClient::scopes(int frameNumber) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::scripts(int types, QList ids, bool includeSource, QVariant /*filter*/) @@ -580,7 +581,7 @@ void QJSDebugClient::scripts(int types, QList ids, bool includeSource, QVar } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::source(int frame, int fromLine, int toLine) @@ -613,7 +614,7 @@ void QJSDebugClient::source(int frame, int fromLine, int toLine) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::setBreakpoint(QString type, QString target, int line, int column, bool enabled, QString condition, int ignoreCount) @@ -630,34 +631,43 @@ void QJSDebugClient::setBreakpoint(QString type, QString target, int line, int c // "ignoreCount" : // } // } - VARIANTMAPINIT; - jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETBREAKPOINT))); - QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); + if (type == QLatin1String(EVENT)) { + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + rs << target.toUtf8() << enabled; + sendMessage(packMessage(QByteArray("breakonsignal"), reply)); - args.setProperty(QLatin1String(TYPE),QJSValue(type)); - args.setProperty(QLatin1String(TARGET),QJSValue(target)); + } else { + VARIANTMAPINIT; + jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(SETBREAKPOINT))); - if (line != -1) - args.setProperty(QLatin1String(LINE),QJSValue(line)); + QJSValue args = parser.call(QJSValue(), QJSValueList() << obj); - if (column != -1) - args.setProperty(QLatin1String(COLUMN),QJSValue(column)); + args.setProperty(QLatin1String(TYPE),QJSValue(type)); + args.setProperty(QLatin1String(TARGET),QJSValue(target)); - args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); + if (line != -1) + args.setProperty(QLatin1String(LINE),QJSValue(line)); - if (!condition.isEmpty()) - args.setProperty(QLatin1String(CONDITION),QJSValue(condition)); + if (column != -1) + args.setProperty(QLatin1String(COLUMN),QJSValue(column)); - if (ignoreCount != -1) - args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount)); + args.setProperty(QLatin1String(ENABLED),QJSValue(enabled)); - if (args.isValid()) { - jsonVal.setProperty(QLatin1String(ARGUMENTS),args); - } + if (!condition.isEmpty()) + args.setProperty(QLatin1String(CONDITION),QJSValue(condition)); - QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + if (ignoreCount != -1) + args.setProperty(QLatin1String(IGNORECOUNT),QJSValue(ignoreCount)); + + if (args.isValid()) { + jsonVal.setProperty(QLatin1String(ARGUMENTS),args); + } + + QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); + } } void QJSDebugClient::changeBreakpoint(int breakpoint, bool enabled, QString condition, int ignoreCount) @@ -690,7 +700,7 @@ void QJSDebugClient::changeBreakpoint(int breakpoint, bool enabled, QString cond } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::clearBreakpoint(int breakpoint) @@ -713,7 +723,7 @@ void QJSDebugClient::clearBreakpoint(int breakpoint) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::setExceptionBreak(Exception type, bool enabled) @@ -743,7 +753,7 @@ void QJSDebugClient::setExceptionBreak(Exception type, bool enabled) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::v8flags(QString flags) @@ -766,7 +776,7 @@ void QJSDebugClient::v8flags(QString flags) } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::version() @@ -779,7 +789,7 @@ void QJSDebugClient::version() jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(VERSION))); QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } //void QJSDebugClient::profile(ProfileCommand command) @@ -805,7 +815,7 @@ void QJSDebugClient::version() // } // QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); -// sendMessage(packMessage(json.toString().toUtf8())); +// sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); //} void QJSDebugClient::disconnect() @@ -818,7 +828,7 @@ void QJSDebugClient::disconnect() jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(DISCONNECT))); QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(DISCONNECT, json.toString().toUtf8())); } void QJSDebugClient::gc() @@ -841,7 +851,7 @@ void QJSDebugClient::gc() } QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::listBreakpoints() @@ -854,7 +864,7 @@ void QJSDebugClient::listBreakpoints() jsonVal.setProperty(QLatin1String(COMMAND),QJSValue(QLatin1String(LISTBREAKPOINTS))); QJSValue json = stringify.call(QJSValue(), QJSValueList() << jsonVal); - sendMessage(packMessage(json.toString().toUtf8())); + sendMessage(packMessage(V8REQUEST, json.toString().toUtf8())); } void QJSDebugClient::statusChanged(Status status) @@ -872,50 +882,59 @@ void QJSDebugClient::messageReceived(const QByteArray &data) ds >> command; if (command == "V8DEBUG") { - ds >> response; - QString jsonString(response); - QVariantMap value = parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - QString type = value.value("type").toString(); - - if (type == "response") { - - if (!value.value("success").toBool()) { -// qDebug() << "Error: The test case will fail since no signal is emitted"; - return; - } - - QString debugCommand(value.value("command").toString()); - if (debugCommand == "backtrace" || - debugCommand == "lookup" || - debugCommand == "setbreakpoint" || - debugCommand == "evaluate" || - debugCommand == "listbreakpoints" || - debugCommand == "version" || - debugCommand == "v8flags" || - debugCommand == "disconnect" || - debugCommand == "gc" || - debugCommand == "changebreakpoint" || - debugCommand == "clearbreakpoint" || - debugCommand == "frame" || - debugCommand == "scope" || - debugCommand == "scopes" || - debugCommand == "scripts" || - debugCommand == "source" || - debugCommand == "setexceptionbreak" /*|| - debugCommand == "profile"*/) { - emit result(); - - } else { - // DO NOTHING - } - - } else if (type == "event") { - QString event(value.value("event").toString()); - - if (event == "break" || - event == "exception") { - emit stopped(); - } + QByteArray type; + ds >> type >> response; + + if (type == CONNECT) { + emit connected(); + + } else if (type == INTERRUPT) { + emit interruptRequested(); + + } else if (type == V8MESSAGE) { + QString jsonString(response); + QVariantMap value = parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString type = value.value("type").toString(); + + if (type == "response") { + + if (!value.value("success").toBool()) { +// qDebug() << "Error: The test case will fail since no signal is emitted"; + return; + } + + QString debugCommand(value.value("command").toString()); + if (debugCommand == "backtrace" || + debugCommand == "lookup" || + debugCommand == "setbreakpoint" || + debugCommand == "evaluate" || + debugCommand == "listbreakpoints" || + debugCommand == "version" || + debugCommand == "v8flags" || + debugCommand == "disconnect" || + debugCommand == "gc" || + debugCommand == "changebreakpoint" || + debugCommand == "clearbreakpoint" || + debugCommand == "frame" || + debugCommand == "scope" || + debugCommand == "scopes" || + debugCommand == "scripts" || + debugCommand == "source" || + debugCommand == "setexceptionbreak" /*|| + debugCommand == "profile"*/) { + emit result(); + + } else { + // DO NOTHING + } + + } else if (type == QLatin1String(EVENT)) { + QString event(value.value(QLatin1String(EVENT)).toString()); + + if (event == "break" || + event == "exception") + emit stopped(); + } } } } @@ -936,17 +955,18 @@ void QJSDebugClient::flushSendBuffer() sendBuffer.clear(); } -QByteArray QJSDebugClient::packMessage(QByteArray message) +QByteArray QJSDebugClient::packMessage(const QByteArray &type, const QByteArray &message) { QByteArray reply; QDataStream rs(&reply, QIODevice::WriteOnly); QByteArray cmd = "V8DEBUG"; - rs << cmd << message; + rs << cmd << type << message; return reply; } void tst_QDeclarativeDebugJS::initTestCase() { + t.start(); process = 0; client = 0; connection = 0; @@ -964,6 +984,8 @@ void tst_QDeclarativeDebugJS::cleanupTestCase() if (connection) delete connection; + +// qDebug() << "Time Elapsed:" << t.elapsed(); } bool tst_QDeclarativeDebugJS::init(const QString &qmlFile, bool blockMode) @@ -1009,14 +1031,33 @@ void tst_QDeclarativeDebugJS::cleanup() connection = 0; } +void tst_QDeclarativeDebugJS::connect() +{ + //void connect() + + QVERIFY(init()); + client->connect(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected()))); +} + +void tst_QDeclarativeDebugJS::interrupt() +{ + //void connect() + + QVERIFY(init()); + client->connect(); + + client->interrupt(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(interruptRequested()))); +} + void tst_QDeclarativeDebugJS::getVersion() { //void version() QVERIFY(init()); - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(connected()))); client->version(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1027,9 +1068,7 @@ void tst_QDeclarativeDebugJS::getVersionWhenAttaching() //void version() QVERIFY(init(QLatin1String(TIMER_QMLFILE), false)); - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); client->version(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1040,9 +1079,7 @@ void tst_QDeclarativeDebugJS::applyV8Flags() //void v8flags(QString flags) QVERIFY(init()); - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); client->v8flags(QString()); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1053,9 +1090,7 @@ void tst_QDeclarativeDebugJS::disconnect() //void disconnect() QVERIFY(init()); - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); client->disconnect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1066,9 +1101,7 @@ void tst_QDeclarativeDebugJS::gc() //void gc() QVERIFY(init()); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), 43, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); client->gc(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1078,17 +1111,19 @@ void tst_QDeclarativeDebugJS::listBreakpoints() { //void listBreakpoints() - int sourceLine1 = 57; - int sourceLine2 = 60; - int sourceLine3 = 67; + int sourceLine1 = 47; + int sourceLine2 = 48; + int sourceLine3 = 49; QVERIFY(init()); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), sourceLine3, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_QMLFILE), sourceLine3, -1, true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); client->listBreakpoints(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1104,11 +1139,11 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted() { //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - int sourceLine = 49; - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); @@ -1117,24 +1152,37 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnCompleted() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE)); } -void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback() +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComponentCreated() { - int sourceLine = 49; - QVERIFY(init()); - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - sourceLine = 67; - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + + int sourceLine = 47; + QVERIFY(init(CREATECOMPONENT_QMLFILE)); + + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - client->evaluate("timer.running = true"); - client->continueDebugging(QJSDebugClient::Continue); + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(body.value("sourceLine").toInt(), sourceLine); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(ONCOMPLETED_QMLFILE)); +} +void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback() +{ + int sourceLine = 48; + QVERIFY(init(TIMER_QMLFILE)); + + client->connect(); + + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine, -1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); @@ -1143,7 +1191,7 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnTimerCallback() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE)); } void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile() @@ -1151,10 +1199,10 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptInDifferentFile() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int sourceLine = 43; - QVERIFY(init()); + QVERIFY(init(LOADJSFILE_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TEST_JSFILE), sourceLine, -1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); @@ -1170,14 +1218,14 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment() { //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - int sourceLine = 48; - int actualLine = 50; - QVERIFY(init()); + int sourceLine = 47; + int actualLine = 49; + QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1)); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1185,21 +1233,21 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnComment() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_JSFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE)); } void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine() { //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - int sourceLine = 49; - int actualLine = 50; - QVERIFY(init()); + int sourceLine = 48; + int actualLine = 49; + QVERIFY(init(BREAKPOINTRELOCATION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 1)); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1207,7 +1255,7 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptOnEmptyLine() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_JSFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(BREAKPOINTRELOCATION_QMLFILE)); } void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition() @@ -1215,11 +1263,11 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition() //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) int out = 10; - int sourceLine = 51; - QVERIFY(init()); + int sourceLine = 50; + QVERIFY(init(CONDITION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_JSFILE), sourceLine, -1, true, QLatin1String("out > 10")); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CONDITION_QMLFILE), sourceLine, 1, true, QLatin1String("a > 10")); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); //Get the frame index @@ -1231,7 +1279,7 @@ void tst_QDeclarativeDebugJS::setBreakpointInScriptWithCondition() int frameIndex = body.value("index").toInt(); //Verify the value of 'result' - client->evaluate(QLatin1String("out"),frameIndex); + client->evaluate(QLatin1String("a"),frameIndex); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1248,8 +1296,8 @@ void tst_QDeclarativeDebugJS::setBreakpointWhenAttaching() int sourceLine = 49; QVERIFY(init(QLatin1String(TIMER_QMLFILE), false)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TIMER_QMLFILE), sourceLine); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(TIMER_QMLFILE), sourceLine); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); } @@ -1259,7 +1307,7 @@ void tst_QDeclarativeDebugJS::setBreakpointWhenAttaching() // int actualLine = 31; -// client->startDebugging(); +// client->connect(); // client->setBreakpoint(QLatin1String(FUNCTION), QLatin1String("doSomethingElse"), -1, -1, true); // QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); @@ -1273,17 +1321,38 @@ void tst_QDeclarativeDebugJS::setBreakpointWhenAttaching() // QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QMLFILE)); //} +void tst_QDeclarativeDebugJS::setBreakpointOnEvent() +{ + //void setBreakpoint(QString type, QString target, int line = -1, int column = -1, bool enabled = false, QString condition = QString(), int ignoreCount = -1) + + QVERIFY(init(TIMER_QMLFILE)); + + client->connect(); + + client->setBreakpoint(QLatin1String(EVENT), QLatin1String("triggered"), -1, -1, true); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + + QString jsonString(client->response); + QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + + QVariantMap body = value.value("body").toMap(); + + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TIMER_QMLFILE)); +} + + void tst_QDeclarativeDebugJS::changeBreakpoint() { //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - int sourceLine1 = 78; - int sourceLine2 = 79; - QVERIFY(init()); + int sourceLine1 = 50; + int sourceLine2 = 51; + QVERIFY(init(CHANGEBREAKPOINT_QMLFILE)); + + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); - client->startDebugging(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); //Will hit 1st brakpoint, change this breakpoint enable = false @@ -1303,9 +1372,6 @@ void tst_QDeclarativeDebugJS::changeBreakpoint() //Hit 2nd breakpoint QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - // start timer - client->evaluate("timer.running = true"); - //Continue with debugging client->continueDebugging(QJSDebugClient::Continue); //Should stop at 2nd breakpoint @@ -1323,14 +1389,15 @@ void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() { //void changeBreakpoint(int breakpoint, bool enabled = false, QString condition = QString(), int ignoreCount = -1) - int sourceLine1 = 56; - int sourceLine2 = 60; - int result = 0; - QVERIFY(init()); + int sourceLine1 = 50; + int sourceLine2 = 51; + + QVERIFY(init(CHANGEBREAKPOINT_QMLFILE)); + + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); - client->startDebugging(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); //Will hit 1st brakpoint, change this breakpoint enable = false @@ -1341,7 +1408,7 @@ void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() QList breakpointsHit = body.value("breakpoints").toList(); int breakpoint = breakpointsHit.at(0).toInt(); - client->changeBreakpoint(breakpoint,false,QLatin1String("a = 0")); + client->changeBreakpoint(breakpoint, false, QLatin1String("d == 0")); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1349,8 +1416,7 @@ void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() client->continueDebugging(QJSDebugClient::Continue); //Hit 2nd breakpoint QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - // start timer - client->evaluate("timer.running = true"); + //Continue with debugging client->continueDebugging(QJSDebugClient::Continue); //Should stop at 2nd breakpoint @@ -1363,41 +1429,20 @@ void tst_QDeclarativeDebugJS::changeBreakpointOnCondition() QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); - client->frame(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - //Get the frame index - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - int frameIndex = body.value("index").toInt(); - - //Verify the value of 'result' - client->evaluate(QLatin1String("root.result"),frameIndex); - - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - - jsonString = client->response; - value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); - - body = value.value("body").toMap(); - - QVERIFY(body.value("value").toInt() > result); } void tst_QDeclarativeDebugJS::clearBreakpoint() { //void clearBreakpoint(int breakpoint); - int sourceLine1 = 78; - int sourceLine2 = 79; - QVERIFY(init()); + int sourceLine1 = 50; + int sourceLine2 = 51; + QVERIFY(init(CHANGEBREAKPOINT_QMLFILE)); + + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); - client->startDebugging(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); //Will hit 1st brakpoint, change this breakpoint enable = false @@ -1408,7 +1453,7 @@ void tst_QDeclarativeDebugJS::clearBreakpoint() QList breakpointsHit = body.value("breakpoints").toList(); int breakpoint = breakpointsHit.at(0).toInt(); - client->changeBreakpoint(breakpoint,false,QLatin1String("result > 5")); + client->clearBreakpoint(breakpoint); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1416,8 +1461,7 @@ void tst_QDeclarativeDebugJS::clearBreakpoint() client->continueDebugging(QJSDebugClient::Continue); //Hit 2nd breakpoint QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - // start timer - client->evaluate("timer.running = true"); + //Continue with debugging client->continueDebugging(QJSDebugClient::Continue); //Should stop at 2nd breakpoint @@ -1435,32 +1479,25 @@ void tst_QDeclarativeDebugJS::setExceptionBreak() { //void setExceptionBreak(QString type, bool enabled = false); - int sourceLine = 49; - QVERIFY(init()); - - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); + QVERIFY(init(EXCEPTION_QMLFILE)); client->setExceptionBreak(QJSDebugClient::All,true); - client->startDebugging(); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - client->evaluate("root.raiseException = true"); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); } void tst_QDeclarativeDebugJS::stepNext() { //void continueDebugging(StepAction stepAction, int stepCount = 1); - int sourceLine = 57; - QVERIFY(init()); + int sourceLine = 50; + QVERIFY(init(STEPACTION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->continueDebugging(QJSDebugClient::Next); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1468,22 +1505,22 @@ void tst_QDeclarativeDebugJS::stepNext() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 1); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE)); } void tst_QDeclarativeDebugJS::stepNextWithCount() { //void continueDebugging(StepAction stepAction, int stepCount = 1); - int sourceLine = 59; - QVERIFY(init()); + int sourceLine = 50; + QVERIFY(init(STEPACTION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - client->continueDebugging(QJSDebugClient::Next,2); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + client->continueDebugging(QJSDebugClient::Next, 2); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1491,23 +1528,23 @@ void tst_QDeclarativeDebugJS::stepNextWithCount() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine + 2); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE)); } void tst_QDeclarativeDebugJS::stepIn() { //void continueDebugging(StepAction stepAction, int stepCount = 1); - int sourceLine = 61; - int actualLine = 78; - QVERIFY(init()); + int sourceLine = 54; + int actualLine = 50; + QVERIFY(init(STEPACTION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->continueDebugging(QJSDebugClient::In); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1515,23 +1552,23 @@ void tst_QDeclarativeDebugJS::stepIn() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE)); } void tst_QDeclarativeDebugJS::stepOut() { //void continueDebugging(StepAction stepAction, int stepCount = 1); - int sourceLine = 56; - int actualLine = 49; - QVERIFY(init()); + int sourceLine = 50; + int actualLine = 54; + QVERIFY(init(STEPACTION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->continueDebugging(QJSDebugClient::Out); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1539,24 +1576,24 @@ void tst_QDeclarativeDebugJS::stepOut() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), actualLine); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE)); } void tst_QDeclarativeDebugJS::continueDebugging() { //void continueDebugging(StepAction stepAction, int stepCount = 1); - int sourceLine1 = 56; - int sourceLine2 = 60; - QVERIFY(init()); + int sourceLine1 = 54; + int sourceLine2 = 51; + QVERIFY(init(STEPACTION_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine2, -1, true); - client->startDebugging(); + client->connect(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()), 10000)); + QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); QString jsonString(client->response); QVariantMap value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1564,18 +1601,18 @@ void tst_QDeclarativeDebugJS::continueDebugging() QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine2); - QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(TEST_QMLFILE)); + QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(STEPACTION_QMLFILE)); } void tst_QDeclarativeDebugJS::backtrace() { //void backtrace(int fromFrame = -1, int toFrame = -1, bool bottom = false); - int sourceLine = 60; - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->backtrace(); @@ -1586,11 +1623,11 @@ void tst_QDeclarativeDebugJS::getFrameDetails() { //void frame(int number = -1); - int sourceLine = 60; - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->frame(); @@ -1601,11 +1638,11 @@ void tst_QDeclarativeDebugJS::getScopeDetails() { //void scope(int number = -1, int frameNumber = -1); - int sourceLine = 60; - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->scope(); @@ -1616,14 +1653,10 @@ void tst_QDeclarativeDebugJS::evaluateInGlobalScope() { //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - int sourceLine = 49; QVERIFY(init()); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); - - client->evaluate(QLatin1String("print('Hello World')"),true); + client->connect(); + client->evaluate(QLatin1String("print('Hello World')"), true); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); //Verify the value of 'print' @@ -1639,11 +1672,11 @@ void tst_QDeclarativeDebugJS::evaluateInLocalScope() { //void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap()); - int sourceLine = 60; - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->setBreakpoint(QLatin1String(SCRIPT), QLatin1String(TEST_QMLFILE), sourceLine, -1, true); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->frame(); @@ -1657,10 +1690,10 @@ void tst_QDeclarativeDebugJS::evaluateInLocalScope() int frameIndex = body.value("index").toInt(); - client->evaluate(QLatin1String("root.someValue"),frameIndex); + client->evaluate(QLatin1String("root.a"), frameIndex); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); - //Verify the value of 'root.someValue' + //Verify the value of 'timer.interval' jsonString = client->response; value = client->parser.call(QJSValue(), QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); @@ -1673,10 +1706,11 @@ void tst_QDeclarativeDebugJS::getScopes() { //void scopes(int frameNumber = -1); - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->interrupt(); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->scopes(); @@ -1687,11 +1721,9 @@ void tst_QDeclarativeDebugJS::getScripts() { //void scripts(int types = -1, QList ids = QList(), bool includeSource = false, QVariant filter = QVariant()); - QVERIFY(init(QLatin1String(TIMER_QMLFILE), true)); + QVERIFY(init()); - client->interrupt(); - client->startDebugging(); - QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); + client->connect(); client->scripts(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(result()))); @@ -1709,10 +1741,11 @@ void tst_QDeclarativeDebugJS::getSource() { //void source(int frame = -1, int fromLine = -1, int toLine = -1); - QVERIFY(init()); + int sourceLine = 47; + QVERIFY(init(ONCOMPLETED_QMLFILE)); - client->interrupt(); - client->startDebugging(); + client->setBreakpoint(QLatin1String(SCRIPTREGEXP), QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + client->connect(); QVERIFY(QDeclarativeDebugTest::waitForSignal(client, SIGNAL(stopped()))); client->source(); -- 2.7.4