aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2016-12-07 14:24:04 +0100
committerUlf Hermann <ulf.hermann@qt.io>2016-12-09 12:51:51 +0000
commitbff7302fc277d18b5bd4ad95d35b9e1bbc2be001 (patch)
tree8ba4cc517e513b0a519ebdab4b99ba1146960d8c /src/plugins
parent3dd96630a2823ff9723a399c84303f565abce455 (diff)
V4 Debugger: Add an option to pass additional context for evaluate
Interpret the "context" option as an ID for a QObject whose QML context is then injected when evaluating the expression. The QObject needs to be tracked by some other debug service for this to work, e.g. the QML debugger or the inspector. Task-number: QTCREATORBUG-17177 Change-Id: I6a9e8b9ae23e8bb67ed1905a2ef73f7c4faeb990 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp40
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h7
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp5
3 files changed, 34 insertions, 18 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
index 4e4048f6ad..6c1e353b4d 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp
@@ -42,6 +42,7 @@
#include <private/qv4script_p.h>
#include <private/qqmlcontext_p.h>
#include <private/qv4qobjectwrapper_p.h>
+#include <private/qqmldebugservice_p.h>
#include <QtQml/qqmlengine.h>
@@ -51,9 +52,10 @@ QV4DebugJob::~QV4DebugJob()
{
}
-JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr,
- const QString &script) :
- engine(engine), frameNr(frameNr), script(script), resultIsException(false)
+JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context,
+ const QString &script) :
+ engine(engine), frameNr(frameNr), context(context), script(script),
+ resultIsException(false)
{}
void JavaScriptJob::run()
@@ -64,7 +66,23 @@ void JavaScriptJob::run()
QV4::ExecutionContext *ctx = engine->currentContext;
QObject scopeObject;
- if (frameNr < 0) { // Use QML context if available
+
+ if (frameNr > 0) {
+ for (int i = 0; i < frameNr; ++i) {
+ ctx = engine->parentContext(ctx);
+ }
+ engine->pushContext(ctx);
+ ctx = engine->currentContext;
+ }
+
+ if (context >= 0) {
+ QQmlContext *extraContext = qmlContext(QQmlDebugService::objectForId(context));
+ if (extraContext) {
+ engine->pushContext(ctx->newQmlContext(QQmlContextData::get(extraContext),
+ &scopeObject));
+ ctx = engine->currentContext;
+ }
+ } else if (frameNr < 0) { // Use QML context if available
QQmlEngine *qmlEngine = engine->qmlEngine();
if (qmlEngine) {
QQmlContext *qmlRootContext = qmlEngine->rootContext();
@@ -88,13 +106,6 @@ void JavaScriptJob::run()
engine->pushContext(ctx->newWithContext(withContext->toObject(engine)));
ctx = engine->currentContext;
}
- } else {
- if (frameNr > 0) {
- for (int i = 0; i < frameNr; ++i) {
- ctx = engine->parentContext(ctx);
- }
- engine->pushContext(ctx);
- }
}
QV4::Script script(ctx, this->script);
@@ -224,8 +235,9 @@ const QString &ValueLookupJob::exceptionMessage() const
}
ExpressionEvalJob::ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr,
- const QString &expression, QV4DataCollector *collector) :
- JavaScriptJob(engine, frameNr, expression), collector(collector)
+ int context, const QString &expression,
+ QV4DataCollector *collector) :
+ JavaScriptJob(engine, frameNr, context, expression), collector(collector)
{
}
@@ -271,7 +283,7 @@ const QStringList &GatherSourcesJob::result() const
}
EvalJob::EvalJob(QV4::ExecutionEngine *engine, const QString &script) :
- JavaScriptJob(engine, /*frameNr*/-1, script), result(false)
+ JavaScriptJob(engine, /*frameNr*/-1, /*context*/ -1, script), result(false)
{}
void EvalJob::handleResult(QV4::ScopedValue &result)
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
index b28adffae5..00d3e6206a 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.h
@@ -60,11 +60,12 @@ class JavaScriptJob : public QV4DebugJob
{
QV4::ExecutionEngine *engine;
int frameNr;
+ int context;
const QString &script;
bool resultIsException;
public:
- JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, const QString &script);
+ JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, int context, const QString &script);
void run() override;
bool hasExeption() const;
@@ -135,8 +136,8 @@ class ExpressionEvalJob: public JavaScriptJob
QJsonArray collectedRefs;
public:
- ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, const QString &expression,
- QV4DataCollector *collector);
+ ExpressionEvalJob(QV4::ExecutionEngine *engine, int frameNr, int context,
+ const QString &expression, QV4DataCollector *collector);
void handleResult(QV4::ScopedValue &value) override;
const QString &exceptionMessage() const;
const QJsonObject &returnValue() const;
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
index de97b5437b..1d2cc092dc 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
@@ -177,6 +177,7 @@ public:
body.insert(QStringLiteral("V8Version"),
QLatin1String("this is not V8, this is V4 in Qt " QT_VERSION_STR));
body.insert(QStringLiteral("UnpausedEvaluate"), true);
+ body.insert(QStringLiteral("ContextEvaluate"), true);
addBody(body);
}
};
@@ -610,6 +611,7 @@ public:
{
QJsonObject arguments = req.value(QLatin1String("arguments")).toObject();
QString expression = arguments.value(QLatin1String("expression")).toString();
+ int context = arguments.value(QLatin1String("context")).toInt(-1);
int frame = -1;
QV4Debugger *debugger = debugService->debuggerAgent.pausedDebugger();
@@ -627,7 +629,8 @@ public:
frame = arguments.value(QLatin1String("frame")).toInt(0);
}
- ExpressionEvalJob job(debugger->engine(), frame, expression, debugger->collector());
+ ExpressionEvalJob job(debugger->engine(), frame, context, expression,
+ debugger->collector());
debugger->runInEngine(&job);
if (job.hasExeption()) {
createErrorResponse(job.exceptionMessage());