33 QV4::Scope scope(engine);
35 QV4::ScopedContext ctx(scope, engine->currentStackFrame ? engine->currentContext()
36 : engine->scriptContext());
38 QV4::CppStackFrame *frame = engine->currentStackFrame;
40 for (
int i = 0; frame && i < frameNr; ++i)
41 frame = frame->parentFrame();
42 if (frameNr > 0 && frame)
43 ctx = frame->context();
46 QObject *forId = QQmlDebugService::objectForId(context);
47 QQmlContext *extraContext = qmlContext(forId);
49 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(extraContext), forId);
50 }
else if (frameNr < 0) {
51 QQmlEngine *qmlEngine = engine->qmlEngine();
53 QQmlContext *qmlRootContext = qmlEngine->rootContext();
54 QQmlContextPrivate *ctxtPriv = QQmlContextPrivate::get(qmlRootContext);
56 QV4::ScopedObject withContext(scope, engine->newObject());
57 QV4::ScopedString k(scope);
58 QV4::ScopedValue v(scope);
59 const QList<QPointer<QObject>> instances = ctxtPriv->instances();
60 for (
const QPointer<QObject> &object : instances) {
61 if (QQmlContext *context = qmlContext(object.data())) {
62 if (QQmlRefPointer<QQmlContextData> cdata = QQmlContextData::get(context)) {
63 v = QV4::QObjectWrapper::wrap(engine, object);
64 k = engine->newString(cdata->findObjectId(object));
65 withContext->put(k, v);
69 if (!engine->qmlContext())
70 ctx = QV4::QmlContext::create(ctx, QQmlContextData::get(qmlRootContext),
nullptr);
74 QV4::Script script(ctx, QV4::Compiler::ContextType::Eval,
this->script);
75 if (
const QV4::Function *function = frame ? frame->v4Function : engine->globalCode)
76 script.setStrictMode(function->isStrict());
80 script.setInheritContext();
82 QV4::ScopedValue result(scope);
83 if (!scope.hasException()) {
85 QV4::ScopedValue thisObject(scope, frame->thisObject());
86 result = script.run(thisObject);
88 result = script.run();
91 if (scope.hasException()) {
92 result = scope.engine->catchException();
93 resultIsException =
true;
110 QJsonArray frameArray;
111 QVector<QV4::StackFrame> frames =
collector->engine()->stackTrace(toFrame);
112 for (
int i = fromFrame; i < toFrame && i < frames.size(); ++i)
113 frameArray.push_back(
collector->buildFrame(frames[i], i));
114 if (frameArray.isEmpty()) {
115 result.insert(QStringLiteral(
"totalFrames"), 0);
117 result.insert(QStringLiteral(
"fromFrame"), fromFrame);
118 result.insert(QStringLiteral(
"toFrame"), fromFrame + frameArray.size());
119 result.insert(QStringLiteral(
"frames"), frameArray);
152 success =
collector->collectScope(&object, frameNr, scopeNr);
155 QVector<QV4::Heap::ExecutionContext::ContextType> scopeTypes =
157 result[QLatin1String(
"type")] = QV4DataCollector::encodeScopeType(scopeTypes[scopeNr]);
159 result[QLatin1String(
"type")] = -1;
161 result[QLatin1String(
"index")] = scopeNr;
162 result[QLatin1String(
"frameIndex")] = frameNr;
163 result[QLatin1String(
"object")] = object;
179 QScopedPointer<QObject> scopeObject;
180 QV4::ExecutionEngine *engine =
collector->engine();
181 QV4::Scope scope(engine);
182 QV4::Heap::ExecutionContext *qmlContext = engine->qmlContext();
183 if (engine->qmlEngine() && !qmlContext) {
184 scopeObject.reset(
new QObject);
185 qmlContext = QV4::QmlContext::create(engine->currentContext(),
186 QQmlContextData::get(engine->qmlEngine()->rootContext()),
189 QV4::Scoped<QV4::ExecutionContext> scopedContext(scope, qmlContext);
190 QV4::ScopedStackFrame frame(scope, scopedContext);
191 for (
const QJsonValue handle : handles) {
192 QV4DataCollector::Ref ref = handle.toInt();
193 if (!collector->isValidRef(ref)) {
194 exception = QString::fromLatin1(
"Invalid Ref: %1").arg(ref);
197 result[QString::number(ref)] = collector->lookupRef(ref);