Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4resolvedtypereference.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
6
7#include <QtQml/private/qqmlengine_p.h>
8#include <QtQml/qqmlpropertymap.h>
9#include <QtCore/qcryptographichash.h>
10
12
13namespace QV4 {
14
15template <typename T>
16bool qtTypeInherits(const QMetaObject *mo) {
17 while (mo) {
18 if (mo == &T::staticMetaObject)
19 return true;
20 mo = mo->superClass();
21 }
22 return false;
23}
24
26{
27 const QMetaObject *mo = nullptr;
28 if (m_typePropertyCache)
29 mo = m_typePropertyCache->firstCppMetaObject();
30 else if (m_type.isValid())
31 mo = m_type.metaObject();
32 m_isFullyDynamicType = qtTypeInherits<QQmlPropertyMap>(mo);
33}
34
35/*!
36Returns the property cache, creating one if it doesn't already exist. The cache is not referenced.
37*/
39{
40 if (!m_typePropertyCache && m_type.isValid()) {
41 const QMetaObject *metaObject = m_type.metaObject();
42 if (!metaObject) // value type of non-Q_GADGET base with extension
43 metaObject = m_type.extensionMetaObject();
44 if (metaObject)
45 m_typePropertyCache = QQmlMetaType::propertyCache(metaObject, m_version);
46 }
47
48 return m_typePropertyCache;
49}
50
52 QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums)
53{
54 // No need to add types from the same document to the hash.
55 if (m_isSelfReference)
56 return true;
57
58 if (m_compilationUnit) {
59 hash->addData({m_compilationUnit->unitData()->md5Checksum,
60 sizeof(m_compilationUnit->unitData()->md5Checksum)});
61 return true;
62 }
63
64 if (QQmlPropertyCache::ConstPtr propertyCache = createPropertyCache()) {
65 bool ok = false;
66 hash->addData(propertyCache->checksum(checksums, &ok));
67 return ok;
68 }
69
70 return false;
71}
72
73} // namespace QV4
74
75QT_END_NAMESPACE
bool addToHash(QCryptographicHash *hash, QHash< quintptr, QByteArray > *checksums)
QQmlPropertyCache::ConstPtr createPropertyCache()
Returns the property cache, creating one if it doesn't already exist.
Definition qjsvalue.h:23
bool qtTypeInherits(const QMetaObject *mo)