Commit 3a88a829 authored by Olivier Goffart's avatar Olivier Goffart
Browse files

QML JS Debugger: Ability to edit properties from the debugger

parent f5249f06
......@@ -517,7 +517,19 @@ void QmlEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEd
void QmlEngine::assignValueInDebugger(const QString &expression,
const QString &value)
{
XSDEBUG("ASSIGNING: " << expression + '=' + value);
QRegExp inObject("@([0-9a-fA-F]+)->(.+)");
if (inObject.exactMatch(expression)) {
bool ok = false;
quint64 objectId = inObject.cap(1).toULongLong(&ok, 16);
QString property = inObject.cap(2);
if (ok && objectId > 0 && !property.isEmpty()) {
QByteArray reply;
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("SET_PROPERTY");
rs << expression.toUtf8() << objectId << property << value;
sendMessage(reply);
}
}
}
void QmlEngine::updateWatchData(const WatchData &data)
......
......@@ -121,6 +121,7 @@ static QList<JSAgentWatchData> expandObject(const QScriptValue &object)
{
QList<JSAgentWatchData> result;
QScriptValueIterator it(object);
QByteArray expPrefix = '@' + QByteArray::number(object.objectId(), 16) + "->";
while (it.hasNext()) {
it.next();
if (it.flags() & QScriptValue::SkipInEnumeration)
......@@ -130,7 +131,9 @@ static QList<JSAgentWatchData> expandObject(const QScriptValue &object)
// and it is not usefull in the debugger.
continue;
}
result << JSAgentWatchData::fromScriptValue(it.name(), it.value());
JSAgentWatchData data = JSAgentWatchData::fromScriptValue(it.name(), it.value());
data.exp.prepend(expPrefix);
result << data;
}
return result;
}
......@@ -368,6 +371,31 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
QDataStream rs(&reply, QIODevice::WriteOnly);
rs << QByteArray("LOCALS") << frameId << locals;
sendMessage(reply);
} else if (command == "SET_PROPERTY") {
State oldState = state;
state = Stopped;
QByteArray id;
qint64 objectId;
QString property;
QString value;
ds >> id >> objectId >> property >> value;
if (knownObjectIds.contains(objectId)) {
QScriptValue object;
object = engine()->objectById(objectId);
if(object.isObject()) {
QScriptValue result = engine()->evaluate(value);
object.setProperty(property, result);
}
// Clear any exceptions occurred during locals evaluation.
engine()->clearExceptions();
}
state = oldState;
//TODO: feedback
} else {
qDebug() << Q_FUNC_INFO << "Unknown command" << command;
}
......@@ -414,6 +442,7 @@ void JSDebuggerAgent::stopped()
recordKnownObjects(watches);
recordKnownObjects(locals);
knownObjectIds << activationObject.objectId();
// Clear any exceptions occurred during locals evaluation.
engine()->clearExceptions();
......
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