Allow QQmlEngine to load the compilation unit from url

This seems fairly essential one way or another since e.g. QQmlContext
uses the compilation unit to set up some of the internal data members.
Add a new method to the private API of QQmlEngine. This API could be
used by the object creation compiler to set up different parts of the
object (again, QQmlContext)

Change-Id: I25894ab74606793ade391bafd8eb5b1cbfbe0952
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Andrei Golubev 2021-06-21 11:41:57 +02:00
parent 46f5640824
commit 562ba78426
2 changed files with 12 additions and 4 deletions

View File

@ -2262,16 +2262,13 @@ void QQmlEnginePrivate::executeRuntimeFunction(const QUrl &url, qsizetype functi
QMetaType *types)
{
Q_Q(QQmlEngine);
const auto unit = typeLoader.getType(url)->compilationUnit();
const auto unit = compilationUnitFromUrl(url);
if (!unit)
return;
Q_ASSERT(functionIndex >= 0);
Q_ASSERT(thisObject);
if (!unit->engine)
unit->linkToEngine(q->handle());
if (unit->runtimeFunctions.length() <= functionIndex)
return;
@ -2284,6 +2281,16 @@ void QQmlEnginePrivate::executeRuntimeFunction(const QUrl &url, qsizetype functi
QQmlContextData::get(ctx), argc, args, types);
}
QV4::ExecutableCompilationUnit *QQmlEnginePrivate::compilationUnitFromUrl(const QUrl &url)
{
auto unit = typeLoader.getType(url)->compilationUnit();
if (!unit)
return nullptr;
if (!unit->engine)
unit->linkToEngine(v4engine());
return unit;
}
#if defined(Q_OS_WIN)
// Normalize a file name using Shell API. As opposed to converting it
// to a short 8.3 name and back, this also works for drives where 8.3 notation

View File

@ -297,6 +297,7 @@ public:
void executeRuntimeFunction(const QUrl &url, qsizetype functionIndex, QObject *thisObject,
int argc = 0, void **args = nullptr, QMetaType *types = nullptr);
QV4::ExecutableCompilationUnit *compilationUnitFromUrl(const QUrl &url);
private:
class SingletonInstances : private QHash<QQmlType, QJSValue>