From be6d1499af75228341227d15441284e07cfe1e41 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 21 Dec 2023 16:53:36 +0100 Subject: QtQml: Always link executable CU on creation We don't want floating unlinked executable CUs. They should always be tied to an engine, and the engine should not change. This gives us one definite point where to register them with the engine (to be done in subsequent change). Unfortunately, due to the refcounting, we need to remove the engine from any still-referenced CUs when the engine itself is destructed. We will be able to drop the refcounting and make the engine fully own its executable CUs once we can hold base CUs in most places. Change-Id: I9a53e83d5c4746c2b2bca896b51baa4fe7fee757 Reviewed-by: Fabian Kosmale --- tools/qmljs/qmljs.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tools/qmljs/qmljs.cpp') diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index 2b12c4fc9d..99de7f528c 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) if (runAsModule) { auto module = vm.loadModule(QUrl::fromLocalFile(QFileInfo(fn).absoluteFilePath())); if (module.compiled) { - if (module.compiled->instantiate(&vm)) + if (module.compiled->instantiate()) module.compiled->evaluate(); } else if (module.native) { // Nothing to do. Native modules have no global code. @@ -120,11 +120,12 @@ int main(int argc, char *argv[]) } QScopedPointer script; if (useCache && QFile::exists(fn + QLatin1Char('c'))) { - QQmlRefPointer unit - = QV4::ExecutableCompilationUnit::create(); + auto unit = QQml::makeRefPointer(); QString error; if (unit->loadFromDisk(QUrl::fromLocalFile(fn), QFileInfo(fn).lastModified(), &error)) { - script.reset(new QV4::Script(&vm, nullptr, unit)); + script.reset(new QV4::Script( + &vm, nullptr, QV4::ExecutableCompilationUnit::create( + std::move(unit), &vm))); } else { std::cout << "Error loading" << qPrintable(fn) << "from disk cache:" << qPrintable(error) << std::endl; } @@ -145,7 +146,8 @@ int main(int argc, char *argv[]) const_cast(unit->unitData())->sourceTimeStamp = QFileInfo(fn).lastModified().toMSecsSinceEpoch(); } QString saveError; - if (!unit->saveToDisk(QUrl::fromLocalFile(fn), &saveError)) { + if (!unit->baseCompilationUnit()->saveToDisk( + QUrl::fromLocalFile(fn), &saveError)) { std::cout << "Error saving JS cache file: " << qPrintable(saveError) << std::endl; } } -- cgit v1.2.3