32 QV4::Scope scope(engine);
34 QV4::ScopedContext ctx(scope, engine->currentStackFrame ? engine->currentContext()
35 : engine->scriptContext());
37 QV4::CppStackFrame *frame = engine->currentStackFrame;
39 for (
int i = 0; frame && i < frameNr; ++i)
40 frame = frame->parentFrame();
41 if (frameNr > 0 && frame)
42 ctx = frame->context();
45 QObject *forId = QQmlDebugService::objectForId(context);
46 QQmlContext *extraContext = qmlContext(forId);
48 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), forId);
49 }
else if (frameNr < 0) {
50 QQmlEngine *qmlEngine = engine->qmlEngine();
52 QQmlContext *qmlRootContext = qmlEngine->rootContext();
53 QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(qmlRootContext);
55 QV4::ScopedObject withContext(scope, engine->newObject());
56 QV4::ScopedString k(scope);
57 QV4::ScopedValue v(scope);
58 const QList<QPointer<QObject>> instances = ctxtPriv->instances();
59 for (
const QPointer<QObject> &object : instances) {
60 if (QQmlContext *context = qmlContext(object.data())) {
61 if (QQmlRefPointer<QQmlContextData> cdata = QQmlContextData::get(context)) {
62 v = QV4::QObjectWrapper::wrap(engine, object);
63 k = engine->newString(cdata->findObjectId(object));
64 withContext->put(k, v);
68 if (!engine->qmlContext())
69 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext),
nullptr);
73 QV4::Script script(ctx, QV4::Compiler::ContextType::Eval,
this->script);
74 if (
const QV4::Function *function = frame ? frame->v4Function : engine->globalCode)
75 script.setStrictMode(function->isStrict());
79 script.setInheritContext();
81 QV4::ScopedValue result(scope);
82 if (!scope.hasException()) {
84 QV4::ScopedValue thisObject(scope, frame->thisObject());
85 result = script.run(thisObject);
87 result = script.run();
90 if (scope.hasException()) {
91 result = scope.engine->catchException();
92 resultIsException =
true;
109 QJsonArray frameArray;
110 QVector<QV4::StackFrame> frames =
collector->engine()->stackTrace(toFrame);
111 for (
int i = fromFrame; i < toFrame && i < frames.size(); ++i)
112 frameArray.push_back(
collector->buildFrame(frames[i], i));
113 if (frameArray.isEmpty()) {
114 result.insert(QStringLiteral(
"totalFrames"), 0);
116 result.insert(QStringLiteral(
"fromFrame"), fromFrame);
117 result.insert(QStringLiteral(
"toFrame"), fromFrame + frameArray.size());
118 result.insert(QStringLiteral(
"frames"), frameArray);
151 success =
collector->collectScope(&object, frameNr, scopeNr);
154 QVector<QV4::Heap::ExecutionContext::ContextType> scopeTypes =
156 result[QLatin1String(
"type")] = QV4DataCollector::encodeScopeType(scopeTypes[scopeNr]);
158 result[QLatin1String(
"type")] = -1;
160 result[QLatin1String(
"index")] = scopeNr;
161 result[QLatin1String(
"frameIndex")] = frameNr;
162 result[QLatin1String(
"object")] = object;
178 QScopedPointer<QObject> scopeObject;
179 QV4::ExecutionEngine *engine =
collector->engine();
180 QV4::Scope scope(engine);
181 QV4::Heap::ExecutionContext *qmlContext = engine->qmlContext();
182 if (engine->qmlEngine() && !qmlContext) {
183 scopeObject.reset(
new QObject);
184 qmlContext = QV4::QmlContext::create(engine->currentContext(),
185 QQmlContextData::get(engine->qmlEngine()->rootContext()),
188 QV4::Scoped<QV4::ExecutionContext> scopedContext(scope, qmlContext);
189 QV4::ScopedStackFrame frame(scope, scopedContext);
190 for (
const QJsonValue handle : handles) {
191 QV4DataCollector::Ref ref = handle.toInt();
192 if (!collector->isValidRef(ref)) {
193 exception = QString::fromLatin1(
"Invalid Ref: %1").arg(ref);
196 result[QString::number(ref)] = collector->lookupRef(ref);