Commit 91b6d329 authored by Olivier Goffart's avatar Olivier Goffart
Browse files

QML JS Debugger: Break when there is an uncaught exception

parent e139238d
......@@ -59,6 +59,7 @@
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QToolTip>
#include <QtGui/QTextDocument>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QHostAddress>
......@@ -75,6 +76,7 @@
# define XSDEBUG(s) qDebug() << s
namespace Debugger {
namespace Internal {
......@@ -656,6 +658,16 @@ void QmlEngine::messageReceived(const QByteArray &message)
Debugger::DebuggerUISwitcher *uiSwitcher = Debugger::DebuggerUISwitcher::instance();
uiSwitcher->setActiveLanguage("C++");
bool becauseOfexception;
stream >> becauseOfexception;
if (becauseOfexception) {
QString error;
stream >> error;
QString msg = tr("<p>An Uncaught Exception occured in <i>%1</i>:</p><p>%2</p>").arg(stackFrames.value(0).file, Qt::escape(error));
showMessageBox(QMessageBox::Information, tr("Uncaught Exception"), msg);
}
} else if (command == "RESULT") {
WatchData data;
......
......@@ -303,9 +303,9 @@ void JSDebuggerAgent::exceptionThrow(qint64 scriptId,
bool hasHandler)
{
Q_UNUSED(scriptId);
Q_UNUSED(exception);
Q_UNUSED(hasHandler);
/* ... */
// qDebug() << Q_FUNC_INFO << exception.toString() << hasHandler;
if (!hasHandler && state != Stopped)
stopped(true, exception);
}
/*!
......@@ -427,7 +427,7 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
QDeclarativeDebugService::messageReceived(message);
}
void JSDebuggerAgent::stopped()
void JSDebuggerAgent::stopped(bool becauseOfException, const QScriptValue& exception)
{
knownObjectIds.clear();
state = Stopped;
......@@ -464,12 +464,14 @@ void JSDebuggerAgent::stopped()
QList<JSAgentWatchData> locals = getLocals(engine()->currentContext());
// Clear any exceptions occurred during locals evaluation.
engine()->clearExceptions();
if (!becauseOfException) {
// Clear any exceptions occurred during locals evaluation.
engine()->clearExceptions();
}
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("STOPPED") << backtrace << watches << locals;
rs << QByteArray("STOPPED") << backtrace << watches << locals << becauseOfException << exception.toString();
sendMessage(reply);
loop.exec(QEventLoop::ExcludeUserInputEvents);
......
......@@ -54,6 +54,7 @@
//
#include <QtScript/qscriptengineagent.h>
#include <QtScript/QScriptValue>
#include <QtCore/QEventLoop>
#include <QtCore/QSet>
#include <private/qdeclarativedebugservice_p.h>
......@@ -118,7 +119,7 @@ private:
int stepCount;
void continueExec();
void stopped();
void stopped(bool becauseOfException = false, const QScriptValue &exception = QScriptValue());
void recordKnownObjects(const QList<JSAgentWatchData> &);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment