aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qmldom/qqmldomelements.cpp10
-rw-r--r--src/qmldom/qqmldomitem.cpp67
-rw-r--r--tests/auto/qmldom/domitem/tst_qmldomitem.h13
3 files changed, 58 insertions, 32 deletions
diff --git a/src/qmldom/qqmldomelements.cpp b/src/qmldom/qqmldomelements.cpp
index 914c72e34f..0b5d36b4a0 100644
--- a/src/qmldom/qqmldomelements.cpp
+++ b/src/qmldom/qqmldomelements.cpp
@@ -1197,9 +1197,10 @@ void EnumDecl::writeOut(DomItem &self, OutWriter &ow) const
QList<Path> ImportScope::allSources(DomItem &self) const
{
- DomItem env = self.environment();
+ DomItem top = self.top();
+ DomItem env = top.environment();
Path selfPath = self.canonicalPath().field(Fields::allSources);
- RefCacheEntry cached = RefCacheEntry::forPath(env, selfPath);
+ RefCacheEntry cached = (env ? RefCacheEntry::forPath(env, selfPath) : RefCacheEntry());
if (cached.cached == RefCacheEntry::Cached::All)
return cached.canonicalPaths;
QList<Path> res;
@@ -1211,7 +1212,7 @@ QList<Path> ImportScope::allSources(DomItem &self) const
continue;
knownPaths.insert(pNow);
res.append(pNow);
- DomItem sourceBase = env.path(pNow);
+ DomItem sourceBase = top.path(pNow);
for (DomItem autoExp : sourceBase.field(Fields::autoExports).values()) {
if (const ModuleAutoExport *autoExpPtr = autoExp.as<ModuleAutoExport>()) {
Path newSource;
@@ -1241,7 +1242,8 @@ QList<Path> ImportScope::allSources(DomItem &self) const
}
}
}
- RefCacheEntry::addForPath(env, selfPath, RefCacheEntry { RefCacheEntry::Cached::All, res });
+ if (env)
+ RefCacheEntry::addForPath(env, selfPath, RefCacheEntry { RefCacheEntry::Cached::All, res });
return res;
}
diff --git a/src/qmldom/qqmldomitem.cpp b/src/qmldom/qqmldomitem.cpp
index 0a52a11121..49fc3fabda 100644
--- a/src/qmldom/qqmldomitem.cpp
+++ b/src/qmldom/qqmldomitem.cpp
@@ -1927,14 +1927,23 @@ MutableDomItem DomItem::makeCopy(DomItem::CopyOption option)
return MutableDomItem(newItem.path(pathFromOwner()));
}
DomItem env = environment();
- std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>();
- Q_ASSERT(envPtr);
- std::shared_ptr<DomEnvironment> newEnvPtr(
- new DomEnvironment(envPtr, envPtr->loadPaths(), envPtr->options()));
- DomBase *eBase = envPtr.get();
- if (std::holds_alternative<DomEnvironment *>(m_element) && eBase
- && std::get<DomEnvironment *>(m_element) == eBase)
- return MutableDomItem(DomItem(newEnvPtr));
+ std::shared_ptr<DomEnvironment> newEnvPtr;
+ if (std::shared_ptr<DomEnvironment> envPtr = env.ownerAs<DomEnvironment>()) {
+ newEnvPtr = std::shared_ptr<DomEnvironment>(
+ new DomEnvironment(envPtr, envPtr->loadPaths(), envPtr->options()));
+ DomBase *eBase = envPtr.get();
+ if (std::holds_alternative<DomEnvironment *>(m_element) && eBase
+ && std::get<DomEnvironment *>(m_element) == eBase)
+ return MutableDomItem(DomItem(newEnvPtr));
+ } else if (std::shared_ptr<DomUniverse> univPtr = top().ownerAs<DomUniverse>()) {
+ newEnvPtr = std::shared_ptr<DomEnvironment>(new DomEnvironment(
+ QStringList(),
+ DomEnvironment::Option::SingleThreaded | DomEnvironment::Option::NoDependencies,
+ univPtr));
+ } else {
+ Q_ASSERT(false);
+ return {};
+ }
DomItem newItem = std::visit(
[this, newEnvPtr, &o](auto &&el) {
auto copyPtr = el->makeCopy(o);
@@ -2729,26 +2738,28 @@ DomItem Reference::get(DomItem &self, ErrorHandler h, QList<Path> *visitedRefs)
Path cachedPath;
if (shouldCache()) {
env = self.environment();
- selfPath = self.canonicalPath();
- RefCacheEntry cached = RefCacheEntry::forPath(self, selfPath);
- switch (cached.cached) {
- case RefCacheEntry::Cached::None:
- break;
- case RefCacheEntry::Cached::First:
- case RefCacheEntry::Cached::All:
- if (!cached.canonicalPaths.isEmpty())
- cachedPath = cached.canonicalPaths.first();
- else
- return res;
- break;
- }
- if (cachedPath) {
- res = env.path(cachedPath);
- if (!res)
- qCWarning(refLog) << "referenceCache outdated, reference at " << selfPath
- << " leads to invalid path " << cachedPath;
- else
- return res;
+ if (env) {
+ selfPath = self.canonicalPath();
+ RefCacheEntry cached = RefCacheEntry::forPath(self, selfPath);
+ switch (cached.cached) {
+ case RefCacheEntry::Cached::None:
+ break;
+ case RefCacheEntry::Cached::First:
+ case RefCacheEntry::Cached::All:
+ if (!cached.canonicalPaths.isEmpty())
+ cachedPath = cached.canonicalPaths.first();
+ else
+ return res;
+ break;
+ }
+ if (cachedPath) {
+ res = env.path(cachedPath);
+ if (!res)
+ qCWarning(refLog) << "referenceCache outdated, reference at " << selfPath
+ << " leads to invalid path " << cachedPath;
+ else
+ return res;
+ }
}
}
QList<Path> visitedRefsLocal;
diff --git a/tests/auto/qmldom/domitem/tst_qmldomitem.h b/tests/auto/qmldom/domitem/tst_qmldomitem.h
index 8346649aa0..4b98f467ea 100644
--- a/tests/auto/qmldom/domitem/tst_qmldomitem.h
+++ b/tests/auto/qmldom/domitem/tst_qmldomitem.h
@@ -41,6 +41,8 @@
#include <QtQmlDom/private/qqmldomtop_p.h>
#include <QtQmlDom/private/qqmldomastdumper_p.h>
#include <QtQmlDom/private/qqmldommock_p.h>
+#include <QtQmlDom/private/qqmldomcompare_p.h>
+#include <QtQmlDom/private/qqmldomfieldfilter_p.h>
#include <QtTest/QtTest>
#include <QCborValue>
@@ -531,6 +533,17 @@ private slots:
if (!diff.isEmpty())
qDebug().nospace().noquote() << diff;
QCOMPARE(dump1, dump2);
+ QStringList diffs = domCompareStrList(f, copy, FieldFilter::compareFilter());
+ if (!diffs.isEmpty())
+ qDebug() << "testDeepCopy.diffs:" << diffs;
+ QVERIFY(diffs.isEmpty());
+ DomItem univFile = env.universe().path(f.canonicalPath());
+ MutableDomItem univFileCopy = univFile.makeCopy();
+ QStringList univFileDiffs =
+ domCompareStrList(univFile, univFileCopy, FieldFilter::compareFilter());
+ if (!univFileDiffs.isEmpty())
+ qDebug() << "testDeepCopy.univFileDiffs:" << univFileDiffs;
+ QVERIFY(univFileDiffs.isEmpty());
}
private: