summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-07-23 12:14:24 +0200
committerOlivier Goffart <olivier.goffart@nokia.com>2010-07-23 12:14:24 +0200
commite31e0de9ad75a31500be994c3057776be6f5bb0d (patch)
tree37ffdebbcc0cc494bbe05e81768e291fef3a2013 /src
parent70f3f5d02941d844fbf7e87b734b5b9027fc0590 (diff)
downloadqt-creator-e31e0de9ad75a31500be994c3057776be6f5bb0d.tar.gz
QML JS Debugger: use RIIA for initializeing an evaluation context
Diffstat (limited to 'src')
-rw-r--r--src/tools/qml/qmlobserver/jsdebuggeragent.cpp51
-rw-r--r--src/tools/qml/qmlobserver/jsdebuggeragent.h2
2 files changed, 30 insertions, 23 deletions
diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
index 9d3dbec225..e6007676e9 100644
--- a/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
+++ b/src/tools/qml/qmlobserver/jsdebuggeragent.cpp
@@ -52,6 +52,26 @@
QT_BEGIN_NAMESPACE
+class JSDebuggerAgent::SetupExecEnv {
+ JSDebuggerAgent* agent;
+ JSDebuggerAgent::State previousState;
+ bool hadException;
+public:
+ SetupExecEnv(JSDebuggerAgent *a)
+ : agent(a),
+ previousState(a->state),
+ hadException(a->engine()->hasUncaughtException())
+ {
+ agent->state = JSDebuggerAgent::Stopped;
+ }
+
+ ~SetupExecEnv() {
+ if (!hadException && agent->engine()->hasUncaughtException())
+ agent->engine()->clearExceptions();
+ agent->state = previousState;
+ }
+};
+
class JSAgentWatchData {
public:
QByteArray exp;
@@ -323,25 +343,22 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
state = NoState;
continueExec();
} else if (command == "EXEC") {
- State oldState = state;
- state = Stopped;
+ SetupExecEnv execEnv(this);
+
QByteArray id;
QString expr;
ds >> id >> expr;
JSAgentWatchData data = JSAgentWatchData::fromScriptValue(expr, engine()->evaluate(expr));
knownObjectIds << data.objectId;
- // Clear any exceptions occurred during locals evaluation.
- engine()->clearExceptions();
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("RESULT") << id << data;
sendMessage(reply);
- state = oldState;
} else if (command == "EXPAND") {
- State oldState = state;
- state = Stopped;
+ SetupExecEnv execEnv(this);
+
QByteArray requestId;
quint64 objectId;
ds >> requestId >> objectId;
@@ -352,17 +369,13 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
QList<JSAgentWatchData> result = expandObject(v);
recordKnownObjects(result);
- // Clear any exceptions occurred during locals evaluation.
- engine()->clearExceptions();
-
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("EXPANDED") << requestId << result;
sendMessage(reply);
- state = oldState;
+
} else if (command == "ACTIVATE_FRAME") {
- State oldState = state;
- state = Stopped;
+ SetupExecEnv execEnv(this);
int frameId;
ds >> frameId;
@@ -376,17 +389,12 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
QList<JSAgentWatchData> locals = getLocals(ctx);
- // Clear any exceptions occurred during locals evaluation.
- engine()->clearExceptions();
-
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("LOCALS") << frameId << locals;
sendMessage(reply);
- state = oldState;
} else if (command == "SET_PROPERTY") {
- State oldState = state;
- state = Stopped;
+ SetupExecEnv execEnv(this);
QByteArray id;
qint64 objectId;
@@ -402,11 +410,8 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
QScriptValue result = engine()->evaluate(value);
object.setProperty(property, result);
}
-
- // Clear any exceptions occurred during locals evaluation.
- engine()->clearExceptions();
}
- state = oldState;
+
//TODO: feedback
} else if (command == "PING") {
int ping;
diff --git a/src/tools/qml/qmlobserver/jsdebuggeragent.h b/src/tools/qml/qmlobserver/jsdebuggeragent.h
index ee8cd049cc..93d4b75095 100644
--- a/src/tools/qml/qmlobserver/jsdebuggeragent.h
+++ b/src/tools/qml/qmlobserver/jsdebuggeragent.h
@@ -103,6 +103,8 @@ public slots:
// void pauses();
private:
+ class SetupExecEnv;
+ friend class SetupExecEnv;
enum State {
NoState,