diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-03-08 18:35:03 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2018-03-08 18:35:03 +0100 |
commit | d9ea4917ca97aeee050a86151fbfa069771b498d (patch) | |
tree | 21fd6960d8a866bf6f5a5a8f9db9be801f8065c1 /src/qml/qml | |
parent | f9beafddd256cd0b79bf2478a812053ef61241fc (diff) | |
parent | c6a26c248e8abc421b87c3dd6b2466d490ea902e (diff) |
Merge remote-tracking branch 'gerrit/5.11' into wip/webassembly
Change-Id: I729af792166fd2f6c5843ba564e63adf8ae09a97
Diffstat (limited to 'src/qml/qml')
106 files changed, 2288 insertions, 2048 deletions
diff --git a/src/qml/qml/ftw/qbitfield_p.h b/src/qml/qml/ftw/qbitfield_p.h index 8f35842249..92017580d6 100644 --- a/src/qml/qml/ftw/qbitfield_p.h +++ b/src/qml/qml/ftw/qbitfield_p.h @@ -77,12 +77,12 @@ private: }; QBitField::QBitField() -: bits(0), ownData(0), data(0) +: bits(0), ownData(nullptr), data(nullptr) { } QBitField::QBitField(const quint32 *bitData, int bitCount) -: bits((quint32)bitCount), ownData(0), data(bitData) +: bits((quint32)bitCount), ownData(nullptr), data(bitData) { } diff --git a/src/qml/qml/ftw/qfieldlist_p.h b/src/qml/qml/ftw/qfieldlist_p.h index d83d708b5e..2bf07fb20d 100644 --- a/src/qml/qml/ftw/qfieldlist_p.h +++ b/src/qml/qml/ftw/qfieldlist_p.h @@ -141,7 +141,7 @@ N *QForwardFieldList<N, nextMember>::takeFirst() N *value = *_first; if (value) { _first = next(value); - value->*nextMember = 0; + value->*nextMember = nullptr; } return value; } @@ -149,7 +149,7 @@ N *QForwardFieldList<N, nextMember>::takeFirst() template<class N, N *N::*nextMember> void QForwardFieldList<N, nextMember>::prepend(N *v) { - Q_ASSERT(v->*nextMember == 0); + Q_ASSERT(v->*nextMember == nullptr); v->*nextMember = *_first; _first = v; } @@ -229,7 +229,7 @@ void QForwardFieldList<N, nextMember>::setFlag2Value(bool v) template<class N, N *N::*nextMember> QFieldList<N, nextMember>::QFieldList() -: _first(0), _last(0), _flag(0), _count(0) +: _first(nullptr), _last(nullptr), _flag(0), _count(0) { } @@ -246,10 +246,10 @@ N *QFieldList<N, nextMember>::takeFirst() if (value) { _first = next(value); if (_last == value) { - Q_ASSERT(_first == 0); - _last = 0; + Q_ASSERT(_first == nullptr); + _last = nullptr; } - value->*nextMember = 0; + value->*nextMember = nullptr; --_count; } return value; @@ -258,7 +258,7 @@ N *QFieldList<N, nextMember>::takeFirst() template<class N, N *N::*nextMember> void QFieldList<N, nextMember>::append(N *v) { - Q_ASSERT(v->*nextMember == 0); + Q_ASSERT(v->*nextMember == nullptr); if (isEmpty()) { _first = v; _last = v; @@ -272,7 +272,7 @@ void QFieldList<N, nextMember>::append(N *v) template<class N, N *N::*nextMember> void QFieldList<N, nextMember>::prepend(N *v) { - Q_ASSERT(v->*nextMember == 0); + Q_ASSERT(v->*nextMember == nullptr); if (isEmpty()) { _first = v; _last = v; @@ -375,7 +375,7 @@ void QFieldList<N, nextMember>::copyAndClear(QFieldList<N, nextMember> &o) _first = o._first; _last = o._last; _count = o._count; - o._first = o._last = 0; + o._first = o._last = nullptr; o._count = 0; } @@ -391,8 +391,8 @@ void QFieldList<N, nextMember>::copyAndClearAppend(QForwardFieldList<N, nextMemb template<class N, N *N::*nextMember> void QFieldList<N, nextMember>::copyAndClearPrepend(QForwardFieldList<N, nextMember> &o) { - _first = 0; - _last = 0; + _first = nullptr; + _last = nullptr; _count = 0; while (N *n = o.takeFirst()) prepend(n); } diff --git a/src/qml/qml/ftw/qfinitestack_p.h b/src/qml/qml/ftw/qfinitestack_p.h index f1f1a551d5..9a74199137 100644 --- a/src/qml/qml/ftw/qfinitestack_p.h +++ b/src/qml/qml/ftw/qfinitestack_p.h @@ -81,7 +81,7 @@ private: template<typename T> QFiniteStack<T>::QFiniteStack() -: _array(0), _alloc(0), _size(0) +: _array(nullptr), _alloc(0), _size(0) { } @@ -156,7 +156,7 @@ T &QFiniteStack<T>::operator[](int index) template<typename T> void QFiniteStack<T>::allocate(int size) { - Q_ASSERT(_array == 0); + Q_ASSERT(_array == nullptr); Q_ASSERT(_alloc == 0); Q_ASSERT(_size == 0); @@ -177,7 +177,7 @@ void QFiniteStack<T>::deallocate() free(_array); - _array = 0; + _array = nullptr; _alloc = 0; _size = 0; } diff --git a/src/qml/qml/ftw/qflagpointer_p.h b/src/qml/qml/ftw/qflagpointer_p.h index 6954a8f09c..91ce74bec9 100644 --- a/src/qml/qml/ftw/qflagpointer_p.h +++ b/src/qml/qml/ftw/qflagpointer_p.h @@ -83,7 +83,7 @@ public: inline T *data() const; private: - quintptr ptr_value; + quintptr ptr_value = 0; static const quintptr FlagBit = 0x1; static const quintptr Flag2Bit = 0x2; @@ -115,7 +115,7 @@ public: inline T2 *asT2() const; private: - quintptr ptr_value; + quintptr ptr_value = 0; static const quintptr FlagBit = 0x1; static const quintptr Flag2Bit = 0x2; @@ -124,7 +124,6 @@ private: template<typename T> QFlagPointer<T>::QFlagPointer() -: ptr_value(0) { } @@ -233,7 +232,6 @@ T *QFlagPointer<T>::data() const template<typename T, typename T2> QBiPointer<T, T2>::QBiPointer() -: ptr_value(0) { } diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 956805d696..2d6c25bdd3 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -94,7 +94,7 @@ private: friend class QStringHashNode; inline void computeHash() const; - mutable quint32 m_hash; + mutable quint32 m_hash = 0; }; class QHashedCStringRef; @@ -142,9 +142,9 @@ private: inline void computeHash() const; - const QChar *m_data; - int m_length; - mutable quint32 m_hash; + const QChar *m_data = nullptr; + int m_length = 0; + mutable quint32 m_hash = 0; }; class Q_AUTOTEST_EXPORT QHashedCStringRef @@ -169,9 +169,9 @@ private: inline void computeHash() const; - const char *m_data; - int m_length; - mutable quint32 m_hash; + const char *m_data = nullptr; + int m_length = 0; + mutable quint32 m_hash = 0; }; class QStringHashData; @@ -179,7 +179,7 @@ class Q_AUTOTEST_EXPORT QStringHashNode { public: QStringHashNode() - : length(0), hash(0), symbolId(0), ckey(0) + : ckey(nullptr) { } @@ -210,9 +210,9 @@ public: QFlagPointer<QStringHashNode> next; - qint32 length; - quint32 hash; - quint32 symbolId; + qint32 length = 0; + quint32 hash = 0; + quint32 symbolId = 0; union { const char *ckey; @@ -276,25 +276,20 @@ public: class Q_AUTOTEST_EXPORT QStringHashData { public: - QStringHashData() - : buckets(0), numBuckets(0), size(0), numBits(0) -#ifdef QSTRINGHASH_LINK_DEBUG - , linkCount(0) -#endif - {} + QStringHashData() {} - QStringHashNode **buckets; - int numBuckets; - int size; - short numBits; + QStringHashNode **buckets = nullptr; + int numBuckets = 0; + int size = 0; + short numBits = 0; #ifdef QSTRINGHASH_LINK_DEBUG - int linkCount; + int linkCount = 0; #endif struct IteratorData { - IteratorData() : n(0), p(0) {} - QStringHashNode *n; - void *p; + IteratorData() {} + QStringHashNode *n = nullptr; + void *p = nullptr; }; void rehashToBits(short); void rehashToSize(int); @@ -362,17 +357,17 @@ public: T value; }; struct NewedNode : public Node { - NewedNode(const QHashedString &key, const T &value) : Node(key, value), nextNewed(0) {} - NewedNode(const QHashedCStringRef &key, const T &value) : Node(key, value), nextNewed(0) {} - NewedNode(const Node &o) : Node(o), nextNewed(0) {} + NewedNode(const QHashedString &key, const T &value) : Node(key, value), nextNewed(nullptr) {} + NewedNode(const QHashedCStringRef &key, const T &value) : Node(key, value), nextNewed(nullptr) {} + NewedNode(const Node &o) : Node(o), nextNewed(nullptr) {} NewedNode *nextNewed; }; struct ReservedNodePool { - ReservedNodePool() : count(0), used(0), nodes(0) {} + ReservedNodePool() : nodes(nullptr) {} ~ReservedNodePool() { delete [] nodes; } - int count; - int used; + int count = 0; + int used = 0; Node *nodes; }; @@ -475,13 +470,13 @@ public: template<class T> QStringHash<T>::QStringHash() -: newedNodes(0), nodePool(0), link(0) +: newedNodes(nullptr), nodePool(nullptr), link(nullptr) { } template<class T> QStringHash<T>::QStringHash(const QStringHash<T> &other) -: newedNodes(0), nodePool(0), link(0) +: newedNodes(nullptr), nodePool(nullptr), link(nullptr) { data.numBits = other.data.numBits; data.size = other.data.size; @@ -579,14 +574,14 @@ void QStringHash<T>::clear() if (nodePool) delete nodePool; delete [] data.buckets; - data.buckets = 0; + data.buckets = nullptr; data.numBuckets = 0; data.numBits = 0; data.size = 0; - newedNodes = 0; - nodePool = 0; - link = 0; + newedNodes = nullptr; + nodePool = nullptr; + link = nullptr; } template<class T> @@ -716,16 +711,16 @@ QStringHash<T>::iterateNext(const QStringHashData::IteratorData &d) node < (This->nodePool->nodes + This->nodePool->used)) { node--; if (node < This->nodePool->nodes) - node = 0; + node = nullptr; } else { NewedNode *nn = (NewedNode *)node; node = nn->nextNewed; - if (node == 0 && This->nodePool && This->nodePool->used) + if (node == nullptr && This->nodePool && This->nodePool->used) node = This->nodePool->nodes + This->nodePool->used - 1; } - if (node == 0 && This->link) + if (node == nullptr && This->link) return This->link->iterateFirst(); QStringHashData::IteratorData rv; @@ -737,13 +732,13 @@ QStringHash<T>::iterateNext(const QStringHashData::IteratorData &d) template<class T> QStringHashData::IteratorData QStringHash<T>::iterateFirst() const { - Node *n = 0; + Node *n = nullptr; if (newedNodes) n = newedNodes; else if (nodePool && nodePool->used) n = nodePool->nodes + nodePool->used - 1; - if (n == 0 && link) + if (n == nullptr && link) return link->iterateFirst(); QStringHashData::IteratorData rv; @@ -822,7 +817,7 @@ void QStringHash<T>::insert(const K &key, const T &value) { // If this is a linked hash, we can't rely on owning the node, so we always // create a new one. - Node *n = link?0:findNode(key); + Node *n = link?nullptr:findNode(key); if (n) n->value = value; else createNode(key, value); } @@ -837,7 +832,7 @@ template<class T> template<class K> typename QStringHash<T>::Node *QStringHash<T>::findNode(const K &key) const { - QStringHashNode *node = data.numBuckets?data.buckets[hashOf(key) % data.numBuckets]:0; + QStringHashNode *node = data.numBuckets?data.buckets[hashOf(key) % data.numBuckets]:nullptr; typename HashedForm<K>::Type hashedKey(hashedString(key)); while (node && !node->equals(hashedKey)) @@ -851,7 +846,7 @@ template<class K> T *QStringHash<T>::value(const K &key) const { Node *n = findNode(key); - return n?&n->value:0; + return n?&n->value:nullptr; } template<class T> @@ -865,14 +860,14 @@ template<class T> T *QStringHash<T>::value(const QV4::String *string) const { Node *n = findNode(string); - return n?&n->value:0; + return n?&n->value:nullptr; } template<class T> template<class K> bool QStringHash<T>::contains(const K &key) const { - return 0 != value(key); + return nullptr != value(key); } template<class T> @@ -1038,7 +1033,7 @@ inline uint qHash(const QHashedStringRef &string) } QHashedString::QHashedString() -: QString(), m_hash(0) +: QString() { } @@ -1089,7 +1084,6 @@ quint32 QHashedString::existingHash() const } QHashedStringRef::QHashedStringRef() -: m_data(0), m_length(0), m_hash(0) { } @@ -1236,7 +1230,6 @@ quint32 QHashedStringRef::hash() const } QHashedCStringRef::QHashedCStringRef() -: m_data(0), m_length(0), m_hash(0) { } diff --git a/src/qml/qml/ftw/qintrusivelist_p.h b/src/qml/qml/ftw/qintrusivelist_p.h index 3d749e697e..8992be9f93 100644 --- a/src/qml/qml/ftw/qintrusivelist_p.h +++ b/src/qml/qml/ftw/qintrusivelist_p.h @@ -95,7 +95,7 @@ public: private: static inline N *nodeToN(QIntrusiveListNode *node); - QIntrusiveListNode *__first; + QIntrusiveListNode *__first = nullptr; }; class QIntrusiveListNode @@ -107,13 +107,13 @@ public: inline void remove(); inline bool isInList() const; - QIntrusiveListNode *_next; - QIntrusiveListNode**_prev; + QIntrusiveListNode *_next = nullptr; + QIntrusiveListNode**_prev = nullptr; }; template<class N, QIntrusiveListNode N::*member> QIntrusiveList<N, member>::iterator::iterator() -: _value(0) +: _value(nullptr) { } @@ -165,7 +165,7 @@ typename QIntrusiveList<N, member>::iterator &QIntrusiveList<N, member>::iterato template<class N, QIntrusiveListNode N::*member> QIntrusiveList<N, member>::QIntrusiveList() -: __first(0) + { } @@ -178,7 +178,7 @@ QIntrusiveList<N, member>::~QIntrusiveList() template<class N, QIntrusiveListNode N::*member> bool QIntrusiveList<N, member>::isEmpty() const { - return __first == 0; + return __first == nullptr; } template<class N, QIntrusiveListNode N::*member> @@ -215,14 +215,14 @@ bool QIntrusiveList<N, member>::contains(N *n) const template<class N, QIntrusiveListNode N::*member> N *QIntrusiveList<N, member>::first() const { - return __first?nodeToN(__first):0; + return __first?nodeToN(__first):nullptr; } template<class N, QIntrusiveListNode N::*member> N *QIntrusiveList<N, member>::next(N *current) { QIntrusiveListNode *nextnode = (current->*member)._next; - N *nextstruct = nextnode?nodeToN(nextnode):0; + N *nextstruct = nextnode?nodeToN(nextnode):nullptr; return nextstruct; } @@ -241,11 +241,10 @@ typename QIntrusiveList<N, member>::iterator QIntrusiveList<N, member>::end() template<class N, QIntrusiveListNode N::*member> N *QIntrusiveList<N, member>::nodeToN(QIntrusiveListNode *node) { - return (N *)((char *)node - ((char *)&(((N *)0)->*member) - (char *)0)); + return (N *)((char *)node - ((char *)&(((N *)nullptr)->*member) - (char *)nullptr)); } QIntrusiveListNode::QIntrusiveListNode() -: _next(0), _prev(0) { } @@ -258,13 +257,13 @@ void QIntrusiveListNode::remove() { if (_prev) *_prev = _next; if (_next) _next->_prev = _prev; - _prev = 0; - _next = 0; + _prev = nullptr; + _next = nullptr; } bool QIntrusiveListNode::isInList() const { - return _prev != 0; + return _prev != nullptr; } QT_END_NAMESPACE diff --git a/src/qml/qml/ftw/qpodvector_p.h b/src/qml/qml/ftw/qpodvector_p.h index cafe3367de..b2fb481793 100644 --- a/src/qml/qml/ftw/qpodvector_p.h +++ b/src/qml/qml/ftw/qpodvector_p.h @@ -61,7 +61,7 @@ class QPODVector { public: QPODVector() - : m_count(0), m_capacity(0), m_data(0) {} + : m_count(0), m_capacity(0), m_data(nullptr) {} ~QPODVector() { if (m_data) ::free(m_data); } const T &at(int idx) const { @@ -87,11 +87,11 @@ public: void insert(int idx, const T &v) { if (m_count == m_capacity) { m_capacity += Increment; - m_data = (T *)realloc(m_data, m_capacity * sizeof(T)); + m_data = (T *)realloc(static_cast<void *>(m_data), m_capacity * sizeof(T)); } int moveCount = m_count - idx; if (moveCount) - ::memmove(m_data + idx + 1, m_data + idx, moveCount * sizeof(T)); + ::memmove(static_cast<void *>(m_data + idx + 1), static_cast<const void *>(m_data + idx), moveCount * sizeof(T)); m_count++; m_data[idx] = v; } @@ -99,7 +99,7 @@ public: void reserve(int count) { if (count >= m_capacity) { m_capacity = (count + (Increment-1)) & (0xFFFFFFFF - Increment + 1); - m_data = (T *)realloc(m_data, m_capacity * sizeof(T)); + m_data = (T *)realloc(static_cast<void *>(m_data), m_capacity * sizeof(T)); } } @@ -108,7 +108,7 @@ public: reserve(newSize); int moveCount = m_count - idx; if (moveCount) - ::memmove(m_data + idx + count, m_data + idx, + ::memmove(static_cast<void *>(m_data + idx + count), static_cast<const void *>(m_data + idx), moveCount * sizeof(T)); m_count = newSize; } @@ -116,7 +116,7 @@ public: void remove(int idx, int count = 1) { int moveCount = m_count - (idx + count); if (moveCount) - ::memmove(m_data + idx, m_data + idx + count, + ::memmove(static_cast<void *>(m_data + idx), static_cast<const void *>(m_data + idx + count), moveCount * sizeof(T)); m_count -= count; } @@ -154,7 +154,7 @@ public: other.m_data = m_data; m_count = 0; m_capacity = 0; - m_data = 0; + m_data = nullptr; } QPODVector<T,Increment> &operator<<(const T &v) { append(v); return *this; } diff --git a/src/qml/qml/ftw/qqmlnullablevalue_p.h b/src/qml/qml/ftw/qqmlnullablevalue_p.h index 7a9e4d7b8a..5b3d2fc456 100644 --- a/src/qml/qml/ftw/qqmlnullablevalue_p.h +++ b/src/qml/qml/ftw/qqmlnullablevalue_p.h @@ -57,7 +57,7 @@ template<typename T> struct QQmlNullableValue { QQmlNullableValue() - : isNull(true), value(T()) {} + : value(T()) {} QQmlNullableValue(const QQmlNullableValue<T> &o) : isNull(o.isNull), value(o.value) {} QQmlNullableValue(const T &t) @@ -70,7 +70,7 @@ struct QQmlNullableValue void invalidate() { isNull = true; } bool isValid() const { return !isNull; } - bool isNull; + bool isNull = true; T value; }; diff --git a/src/qml/qml/ftw/qqmlrefcount_p.h b/src/qml/qml/ftw/qqmlrefcount_p.h index 225e18156c..3cfb345b30 100644 --- a/src/qml/qml/ftw/qqmlrefcount_p.h +++ b/src/qml/qml/ftw/qqmlrefcount_p.h @@ -137,7 +137,7 @@ void QQmlRefCount::destroy() template<class T> QQmlRefPointer<T>::QQmlRefPointer() -: o(0) +: o(nullptr) { } diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp index bf62d7a99a..322d3281c7 100644 --- a/src/qml/qml/ftw/qqmlthread.cpp +++ b/src/qml/qml/ftw/qqmlthread.cpp @@ -129,7 +129,7 @@ bool QQmlThreadPrivate::MainObject::event(QEvent *e) QQmlThreadPrivate::QQmlThreadPrivate(QQmlThread *q) : q(q), m_threadProcessing(false), m_mainProcessing(false), m_shutdown(false), - m_mainThreadWaiting(false), mainSync(0), m_mainObject(this) + m_mainThreadWaiting(false), mainSync(nullptr), m_mainObject(this) { setObjectName(QStringLiteral("QQmlThread")); } @@ -161,7 +161,7 @@ void QQmlThreadPrivate::mainEvent() m_mainProcessing = true; while (!mainList.isEmpty() || mainSync) { - bool isSync = mainSync != 0; + bool isSync = mainSync != nullptr; QQmlThread::Message *message = isSync?mainSync:mainList.takeFirst(); unlock(); @@ -171,7 +171,7 @@ void QQmlThreadPrivate::mainEvent() lock(); if (isSync) { - mainSync = 0; + mainSync = nullptr; wakeOne(); } } @@ -339,7 +339,7 @@ void QQmlThread::internalCallMethodInThread(Message *message) message->call(this); delete message; lock(); - d->mainSync = 0; + d->mainSync = nullptr; wakeOne(); } else { d->wait(); @@ -356,7 +356,7 @@ void QQmlThread::internalCallMethodInMain(Message *message) d->lock(); - Q_ASSERT(d->mainSync == 0); + Q_ASSERT(d->mainSync == nullptr); d->mainSync = message; if (d->m_mainThreadWaiting) { @@ -370,7 +370,7 @@ void QQmlThread::internalCallMethodInMain(Message *message) while (d->mainSync) { if (d->m_shutdown) { delete d->mainSync; - d->mainSync = 0; + d->mainSync = nullptr; break; } d->wait(); @@ -418,7 +418,7 @@ void QQmlThread::waitForNextMessage() message->call(this); delete message; lock(); - d->mainSync = 0; + d->mainSync = nullptr; wakeOne(); } else { d->wait(); diff --git a/src/qml/qml/ftw/qqmlthread_p.h b/src/qml/qml/ftw/qqmlthread_p.h index 295235e255..0ed12a2972 100644 --- a/src/qml/qml/ftw/qqmlthread_p.h +++ b/src/qml/qml/ftw/qqmlthread_p.h @@ -124,7 +124,7 @@ private: friend class QQmlThreadPrivate; struct Message { - Message() : next(0) {} + Message() : next(nullptr) {} virtual ~Message() {} Message *next; virtual void call(QQmlThread *) = 0; diff --git a/src/qml/qml/ftw/qrecursionwatcher_p.h b/src/qml/qml/ftw/qrecursionwatcher_p.h index 99228b9583..56b714f922 100644 --- a/src/qml/qml/ftw/qrecursionwatcher_p.h +++ b/src/qml/qml/ftw/qrecursionwatcher_p.h @@ -74,7 +74,7 @@ private: }; QRecursionNode::QRecursionNode() -: _r(0) +: _r(nullptr) { } @@ -89,7 +89,7 @@ QRecursionWatcher<T, Node>::QRecursionWatcher(T *t) template<class T, QRecursionNode T::*Node> QRecursionWatcher<T, Node>::~QRecursionWatcher() { - if ((_t->*Node)._r == &_r) (_t->*Node)._r = 0; + if ((_t->*Node)._r == &_r) (_t->*Node)._r = nullptr; } template<class T, QRecursionNode T::*Node> diff --git a/src/qml/qml/ftw/qrecyclepool_p.h b/src/qml/qml/ftw/qrecyclepool_p.h index 42a2f13729..39f4f88512 100644 --- a/src/qml/qml/ftw/qrecyclepool_p.h +++ b/src/qml/qml/ftw/qrecyclepool_p.h @@ -61,7 +61,7 @@ class QRecyclePoolPrivate public: QRecyclePoolPrivate() : recyclePoolHold(true), outstandingItems(0), cookie(QRECYCLEPOOLCOOKIE), - currentPage(0), nextAllocated(0) + currentPage(nullptr), nextAllocated(nullptr) { } @@ -178,7 +178,7 @@ void QRecyclePoolPrivate<T, Step>::releaseIfPossible() template<typename T, int Step> T *QRecyclePoolPrivate<T, Step>::allocate() { - PoolType *rv = 0; + PoolType *rv = nullptr; if (nextAllocated) { rv = nextAllocated; nextAllocated = rv->nextAllocated; diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h index 219df264be..213f23cd98 100644 --- a/src/qml/qml/qqml.h +++ b/src/qml/qml/qqml.h @@ -354,7 +354,7 @@ int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor) sizeof(T), QQmlPrivate::createInto<T>, QString(), - uri, versionMajor, versionMinor, 0, &T::staticMetaObject, + uri, versionMajor, versionMinor, nullptr, &T::staticMetaObject, QQmlPrivate::attachedPropertiesFunc<T>(), QQmlPrivate::attachedPropertiesMetaObject<T>(), diff --git a/src/qml/qml/qqmlabstractbinding.cpp b/src/qml/qml/qqmlabstractbinding.cpp index b1c320afd4..42891c1a8e 100644 --- a/src/qml/qml/qqmlabstractbinding.cpp +++ b/src/qml/qml/qqmlabstractbinding.cpp @@ -83,7 +83,7 @@ void QQmlAbstractBinding::addToObject() // Value type // Find the value type proxy (if there is one) - QQmlValueTypeProxyBinding *proxy = 0; + QQmlValueTypeProxyBinding *proxy = nullptr; if (data->hasBindingBit(coreIndex)) { QQmlAbstractBinding *b = data->bindings; while (b && (b->targetPropertyIndex().coreIndex() != coreIndex || @@ -137,7 +137,7 @@ void QQmlAbstractBinding::removeFromObject() QQmlAbstractBinding::Ptr next; next = nextBinding(); - setNextBinding(0); + setNextBinding(nullptr); int coreIndex = targetPropertyIndex().coreIndex(); if (targetPropertyIndex().hasValueTypeIndex()) { diff --git a/src/qml/qml/qqmlabstractbinding_p.h b/src/qml/qml/qqmlabstractbinding_p.h index bea2d253e4..fc53be3e7b 100644 --- a/src/qml/qml/qqmlabstractbinding_p.h +++ b/src/qml/qml/qqmlabstractbinding_p.h @@ -95,8 +95,8 @@ public: { return m_nextBinding.flag2(); } struct RefCount { - RefCount() : refCount(0) {} - int refCount; + RefCount() {} + int refCount = 0; void ref() { ++refCount; } int deref() { return --refCount; } operator int() const { return refCount; } diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp index faab8bf926..a0517e4558 100644 --- a/src/qml/qml/qqmlapplicationengine.cpp +++ b/src/qml/qml/qqmlapplicationengine.cpp @@ -128,7 +128,7 @@ void QQmlApplicationEnginePrivate::finishLoad(QQmlComponent *c) case QQmlComponent::Error: qWarning() << "QQmlApplicationEngine failed to load component"; qWarning() << qPrintable(c->errorString()); - q->objectCreated(0, c->url()); + q->objectCreated(nullptr, c->url()); break; case QQmlComponent::Ready: { auto newObj = c->create(); diff --git a/src/qml/qml/qqmlapplicationengine.h b/src/qml/qml/qqmlapplicationengine.h index d0f9e6d319..bb5d6b5d68 100644 --- a/src/qml/qml/qqmlapplicationengine.h +++ b/src/qml/qml/qqmlapplicationengine.h @@ -56,7 +56,7 @@ public: QQmlApplicationEngine(QObject *parent = nullptr); QQmlApplicationEngine(const QUrl &url, QObject *parent = nullptr); QQmlApplicationEngine(const QString &filePath, QObject *parent = nullptr); - ~QQmlApplicationEngine(); + ~QQmlApplicationEngine() override; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QList<QObject*> rootObjects(); // ### Qt 6: remove diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index 56ab259229..ca3bff43a4 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -70,7 +70,7 @@ QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, const QQmlScr return b; QString url; - QV4::Function *runtimeFunction = 0; + QV4::Function *runtimeFunction = nullptr; QQmlContextData *ctxtdata = QQmlContextData::get(scriptPrivate->context); QQmlEnginePrivate *engine = QQmlEnginePrivate::get(scriptPrivate->context->engine()); @@ -84,7 +84,7 @@ QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, const QQmlScr b->QQmlJavaScriptExpression::setContext(QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context)); b->setScopeObject(obj ? obj : scriptPrivate->scope); - QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(b->context()->engine)->v4engine(); + QV4::ExecutionEngine *v4 = b->context()->engine->handle(); if (runtimeFunction) { QV4::Scope scope(v4); QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxtdata, b->scopeObject())); @@ -150,7 +150,7 @@ void QQmlBinding::update(QQmlPropertyData::WriteFlags flags) QQmlPropertyData vtd; getPropertyData(&d, &vtd); Q_ASSERT(d); - QQmlProperty p = QQmlPropertyPrivate::restore(targetObject(), *d, &vtd, 0); + QQmlProperty p = QQmlPropertyPrivate::restore(targetObject(), *d, &vtd, nullptr); QQmlAbstractBinding::printBindingLoopError(p); return; } @@ -158,13 +158,13 @@ void QQmlBinding::update(QQmlPropertyData::WriteFlags flags) DeleteWatcher watcher(this); - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context()->engine); - QV4::Scope scope(ep->v4engine()); + QQmlEngine *engine = context()->engine; + QV4::Scope scope(engine->handle()); if (canUseAccessor()) flags.setFlag(QQmlPropertyData::BypassInterceptor); - QQmlBindingProfiler prof(ep->profiler, function()); + QQmlBindingProfiler prof(QQmlEnginePrivate::get(engine)->profiler, function()); doUpdate(watcher, flags, scope); if (!watcher.wasDeleted()) @@ -306,7 +306,7 @@ public: } void doUpdate(const DeleteWatcher &watcher, - QQmlPropertyData::WriteFlags flags, QV4::Scope &) override final + QQmlPropertyData::WriteFlags flags, QV4::Scope &scope) override final { if (watcher.wasDeleted()) return; @@ -322,7 +322,12 @@ public: QQmlPropertyData vpd; getPropertyData(&pd, &vpd); Q_ASSERT(pd); - doStore(result, pd, flags); + if (pd->propType() == QMetaType::QString) { + doStore(result, pd, flags); + } else { + QV4::ScopedString value(scope, scope.engine->newString(result)); + slowWrite(*pd, vpd, value, /*isUndefined*/false, flags); + } } private: @@ -346,7 +351,7 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, bool isUndefined, QQmlPropertyData::WriteFlags flags) { QQmlEngine *engine = context()->engine; - QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); + QV4::ExecutionEngine *v4engine = engine->handle(); int type = valueTypeData.isValid() ? valueTypeData.propType() : core.propType(); @@ -357,13 +362,13 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, if (isUndefined) { } else if (core.isQList()) { - value = QV8Engine::getV4(v8engine)->toVariant(result, qMetaTypeId<QList<QObject *> >()); + value = v4engine->toVariant(result, qMetaTypeId<QList<QObject *> >()); } else if (result.isNull() && core.isQObject()) { - value = QVariant::fromValue((QObject *)0); + value = QVariant::fromValue((QObject *)nullptr); } else if (core.propType() == qMetaTypeId<QList<QUrl> >()) { - value = QQmlPropertyPrivate::resolvedUrlSequence(QV8Engine::getV4(v8engine)->toVariant(result, qMetaTypeId<QList<QUrl> >()), context()); + value = QQmlPropertyPrivate::resolvedUrlSequence(v4engine->toVariant(result, qMetaTypeId<QList<QUrl> >()), context()); } else if (!isVarProperty && type != qMetaTypeId<QJSValue>()) { - value = QV8Engine::getV4(v8engine)->toVariant(result, type); + value = v4engine->toVariant(result, type); } if (hasError()) { @@ -381,7 +386,7 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, Q_ASSERT(vmemo); vmemo->setVMEProperty(core.coreIndex(), result); } else if (isUndefined && core.isResettable()) { - void *args[] = { 0 }; + void *args[] = { nullptr }; QMetaObject::metacall(m_target.data(), QMetaObject::ResetProperty, core.coreIndex(), args); } else if (isUndefined && type == qMetaTypeId<QVariant>()) { QQmlPropertyPrivate::writeValueProperty(m_target.data(), core, valueTypeData, QVariant(), context(), flags); @@ -392,7 +397,7 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, return false; } QQmlPropertyPrivate::writeValueProperty(m_target.data(), core, valueTypeData, QVariant::fromValue( - QJSValue(QV8Engine::getV4(v8engine), result.asReturnedValue())), + QJSValue(v4engine, result.asReturnedValue())), context(), flags); } else if (isUndefined) { const QLatin1String typeName(QMetaType::typeName(type) @@ -412,8 +417,8 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, if (watcher.wasDeleted()) return true; - const char *valueType = 0; - const char *propertyType = 0; + const char *valueType = nullptr; + const char *propertyType = nullptr; const int userType = value.userType(); if (userType == QMetaType::QObjectStar) { @@ -450,12 +455,13 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, QVariant QQmlBinding::evaluate() { - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context()->engine); + QQmlEngine *engine = context()->engine; + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); ep->referenceScarceResources(); bool isUndefined = false; - QV4::Scope scope(ep->v4engine()); + QV4::Scope scope(engine->handle()); QV4::ScopedValue result(scope, QQmlJavaScriptExpression::evaluate(&isUndefined)); ep->dereferenceScarceResources(); @@ -524,7 +530,7 @@ void QQmlBinding::setTarget(QObject *object, const QQmlPropertyData &core, const int aValueTypeIndex; if (!vme->aliasTarget(coreIndex, &object, &coreIndex, &aValueTypeIndex)) { - m_target = 0; + m_target = nullptr; m_targetIndex = QQmlPropertyIndex(); return; } @@ -533,7 +539,7 @@ void QQmlBinding::setTarget(QObject *object, const QQmlPropertyData &core, const QQmlData *data = QQmlData::get(object, false); if (!data || !data->propertyCache) { - m_target = 0; + m_target = nullptr; m_targetIndex = QQmlPropertyIndex(); return; } diff --git a/src/qml/qml/qqmlbinding_p.h b/src/qml/qml/qqmlbinding_p.h index 8bc9554a42..19ec3f5d4f 100644 --- a/src/qml/qml/qqmlbinding_p.h +++ b/src/qml/qml/qqmlbinding_p.h @@ -79,7 +79,7 @@ public: QObject *obj, QQmlContextData *ctxt, QV4::ExecutionContext *scope); static QQmlBinding *createTranslationBinding(QV4::CompiledData::CompilationUnit *unit, const QV4::CompiledData::Binding *binding, QObject *obj, QQmlContextData *ctxt); - ~QQmlBinding(); + ~QQmlBinding() override; void setTarget(const QQmlProperty &); void setTarget(QObject *, const QQmlPropertyData &, const QQmlPropertyData *valueType); diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 1d7a37fc99..060706ac50 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -74,8 +74,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, { init(ctxt, scope); - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine()); - QV4::ExecutionEngine *v4 = ep->v4engine(); + QV4::ExecutionEngine *v4 = engine()->handle(); QString function; @@ -123,7 +122,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, // It's important to call init first, because m_index gets remapped in case of cloned signals. init(ctxt, scope); - QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine); + QV4::ExecutionEngine *engine = ctxt->engine->handle(); QList<QByteArray> signalParameters = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).parameterNames(); if (!signalParameters.isEmpty()) { @@ -182,15 +181,17 @@ void QQmlBoundSignalExpression::evaluate(void **a) if (!expressionFunctionValid()) return; - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine()); - QV4::Scope scope(ep->v4engine()); + QQmlEngine *qmlengine = engine(); + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlengine); + QV4::ExecutionEngine *v4 = qmlengine->handle(); + QV4::Scope scope(v4); ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. QQmlMetaObject::ArgTypeStorage storage; //TODO: lookup via signal index rather than method index as an optimization int methodIndex = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).methodIndex(); - int *argsTypes = QQmlMetaObject(m_target).methodParameterTypes(methodIndex, &storage, 0); + int *argsTypes = QQmlMetaObject(m_target).methodParameterTypes(methodIndex, &storage, nullptr); int argCount = argsTypes ? *argsTypes : 0; QV4::JSCallData jsCall(scope, argCount); @@ -215,13 +216,13 @@ void QQmlBoundSignalExpression::evaluate(void **a) if (!*reinterpret_cast<void* const *>(a[ii + 1])) jsCall->args[ii] = QV4::Primitive::nullValue(); else - jsCall->args[ii] = QV4::QObjectWrapper::wrap(ep->v4engine(), *reinterpret_cast<QObject* const *>(a[ii + 1])); + jsCall->args[ii] = QV4::QObjectWrapper::wrap(v4, *reinterpret_cast<QObject* const *>(a[ii + 1])); } else { jsCall->args[ii] = scope.engine->fromVariant(QVariant(type, a[ii + 1])); } } - QQmlJavaScriptExpression::evaluate(jsCall.callData(), 0); + QQmlJavaScriptExpression::evaluate(jsCall.callData(), nullptr); ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. } @@ -233,8 +234,9 @@ void QQmlBoundSignalExpression::evaluate(const QList<QVariant> &args) if (!expressionFunctionValid()) return; - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine()); - QV4::Scope scope(ep->v4engine()); + QQmlEngine *qmlengine = engine(); + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(qmlengine); + QV4::Scope scope(qmlengine->handle()); ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. @@ -243,7 +245,7 @@ void QQmlBoundSignalExpression::evaluate(const QList<QVariant> &args) jsCall->args[ii] = scope.engine->fromVariant(args[ii]); } - QQmlJavaScriptExpression::evaluate(jsCall.callData(), 0); + QQmlJavaScriptExpression::evaluate(jsCall.callData(), nullptr); ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. } @@ -258,8 +260,8 @@ void QQmlBoundSignalExpression::evaluate(const QList<QVariant> &args) QQmlBoundSignal::QQmlBoundSignal(QObject *target, int signal, QObject *owner, QQmlEngine *engine) : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlBoundSignal), - m_prevSignal(0), m_nextSignal(0), - m_enabled(true), m_expression(0) + m_prevSignal(nullptr), m_nextSignal(nullptr), + m_enabled(true), m_expression(nullptr) { addToObject(owner); @@ -296,8 +298,8 @@ void QQmlBoundSignal::removeFromObject() if (m_prevSignal) { *m_prevSignal = m_nextSignal; if (m_nextSignal) m_nextSignal->m_prevSignal = m_prevSignal; - m_prevSignal = 0; - m_nextSignal = 0; + m_prevSignal = nullptr; + m_nextSignal = nullptr; } } diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h index 3a0b8aed59..01094a11f7 100644 --- a/src/qml/qml/qqmlboundsignal_p.h +++ b/src/qml/qml/qqmlboundsignal_p.h @@ -89,14 +89,14 @@ public: QString expression() const; QObject *target() const { return m_target; } - QQmlEngine *engine() const { return context() ? context()->engine : 0; } + QQmlEngine *engine() const { return context() ? context()->engine : nullptr; } private: - ~QQmlBoundSignalExpression(); + ~QQmlBoundSignalExpression() override; void init(QQmlContextData *ctxt, QObject *scope); - bool expressionFunctionValid() const { return function() != 0; } + bool expressionFunctionValid() const { return function() != nullptr; } int m_index; QObject *m_target; diff --git a/src/qml/qml/qqmlboundsignalexpressionpointer_p.h b/src/qml/qml/qqmlboundsignalexpressionpointer_p.h index de651315f8..eabe6666b4 100644 --- a/src/qml/qml/qqmlboundsignalexpressionpointer_p.h +++ b/src/qml/qml/qqmlboundsignalexpressionpointer_p.h @@ -58,7 +58,7 @@ class QQmlBoundSignalExpression; class Q_QML_PRIVATE_EXPORT QQmlBoundSignalExpressionPointer { public: - inline QQmlBoundSignalExpressionPointer() : o(0) {} + inline QQmlBoundSignalExpressionPointer() {} QQmlBoundSignalExpressionPointer(QQmlBoundSignalExpression *); QQmlBoundSignalExpressionPointer(const QQmlBoundSignalExpressionPointer &); ~QQmlBoundSignalExpressionPointer(); @@ -73,7 +73,7 @@ public: QQmlBoundSignalExpressionPointer &take(QQmlBoundSignalExpression *); private: - QQmlBoundSignalExpression *o; + QQmlBoundSignalExpression *o = nullptr; }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlcleanup.cpp b/src/qml/qml/qqmlcleanup.cpp index 708537a303..0d57ef5fe8 100644 --- a/src/qml/qml/qqmlcleanup.cpp +++ b/src/qml/qml/qqmlcleanup.cpp @@ -58,7 +58,7 @@ called by QQmlEngine just before it destroys the context. Create a QQmlCleanup that is not associated with any engine. */ QQmlCleanup::QQmlCleanup() -: prev(0), next(0), engine(0) +: prev(nullptr), next(nullptr), engine(nullptr) { } @@ -66,7 +66,7 @@ QQmlCleanup::QQmlCleanup() Create a QQmlCleanup for \a engine */ QQmlCleanup::QQmlCleanup(QQmlEngine *engine) -: prev(0), next(0), engine(0) +: prev(nullptr), next(nullptr), engine(nullptr) { if (!engine) return; @@ -109,8 +109,8 @@ QQmlCleanup::~QQmlCleanup() if (prev) *prev = next; if (next) next->prev = prev; - prev = 0; - next = 0; + prev = nullptr; + next = nullptr; } QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlcleanup_p.h b/src/qml/qml/qqmlcleanup_p.h index a1db656477..0e15c28b9d 100644 --- a/src/qml/qml/qqmlcleanup_p.h +++ b/src/qml/qml/qqmlcleanup_p.h @@ -64,7 +64,7 @@ public: QQmlCleanup(QQmlEngine *); virtual ~QQmlCleanup(); - bool hasEngine() const { return prev != 0; } + bool hasEngine() const { return prev != nullptr; } void addToEngine(QQmlEngine *); protected: virtual void clear() = 0; diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 5a03f2dd93..3174bbecd3 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -241,6 +241,9 @@ V4_DEFINE_EXTENSION(QQmlComponentExtension, componentExtension); \li main.qml \li \snippet qml/component/main.qml 0 \endtable + + It is important that the lifetime of the creation context outlive any created objects. See + \l{Maintaining Dynamically Created Objects} for more details. */ /*! @@ -315,7 +318,7 @@ void QQmlComponentPrivate::typeDataReady(QQmlTypeData *) Q_ASSERT(typeData); fromTypeData(typeData); - typeData = 0; + typeData = nullptr; progress = 1.0; emit q->statusChanged(q->status()); @@ -349,7 +352,7 @@ void QQmlComponentPrivate::clear() if (typeData) { typeData->unregisterCallback(this); typeData->release(); - typeData = 0; + typeData = nullptr; } compilationUnit = nullptr; @@ -497,8 +500,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, QObject *parent) Create a QQmlComponent from the given \a url and give it the specified \a parent and \a engine. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note \sa loadUrl() */ @@ -512,8 +514,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, const QUrl &url, QObject *paren specified \a parent and \a engine. If \a mode is \l Asynchronous, the component will be loaded and compiled asynchronously. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note \sa loadUrl() */ @@ -549,7 +550,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, const QString &fileName, : QQmlComponent(engine, parent) { Q_D(QQmlComponent); - const QUrl url = QDir::isAbsolutePath(fileName) ? QUrl::fromLocalFile(fileName) : d->engine->baseUrl().resolved(QUrl(fileName)); + const QUrl url = QDir::isAbsolutePath(fileName) ? QUrl::fromLocalFile(fileName) : QUrl(fileName); d->loadUrl(url, mode); } @@ -562,7 +563,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, QV4::CompiledData::CompilationU Q_D(QQmlComponent); d->compilationUnit = compilationUnit; d->start = start; - d->url = compilationUnit->url(); + d->url = compilationUnit->finalUrl(); d->progress = 1.0; } @@ -609,8 +610,7 @@ QQmlContext *QQmlComponent::creationContext() const /*! Load the QQmlComponent from the provided \a url. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note */ void QQmlComponent::loadUrl(const QUrl &url) { @@ -622,8 +622,7 @@ void QQmlComponent::loadUrl(const QUrl &url) Load the QQmlComponent from the provided \a url. If \a mode is \l Asynchronous, the component will be loaded and compiled asynchronously. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note */ void QQmlComponent::loadUrl(const QUrl &url, QQmlComponent::CompilationMode mode) { @@ -636,11 +635,21 @@ void QQmlComponentPrivate::loadUrl(const QUrl &newUrl, QQmlComponent::Compilatio Q_Q(QQmlComponent); clear(); - if ((newUrl.isRelative() && !newUrl.isEmpty()) - || newUrl.scheme() == QLatin1String("file")) // Workaround QTBUG-11929 - url = engine->baseUrl().resolved(newUrl); - else + if (newUrl.isRelative()) { + // The new URL is a relative URL like QUrl("main.qml"). + url = engine->baseUrl().resolved(QUrl(newUrl.toString())); + } else if (engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) { + // The new URL is a file on disk but it's a relative path; e.g.: + // QUrl::fromLocalFile("main.qml") or QUrl("file:main.qml") + // We need to remove the scheme so that it becomes a relative URL with a relative path: + QUrl fixedUrl(newUrl); + fixedUrl.setScheme(QString()); + // Then, turn it into an absolute URL with an absolute path by resolving it against the engine's baseUrl(). + // This is a compatibility hack for QTBUG-58837. + url = engine->baseUrl().resolved(fixedUrl); + } else { url = newUrl; + } if (newUrl.isEmpty()) { QQmlError error; @@ -814,27 +823,27 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context) Q_Q(QQmlComponent); if (!context) { qWarning("QQmlComponent: Cannot create a component in a null context"); - return 0; + return nullptr; } if (!context->isValid()) { qWarning("QQmlComponent: Cannot create a component in an invalid context"); - return 0; + return nullptr; } if (context->engine != engine) { qWarning("QQmlComponent: Must create component in context from the same QQmlEngine"); - return 0; + return nullptr; } if (state.completePending) { qWarning("QQmlComponent: Cannot create new component instance before completing the previous"); - return 0; + return nullptr; } if (!q->isReady()) { qWarning("QQmlComponent: Component is not ready"); - return 0; + return nullptr; } // Do not create infinite recursion in object creation @@ -842,7 +851,7 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context) if (++creationDepth.localData() >= maxCreationDepth) { qWarning("QQmlComponent: Component creation is recursing - aborting"); --creationDepth.localData(); - return 0; + return nullptr; } Q_ASSERT(creationDepth.localData() >= 1); depthIncreased = true; @@ -854,7 +863,7 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context) state.completePending = true; enginePriv->referenceScarceResources(); - QObject *rv = 0; + QObject *rv = nullptr; state.creator.reset(new QQmlObjectCreator(context, compilationUnit, creationContext)); rv = state.creator->create(start); if (!rv) @@ -959,7 +968,7 @@ void QQmlComponentPrivate::completeCreate() } QQmlComponentAttached::QQmlComponentAttached(QObject *parent) -: QObject(parent), prev(0), next(0) +: QObject(parent), prev(nullptr), next(nullptr) { } @@ -967,8 +976,8 @@ QQmlComponentAttached::~QQmlComponentAttached() { if (prev) *prev = next; if (next) next->prev = prev; - prev = 0; - next = 0; + prev = nullptr; + next = nullptr; } /*! @@ -1074,7 +1083,6 @@ void QQmlComponentPrivate::incubateObject( QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component); incubatorPriv->compilationUnit = componentPriv->compilationUnit; - incubatorPriv->compilationUnit->addref(); incubatorPriv->enginePriv = enginePriv; incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext)); incubatorPriv->subComponentToCreate = componentPriv->start; @@ -1111,11 +1119,11 @@ struct QmlIncubatorObject : public QV4::Object V4_OBJECT2(QmlIncubatorObject, Object) V4_NEEDS_DESTROY - static ReturnedValue method_get_statusChanged(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_set_statusChanged(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_status(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_object(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_forceCompletion(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_get_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_set_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_status(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_object(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_forceCompletion(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); void statusChanged(QQmlIncubator::Status); void setInitialState(QObject *); @@ -1264,7 +1272,7 @@ void QQmlComponent::createObject(QQmlV4Function *args) Q_ASSERT(d->engine); Q_ASSERT(args); - QObject *parent = 0; + QObject *parent = nullptr; QV4::ExecutionEngine *v4 = args->v4engine(); QV4::Scope scope(v4); QV4::ScopedValue valuemap(scope, QV4::Primitive::undefinedValue()); @@ -1381,7 +1389,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args) QV4::ExecutionEngine *v4 = args->v4engine(); QV4::Scope scope(v4); - QObject *parent = 0; + QObject *parent = nullptr; QV4::ScopedValue valuemap(scope, QV4::Primitive::undefinedValue()); QQmlIncubator::IncubationMode mode = QQmlIncubator::Asynchronous; @@ -1436,8 +1444,7 @@ void QQmlComponent::incubateObject(QQmlV4Function *args) // XXX used by QSGLoader void QQmlComponentPrivate::initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext, const QV4::Value &valuemap, QObject *toCreate) { - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); - QV4::ExecutionEngine *v4engine = QV8Engine::getV4(ep->v8engine()); + QV4::ExecutionEngine *v4engine = engine->handle(); QV4::Scope scope(v4engine); QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(v4engine, toCreate)); @@ -1453,27 +1460,27 @@ QQmlComponentExtension::QQmlComponentExtension(QV4::ExecutionEngine *v4) QV4::ScopedObject proto(scope, v4->newObject()); proto->defineAccessorProperty(QStringLiteral("onStatusChanged"), QV4::QmlIncubatorObject::method_get_statusChanged, QV4::QmlIncubatorObject::method_set_statusChanged); - proto->defineAccessorProperty(QStringLiteral("status"), QV4::QmlIncubatorObject::method_get_status, 0); - proto->defineAccessorProperty(QStringLiteral("object"), QV4::QmlIncubatorObject::method_get_object, 0); + proto->defineAccessorProperty(QStringLiteral("status"), QV4::QmlIncubatorObject::method_get_status, nullptr); + proto->defineAccessorProperty(QStringLiteral("object"), QV4::QmlIncubatorObject::method_get_object, nullptr); proto->defineDefaultProperty(QStringLiteral("forceCompletion"), QV4::QmlIncubatorObject::method_forceCompletion); incubationProto.set(v4, proto); } -QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_object(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_object(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>()); + QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>()); if (!o) THROW_TYPE_ERROR(); return QV4::QObjectWrapper::wrap(scope.engine, o->d()->incubator->object()); } -QV4::ReturnedValue QV4::QmlIncubatorObject::method_forceCompletion(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QV4::QmlIncubatorObject::method_forceCompletion(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>()); + QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>()); if (!o) THROW_TYPE_ERROR(); @@ -1482,34 +1489,34 @@ QV4::ReturnedValue QV4::QmlIncubatorObject::method_forceCompletion(const Builtin RETURN_UNDEFINED(); } -QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_status(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_status(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>()); + QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>()); if (!o) THROW_TYPE_ERROR(); return QV4::Encode(o->d()->incubator->status()); } -QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_statusChanged(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QV4::QmlIncubatorObject::method_get_statusChanged(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>()); + QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>()); if (!o) THROW_TYPE_ERROR(); return QV4::Encode(o->d()->statusChanged); } -QV4::ReturnedValue QV4::QmlIncubatorObject::method_set_statusChanged(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QV4::QmlIncubatorObject::method_set_statusChanged(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { QV4::Scope scope(b); - QV4::Scoped<QmlIncubatorObject> o(scope, callData->thisObject.as<QmlIncubatorObject>()); - if (!o || callData->argc() < 1) + QV4::Scoped<QmlIncubatorObject> o(scope, thisObject->as<QmlIncubatorObject>()); + if (!o || argc < 1) THROW_TYPE_ERROR(); - o->d()->statusChanged.set(scope.engine, callData->args[0]); + o->d()->statusChanged.set(scope.engine, argv[0]); RETURN_UNDEFINED(); } diff --git a/src/qml/qml/qqmlcomponent.h b/src/qml/qml/qqmlcomponent.h index b8cc556e4a..444b3ec46c 100644 --- a/src/qml/qml/qqmlcomponent.h +++ b/src/qml/qml/qqmlcomponent.h @@ -83,7 +83,7 @@ public: QQmlComponent(QQmlEngine *, const QString &fileName, CompilationMode mode, QObject *parent = nullptr); QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr); QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr); - virtual ~QQmlComponent(); + ~QQmlComponent() override; enum Status { Null, Ready, Loading, Error }; Q_ENUM(Status) diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h index 8a58a1ada0..2a8d36f317 100644 --- a/src/qml/qml/qqmlcomponent_p.h +++ b/src/qml/qml/qqmlcomponent_p.h @@ -79,7 +79,7 @@ class Q_QML_PRIVATE_EXPORT QQmlComponentPrivate : public QObjectPrivate, public public: QQmlComponentPrivate() - : typeData(0), progress(0.), start(-1), engine(0), creationContext(0), depthIncreased(false) {} + : typeData(nullptr), progress(0.), start(-1), engine(nullptr), creationContext(nullptr), depthIncreased(false) {} void loadUrl(const QUrl &newUrl, QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous); diff --git a/src/qml/qml/qqmlcomponentattached_p.h b/src/qml/qml/qqmlcomponentattached_p.h index 8236aac1af..e3bca18857 100644 --- a/src/qml/qml/qqmlcomponentattached_p.h +++ b/src/qml/qml/qqmlcomponentattached_p.h @@ -62,7 +62,7 @@ class Q_QML_PRIVATE_EXPORT QQmlComponentAttached : public QObject { Q_OBJECT public: - QQmlComponentAttached(QObject *parent = 0); + QQmlComponentAttached(QObject *parent = nullptr); ~QQmlComponentAttached(); void add(QQmlComponentAttached **a) { @@ -72,7 +72,7 @@ public: void rem() { if (next) next->prev = prev; *prev = next; - next = 0; prev = 0; + next = nullptr; prev = nullptr; } QQmlComponentAttached **prev; QQmlComponentAttached *next; diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 37cb328b36..6e43bc735f 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -56,7 +56,7 @@ QT_BEGIN_NAMESPACE QQmlContextPrivate::QQmlContextPrivate() -: data(0), notifyIndex(-1) +: data(nullptr), notifyIndex(-1) { } @@ -177,7 +177,7 @@ QQmlContext::QQmlContext(QQmlEngine *engine, QObject *parent) d->data = new QQmlContextData(this); ++d->data->refCount; - d->data->setParent(engine?QQmlContextData::get(engine->rootContext()):0); + d->data->setParent(engine?QQmlContextData::get(engine->rootContext()):nullptr); } /*! @@ -191,14 +191,14 @@ QQmlContext::QQmlContext(QQmlContext *parentContext, QObject *parent) d->data = new QQmlContextData(this); ++d->data->refCount; - d->data->setParent(parentContext?QQmlContextData::get(parentContext):0); + d->data->setParent(parentContext?QQmlContextData::get(parentContext):nullptr); } /*! \internal */ QQmlContext::QQmlContext(QQmlContextData *data) -: QObject(*(new QQmlContextPrivate), 0) +: QObject(*(new QQmlContextPrivate), nullptr) { Q_D(QQmlContext); d->data = data; @@ -216,7 +216,7 @@ QQmlContext::~QQmlContext() { Q_D(QQmlContext); - d->data->publicContext = 0; + d->data->publicContext = nullptr; if (!--d->data->refCount) d->data->destroy(); } @@ -250,7 +250,7 @@ QQmlEngine *QQmlContext::engine() const QQmlContext *QQmlContext::parentContext() const { Q_D(const QQmlContext); - return d->data->parent?d->data->parent->asQQmlContext():0; + return d->data->parent?d->data->parent->asQQmlContext():nullptr; } /*! @@ -306,16 +306,7 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value) return; } - if (data->engine) { - bool ok; - QObject *o = QQmlEnginePrivate::get(data->engine)->toQObject(value, &ok); - if (ok) { - setContextProperty(name, o); - return; - } - } - - QV4::IdentifierHash<int> &properties = data->detachedPropertyNames(); + QV4::IdentifierHash &properties = data->detachedPropertyNames(); int idx = properties.value(name); if (idx == -1) { properties.add(name, data->idValueCount + d->propertyValues.count()); @@ -324,7 +315,7 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value) data->refreshExpressions(); } else { d->propertyValues[idx] = value; - QMetaObject::activate(this, d->notifyIndex, idx, 0); + QMetaObject::activate(this, d->notifyIndex, idx, nullptr); } } @@ -335,37 +326,54 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value) */ void QQmlContext::setContextProperty(const QString &name, QObject *value) { - Q_D(QQmlContext); - if (d->notifyIndex == -1) - d->notifyIndex = QMetaObjectPrivate::absoluteSignalCount(&QQmlContext::staticMetaObject); + setContextProperty(name, QVariant::fromValue(value)); +} + +/*! + \since 5.11 + + Set a batch of \a properties on this context. + + Setting all properties in one batch avoids unnecessary + refreshing expressions, and is therefore recommended + instead of calling \l setContextProperty() for each individual property. + + \sa QQmlContext::setContextProperty() +*/ +void QQmlContext::setContextProperties(const QVector<PropertyPair> &properties) +{ + Q_D(const QQmlContext); QQmlContextData *data = d->data; - if (data->isInternal) { - qWarning("QQmlContext: Cannot set property on internal context."); - return; - } + QQmlJavaScriptExpression *expressions = data->expressions; + QQmlContextData *childContexts = data->childContexts; - if (!isValid()) { - qWarning("QQmlContext: Cannot set property on invalid context."); - return; - } + data->expressions = nullptr; + data->childContexts = nullptr; - QV4::IdentifierHash<int> &properties = data->detachedPropertyNames(); - int idx = properties.value(name); + for (auto property : properties) + setContextProperty(property.name, property.value); - if (idx == -1) { - properties.add(name, data->idValueCount + d->propertyValues.count()); - d->propertyValues.append(QVariant::fromValue(value)); + data->expressions = expressions; + data->childContexts = childContexts; - data->refreshExpressions(); - } else { - d->propertyValues[idx] = QVariant::fromValue(value); - QMetaObject::activate(this, d->notifyIndex, idx, 0); - } + data->refreshExpressions(); } /*! + \since 5.11 + + \class QQmlContext::PropertyPair + \inmodule QtQml + + This struct contains a property name and a property value. + It is used as a parameter for the \c setContextProperties function. + + \sa QQmlContext::setContextProperties() +*/ + +/*! Returns the value of the \a name property for this context as a QVariant. */ @@ -377,7 +385,7 @@ QVariant QQmlContext::contextProperty(const QString &name) const QQmlContextData *data = d->data; - const QV4::IdentifierHash<int> &properties = data->propertyNames(); + const QV4::IdentifierHash &properties = data->propertyNames(); if (properties.count()) idx = properties.value(name); @@ -513,7 +521,7 @@ QObject *QQmlContextPrivate::context_at(QQmlListProperty<QObject> *prop, int ind int contextProperty = (int)(quintptr)prop->data; if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId<QList<QObject*> >()) { - return 0; + return nullptr; } else { return ((const QList<QObject*> *)d->propertyValues.at(contextProperty).constData())->at(index); } @@ -526,12 +534,12 @@ QQmlContextData::QQmlContextData() } QQmlContextData::QQmlContextData(QQmlContext *ctxt) - : engine(0), isInternal(false), isJSContext(false), + : engine(nullptr), isInternal(false), isJSContext(false), isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), isRootObjectInCreation(false), - publicContext(ctxt), incubator(0), componentObjectIndex(-1), - contextObject(0), nextChild(0), prevChild(0), - expressions(0), contextObjects(0), idValues(0), idValueCount(0), - componentAttached(0) + publicContext(ctxt), incubator(nullptr), componentObjectIndex(-1), + contextObject(nullptr), nextChild(nullptr), prevChild(nullptr), + expressions(nullptr), contextObjects(nullptr), idValues(nullptr), idValueCount(0), + componentAttached(nullptr) { } @@ -548,8 +556,8 @@ void QQmlContextData::emitDestruction() componentAttached = a->next; if (componentAttached) componentAttached->prev = &componentAttached; - a->next = 0; - a->prev = 0; + a->next = nullptr; + a->prev = nullptr; emit a->destruction(); } @@ -575,12 +583,14 @@ void QQmlContextData::invalidate() if (prevChild) { *prevChild = nextChild; if (nextChild) nextChild->prevChild = prevChild; - nextChild = 0; - prevChild = 0; + nextChild = nullptr; + prevChild = nullptr; } - engine = 0; - parent = 0; + importedScripts.clear(); + + engine = nullptr; + parent = nullptr; } void QQmlContextData::clearContext() @@ -591,20 +601,20 @@ void QQmlContextData::clearContext() while (expression) { QQmlJavaScriptExpression *nextExpression = expression->m_nextExpression; - expression->m_prevExpression = 0; - expression->m_nextExpression = 0; + expression->m_prevExpression = nullptr; + expression->m_nextExpression = nullptr; - expression->setContext(0); + expression->setContext(nullptr); expression = nextExpression; } - expressions = 0; + expressions = nullptr; } void QQmlContextData::destroy() { Q_ASSERT(refCount == 0); - linkedContext = 0; + linkedContext = nullptr; // avoid recursion ++refCount; @@ -619,26 +629,26 @@ void QQmlContextData::destroy() QQmlData *co = contextObjects; contextObjects = contextObjects->nextContextObject; - co->context = 0; - co->outerContext = 0; - co->nextContextObject = 0; - co->prevContextObject = 0; + co->context = nullptr; + co->outerContext = nullptr; + co->nextContextObject = nullptr; + co->prevContextObject = nullptr; } Q_ASSERT(refCount == 1); QQmlGuardedContextData *contextGuard = contextGuards; while (contextGuard) { QQmlGuardedContextData *next = contextGuard->m_next; - contextGuard->m_next = 0; - contextGuard->m_prev = 0; - contextGuard->m_contextData = 0; + contextGuard->m_next = nullptr; + contextGuard->m_prev = nullptr; + contextGuard->m_contextData = nullptr; contextGuard = next; } - contextGuards = 0; + contextGuards = nullptr; Q_ASSERT(refCount == 1); delete [] idValues; - idValues = 0; + idValues = nullptr; Q_ASSERT(refCount == 1); if (publicContext) { @@ -736,7 +746,7 @@ void QQmlContextData::refreshExpressionsRecursive(bool isGlobal) // *structure* (not values) changes. void QQmlContextData::refreshExpressions() { - bool isGlobal = (parent == 0); + bool isGlobal = (parent == nullptr); // For efficiency, we try and minimize the number of guards we have to create if (expressions_to_run(this, isGlobal) && childContexts) { @@ -762,7 +772,7 @@ void QQmlContextData::addObject(QObject *o) { QQmlData *data = QQmlData::get(o, true); - Q_ASSERT(data->context == 0); + Q_ASSERT(data->context == nullptr); data->context = this; data->outerContext = this; @@ -782,7 +792,7 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj) QString QQmlContextData::findObjectId(const QObject *obj) const { - const QV4::IdentifierHash<int> &properties = propertyNames(); + const QV4::IdentifierHash &properties = propertyNames(); if (propertyNameCache.isEmpty()) return QString(); @@ -824,18 +834,18 @@ void QQmlContextData::initFromTypeCompilationUnit(const QQmlRefPointer<QV4::Comp idValues = new ContextGuard[idValueCount]; } -const QV4::IdentifierHash<int> &QQmlContextData::propertyNames() const +const QV4::IdentifierHash &QQmlContextData::propertyNames() const { if (propertyNameCache.isEmpty()) { if (typeCompilationUnit) propertyNameCache = typeCompilationUnit->namedObjectsPerComponent(componentObjectIndex); else - propertyNameCache = QV4::IdentifierHash<int>(QV8Engine::getV4(engine)); + propertyNameCache = QV4::IdentifierHash(engine->handle()); } return propertyNameCache; } -QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames() +QV4::IdentifierHash &QQmlContextData::detachedPropertyNames() { propertyNames(); propertyNameCache.detach(); @@ -845,14 +855,14 @@ QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames() QUrl QQmlContextData::url() const { if (typeCompilationUnit) - return typeCompilationUnit->url(); + return typeCompilationUnit->finalUrl(); return baseUrl; } QString QQmlContextData::urlString() const { if (typeCompilationUnit) - return typeCompilationUnit->fileName(); + return typeCompilationUnit->finalUrlString(); return baseUrlString; } diff --git a/src/qml/qml/qqmlcontext.h b/src/qml/qml/qqmlcontext.h index b2b95b7573..7ed70c7619 100644 --- a/src/qml/qml/qqmlcontext.h +++ b/src/qml/qml/qqmlcontext.h @@ -42,6 +42,8 @@ #include <QtCore/qurl.h> #include <QtCore/qobject.h> +#include <QtCore/qlist.h> +#include <QtCore/qpair.h> #include <QtQml/qjsvalue.h> #include <QtCore/qmetatype.h> #include <QtCore/qvariant.h> @@ -62,9 +64,11 @@ class Q_QML_EXPORT QQmlContext : public QObject Q_DECLARE_PRIVATE(QQmlContext) public: + struct PropertyPair { QString name; QVariant value; }; + QQmlContext(QQmlEngine *parent, QObject *objParent = nullptr); QQmlContext(QQmlContext *parent, QObject *objParent = nullptr); - virtual ~QQmlContext(); + ~QQmlContext() override; bool isValid() const; @@ -77,6 +81,7 @@ public: QVariant contextProperty(const QString &) const; void setContextProperty(const QString &, QObject *); void setContextProperty(const QString &, const QVariant &); + void setContextProperties(const QVector<PropertyPair> &properties); // ### Qt 6: no need for a mutable object, this should become a const QObject pointer QString nameForObject(QObject *) const; diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h index d01820a430..ff36d6c9a8 100644 --- a/src/qml/qml/qqmlcontext_p.h +++ b/src/qml/qml/qqmlcontext_p.h @@ -158,9 +158,9 @@ public: void initFromTypeCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit, int subComponentIndex); // flag indicates whether the context owns the cache (after mutation) or not. - mutable QV4::IdentifierHash<int> propertyNameCache; - const QV4::IdentifierHash<int> &propertyNames() const; - QV4::IdentifierHash<int> &detachedPropertyNames(); + mutable QV4::IdentifierHash propertyNameCache; + const QV4::IdentifierHash &propertyNames() const; + QV4::IdentifierHash &detachedPropertyNames(); // Context object QObject *contextObject; @@ -178,7 +178,7 @@ public: QQmlRefPointer<QQmlTypeNameCache> imports; // My children - QQmlContextData *childContexts = 0; + QQmlContextData *childContexts = nullptr; // My peers in parent's childContexts list QQmlContextData *nextChild; @@ -191,7 +191,7 @@ public: QQmlData *contextObjects; // Doubly-linked list of context guards (XXX merge with contextObjects) - QQmlGuardedContextData *contextGuards = 0; + QQmlGuardedContextData *contextGuards = nullptr; // id guards struct ContextGuard : public QQmlGuard<QObject> @@ -261,9 +261,9 @@ private: inline void clear(); - QQmlContextData *m_contextData = 0; - QQmlGuardedContextData *m_next = 0; - QQmlGuardedContextData **m_prev = 0; + QQmlContextData *m_contextData = nullptr; + QQmlGuardedContextData *m_next = nullptr; + QQmlGuardedContextData **m_prev = nullptr; }; @@ -287,14 +287,14 @@ void QQmlGuardedContextData::clear() if (m_prev) { *m_prev = m_next; if (m_next) m_next->m_prev = m_prev; - m_contextData = 0; - m_next = 0; - m_prev = 0; + m_contextData = nullptr; + m_next = nullptr; + m_prev = nullptr; } } QQmlContextDataRef::QQmlContextDataRef() - : m_contextData(0) + : m_contextData(nullptr) { } @@ -338,7 +338,7 @@ void QQmlContextDataRef::clear() { if (m_contextData && !--m_contextData->refCount) m_contextData->destroy(); - m_contextData = 0; + m_contextData = nullptr; } QQmlContextDataRef & @@ -356,7 +356,7 @@ QQmlContextDataRef::operator=(const QQmlContextDataRef &other) } QQmlContextData::ContextGuard::ContextGuard() -: context(0) +: context(nullptr) { } diff --git a/src/qml/qml/qqmlcustomparser.cpp b/src/qml/qml/qqmlcustomparser.cpp index cc6e75a39c..5cf87f5264 100644 --- a/src/qml/qml/qqmlcustomparser.cpp +++ b/src/qml/qml/qqmlcustomparser.cpp @@ -138,7 +138,7 @@ int QQmlCustomParser::evaluateEnum(const QByteArray& script, bool *ok) const QQmlType type; if (imports.isT1()) { - imports.asT1()->resolveType(scope, &type, 0, 0, 0); + imports.asT1()->resolveType(scope, &type, nullptr, nullptr, nullptr); } else { QQmlTypeNameCache::Result result = imports.asT2()->query(scope); if (result.isValid()) @@ -178,7 +178,7 @@ const QMetaObject *QQmlCustomParser::resolveType(const QString& name) const if (!imports.isT1()) return nullptr; QQmlType qmltype; - if (!imports.asT1()->resolveType(name, &qmltype, 0, 0, 0)) + if (!imports.asT1()->resolveType(name, &qmltype, nullptr, nullptr, nullptr)) return nullptr; return qmltype.metaObject(); } diff --git a/src/qml/qml/qqmlcustomparser_p.h b/src/qml/qml/qqmlcustomparser_p.h index 5eb409990d..2a0f805014 100644 --- a/src/qml/qml/qqmlcustomparser_p.h +++ b/src/qml/qml/qqmlcustomparser_p.h @@ -74,8 +74,8 @@ public: }; Q_DECLARE_FLAGS(Flags, Flag) - QQmlCustomParser() : engine(0), validator(0), m_flags(NoFlag) {} - QQmlCustomParser(Flags f) : engine(0), validator(0), m_flags(f) {} + QQmlCustomParser() : engine(nullptr), validator(nullptr), m_flags(NoFlag) {} + QQmlCustomParser(Flags f) : engine(nullptr), validator(nullptr), m_flags(f) {} virtual ~QQmlCustomParser() {} void clearErrors(); diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h index d692feb975..20b96d2c4b 100644 --- a/src/qml/qml/qqmldata_p.h +++ b/src/qml/qml/qqmldata_p.h @@ -56,6 +56,7 @@ #include <private/qqmlpropertyindex_p.h> #include <private/qv4value_p.h> #include <private/qv4persistent_p.h> +#include <private/qqmlrefcount_p.h> #include <qjsengine.h> #include <qvector.h> @@ -76,6 +77,7 @@ class QQmlNotifierEndpoint; namespace QV4 { namespace CompiledData { struct CompilationUnit; +struct Binding; } } @@ -115,6 +117,7 @@ class Q_QML_PRIVATE_EXPORT QQmlData : public QAbstractDeclarativeData { public: QQmlData(); + ~QQmlData(); static inline void init() { static bool initialized = false; @@ -155,18 +158,21 @@ public: quint32 hasInterceptorMetaObject:1; quint32 hasVMEMetaObject:1; quint32 parentFrozen:1; - quint32 dummy:22; + quint32 dummy:6; // When bindingBitsSize < sizeof(ptr), we store the binding bit flags inside // bindingBitsValue. When we need more than sizeof(ptr) bits, we allocated // sufficient space and use bindingBits to point to it. - int bindingBitsSize; + quint32 bindingBitsArraySize : 16; typedef quintptr BindingBitsType; + enum { + BitsPerType = sizeof(BindingBitsType) * 8, + InlineBindingArraySize = 2 + }; union { BindingBitsType *bindingBits; - BindingBitsType bindingBitsValue; + BindingBitsType bindingBitsValue[InlineBindingArraySize]; }; - enum { MaxInlineBits = sizeof(BindingBitsType) * 8 }; struct NotifyList { quint64 connectionMask; @@ -189,9 +195,9 @@ public: void disconnectNotifiers(); // The context that created the C++ object - QQmlContextData *context = 0; + QQmlContextData *context = nullptr; // The outermost context in which this object lives - QQmlContextData *outerContext = 0; + QQmlContextData *outerContext = nullptr; QQmlContextDataRef ownContext; QQmlAbstractBinding *bindings; @@ -215,13 +221,18 @@ public: quint32 jsEngineId; // id of the engine that created the jsWrapper struct DeferredData { + DeferredData(); + ~DeferredData(); unsigned int deferredIdx; - QV4::CompiledData::CompilationUnit *compilationUnit;//Not always the same as the other compilation unit + QMultiHash<int, const QV4::CompiledData::Binding *> bindings; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit;//Not always the same as the other compilation unit QQmlContextData *context;//Could be either context or outerContext + Q_DISABLE_COPY(DeferredData); }; - QV4::CompiledData::CompilationUnit *compilationUnit; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; QVector<DeferredData *> deferredData; + void deferData(int objectIndex, QV4::CompiledData::CompilationUnit *, QQmlContextData *); void releaseDeferredData(); QV4::WeakValue jsWrapper; @@ -236,13 +247,13 @@ public: // to be avoided because QObjectPrivate::currentChildBeingDeleted is in use. if (priv->isDeletingChildren || priv->wasDeleted) { Q_ASSERT(!create); - return 0; + return nullptr; } else if (priv->declarativeData) { return static_cast<QQmlData *>(priv->declarativeData); } else if (create) { return createQQmlData(priv); } else { - return 0; + return nullptr; } } @@ -253,10 +264,10 @@ public: return false; } - bool hasExtendedData() const { return extendedData != 0; } + bool hasExtendedData() const { return extendedData != nullptr; } QHash<int, QObject *> *attachedProperties() const; - static inline bool wasDeleted(QObject *); + static inline bool wasDeleted(const QObject *); static void markAsDeleted(QObject *); static void setQueuedForDeletion(QObject *); @@ -272,6 +283,9 @@ public: return createPropertyCache(engine, object); } + Q_ALWAYS_INLINE static uint offsetForBit(int bit) { return static_cast<uint>(bit) / BitsPerType; } + Q_ALWAYS_INLINE static BindingBitsType bitFlagForBit(int bit) { return BindingBitsType(1) << (static_cast<uint>(bit) & (BitsPerType - 1)); } + private: // For attachedProperties mutable QQmlDataExtended *extendedData; @@ -283,26 +297,26 @@ private: Q_ALWAYS_INLINE bool hasBitSet(int bit) const { - if (bindingBitsSize <= bit) + uint offset = offsetForBit(bit); + if (bindingBitsArraySize <= offset) return false; - if (bindingBitsSize == MaxInlineBits) - return bindingBitsValue & (BindingBitsType(1) << bit); - else - return bindingBits[bit / MaxInlineBits] & (BindingBitsType(1) << (bit % MaxInlineBits)); + const BindingBitsType *bits = (bindingBitsArraySize == InlineBindingArraySize) ? bindingBitsValue : bindingBits; + return bits[offset] & bitFlagForBit(bit); } + Q_DISABLE_COPY(QQmlData); }; -bool QQmlData::wasDeleted(QObject *object) +bool QQmlData::wasDeleted(const QObject *object) { if (!object) return true; - QObjectPrivate *priv = QObjectPrivate::get(object); + const QObjectPrivate *priv = QObjectPrivate::get(object); if (!priv || priv->wasDeleted) return true; - QQmlData *ddata = QQmlData::get(object); + const QQmlData *ddata = QQmlData::get(object); return ddata && ddata->isQueuedForDeletion; } @@ -311,7 +325,7 @@ QQmlNotifierEndpoint *QQmlData::notify(int index) Q_ASSERT(index <= 0xFFFF); if (!notifyList || !(notifyList->connectionMask & (1ULL << quint64(index % 64)))) { - return 0; + return nullptr; } else if (index < notifyList->notifiesSize) { return notifyList->notifies[index]; } else if (index <= notifyList->maximumTodoIndex) { @@ -321,7 +335,7 @@ QQmlNotifierEndpoint *QQmlData::notify(int index) if (index < notifyList->notifiesSize) { return notifyList->notifies[index]; } else { - return 0; + return nullptr; } } diff --git a/src/qml/qml/qqmldelayedcallqueue.cpp b/src/qml/qml/qqmldelayedcallqueue.cpp index df4030e522..5bcf5cd586 100644 --- a/src/qml/qml/qqmldelayedcallqueue.cpp +++ b/src/qml/qml/qqmldelayedcallqueue.cpp @@ -89,7 +89,7 @@ void QQmlDelayedCallQueue::DelayedFunctionCall::execute(QV4::ExecutionEngine *en // QQmlDelayedCallQueue::QQmlDelayedCallQueue() - : QObject(0), m_engine(0), m_callbackOutstanding(false) + : QObject(nullptr), m_engine(nullptr), m_callbackOutstanding(false) { } @@ -106,18 +106,19 @@ void QQmlDelayedCallQueue::init(QV4::ExecutionEngine* engine) m_tickedMethod = metaObject.method(methodIndex); } -QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::BuiltinFunction *b, QV4::CallData *callData) +QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() == 0) + if (argc == 0) THROW_GENERIC_ERROR("Qt.callLater: no arguments given"); - const QV4::FunctionObject *func = callData->args[0].as<QV4::FunctionObject>(); + const QV4::FunctionObject *func = argv[0].as<QV4::FunctionObject>(); if (!func) THROW_GENERIC_ERROR("Qt.callLater: first argument not a function or signal"); QPair<QObject *, int> functionData = QV4::QObjectMethod::extractQtMethod(func); + QV4::ReturnedValue arg0 = argc ? argv[0].asReturnedValue() : QV4::Encode::undefined(); QVector<DelayedFunctionCall>::Iterator iter; if (functionData.second != -1) { @@ -136,7 +137,7 @@ QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::B iter = m_delayedFunctionCalls.begin(); while (iter != m_delayedFunctionCalls.end()) { DelayedFunctionCall& dfc = *iter; - if (callData->argument(0) == dfc.m_function.value()) { + if (arg0 == dfc.m_function.value()) { break; // Already stored! } ++iter; @@ -149,7 +150,7 @@ QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::B m_delayedFunctionCalls.erase(iter); m_delayedFunctionCalls.append(dfc); } else { - m_delayedFunctionCalls.append(QV4::PersistentValue(m_engine, callData->argument(0))); + m_delayedFunctionCalls.append(QV4::PersistentValue(m_engine, arg0)); } DelayedFunctionCall& dfc = m_delayedFunctionCalls.last(); @@ -165,7 +166,7 @@ QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::B dfc.m_guarded = true; } } - storeAnyArguments(dfc, callData, 1, m_engine); + storeAnyArguments(dfc, argv, argc, 1, m_engine); if (!m_callbackOutstanding) { m_tickedMethod.invoke(this, Qt::QueuedConnection); @@ -174,9 +175,9 @@ QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(const QV4::B return QV4::Encode::undefined(); } -void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, const QV4::CallData *callData, int offset, QV4::ExecutionEngine *engine) +void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, const QV4::Value *argv, int argc, int offset, QV4::ExecutionEngine *engine) { - const int length = callData->argc() - offset; + const int length = argc - offset; if (length == 0) { dfc.m_args.clear(); return; @@ -184,8 +185,8 @@ void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, const QV4 QV4::Scope scope(engine); QV4::ScopedArrayObject array(scope, engine->newArrayObject(length)); uint i = 0; - for (int j = offset, ej = callData->argc(); j < ej; ++i, ++j) - array->putIndexed(i, callData->args[j]); + for (int j = offset, ej = argc; j < ej; ++i, ++j) + array->putIndexed(i, argv[j]); dfc.m_args.set(engine, array); } diff --git a/src/qml/qml/qqmldelayedcallqueue_p.h b/src/qml/qml/qqmldelayedcallqueue_p.h index 5b3043cfed..7962318561 100644 --- a/src/qml/qml/qqmldelayedcallqueue_p.h +++ b/src/qml/qml/qqmldelayedcallqueue_p.h @@ -60,17 +60,16 @@ QT_BEGIN_NAMESPACE -class QV8Engine; class QQmlDelayedCallQueue : public QObject { Q_OBJECT public: QQmlDelayedCallQueue(); - ~QQmlDelayedCallQueue(); + ~QQmlDelayedCallQueue() override; void init(QV4::ExecutionEngine *); - QV4::ReturnedValue addUniquelyAndExecuteLater(const QV4::BuiltinFunction *, QV4::CallData *callData); + QV4::ReturnedValue addUniquelyAndExecuteLater(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); public Q_SLOTS: void ticked(); @@ -90,7 +89,7 @@ private: bool m_guarded; }; - void storeAnyArguments(DelayedFunctionCall& dfc, const QV4::CallData *callData, int offset, QV4::ExecutionEngine *engine); + void storeAnyArguments(DelayedFunctionCall& dfc, const QV4::Value *argv, int argc, int offset, QV4::ExecutionEngine *engine); void executeAllExpired_Later(); QV4::ExecutionEngine *m_engine; diff --git a/src/qml/qml/qqmldirparser_p.h b/src/qml/qml/qqmldirparser_p.h index 1530b7a6cf..95370398ad 100644 --- a/src/qml/qml/qqmldirparser_p.h +++ b/src/qml/qml/qqmldirparser_p.h @@ -91,8 +91,7 @@ public: struct Component { - Component() - : majorVersion(0), minorVersion(0), internal(false), singleton(false) {} + Component() {} Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion) : typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion), @@ -100,24 +99,23 @@ public: QString typeName; QString fileName; - int majorVersion; - int minorVersion; - bool internal; - bool singleton; + int majorVersion = 0; + int minorVersion = 0; + bool internal = false; + bool singleton = false; }; struct Script { - Script() - : majorVersion(0), minorVersion(0) {} + Script() {} Script(const QString &nameSpace, const QString &fileName, int majorVersion, int minorVersion) : nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) {} QString nameSpace; QString fileName; - int majorVersion; - int minorVersion; + int majorVersion = 0; + int minorVersion = 0; }; QHash<QString,Component> components() const; diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 9ef47b2c2e..4054d2f0be 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -110,7 +110,10 @@ Q_DECLARE_METATYPE(QQmlProperty) QT_BEGIN_NAMESPACE typedef QQmlData::BindingBitsType BindingBitsType; -enum { MaxInlineBits = QQmlData::MaxInlineBits }; +enum { + BitsPerType = QQmlData::BitsPerType, + InlineBindingArraySize = QQmlData::InlineBindingArraySize +}; void qmlRegisterBaseTypes(const char *uri, int versionMajor, int versionMinor) { @@ -666,19 +669,19 @@ the same object as is returned from the Qt.include() call. // Qt.include() is implemented in qv4include.cpp QQmlEnginePrivate::QQmlEnginePrivate(QQmlEngine *e) -: propertyCapture(0), rootContext(0), +: propertyCapture(nullptr), rootContext(nullptr), #if QT_CONFIG(qml_debug) - profiler(0), + profiler(nullptr), #endif outputWarningsToMsgLog(true), - cleanup(0), erroredBindings(0), inProgressCreations(0), - workerScriptEngine(0), - activeObjectCreator(0), + cleanup(nullptr), erroredBindings(nullptr), inProgressCreations(0), + workerScriptEngine(nullptr), + activeObjectCreator(nullptr), #if QT_CONFIG(qml_network) - networkAccessManager(0), networkAccessManagerFactory(0), + networkAccessManager(nullptr), networkAccessManagerFactory(nullptr), #endif - urlInterceptor(0), scarceResourcesRefCount(0), importDatabase(e), typeLoader(e), - uniqueId(1), incubatorCount(0), incubationController(0) + urlInterceptor(nullptr), scarceResourcesRefCount(0), importDatabase(e), typeLoader(e), + uniqueId(1), incubatorCount(0), incubationController(nullptr) { } @@ -691,15 +694,15 @@ QQmlEnginePrivate::~QQmlEnginePrivate() QQmlCleanup *c = cleanup; cleanup = c->next; if (cleanup) cleanup->prev = &cleanup; - c->next = 0; - c->prev = 0; + c->next = nullptr; + c->prev = nullptr; c->clear(); } doDeleteInEngineThread(); - if (incubationController) incubationController->d = 0; - incubationController = 0; + if (incubationController) incubationController->d = nullptr; + incubationController = nullptr; QQmlMetaType::freeUnusedTypesAndCaches(); @@ -720,13 +723,16 @@ void QQmlPrivate::qdeclarativeelement_destructor(QObject *o) { if (QQmlData *d = QQmlData::get(o)) { if (d->ownContext) { - for (QQmlContextData *lc = d->ownContext->linkedContext; lc; lc = lc->linkedContext) + for (QQmlContextData *lc = d->ownContext->linkedContext; lc; lc = lc->linkedContext) { lc->invalidate(); + if (lc->contextObject == o) + lc->contextObject = nullptr; + } d->ownContext->invalidate(); if (d->ownContext->contextObject == o) d->ownContext->contextObject = nullptr; - d->ownContext = 0; - d->context = 0; + d->ownContext = nullptr; + d->context = nullptr; } // Mark this object as in the process of deletion to @@ -744,14 +750,19 @@ QQmlData::QQmlData() : ownedByQml1(false), ownMemory(true), indestructible(true), explicitIndestructibleSet(false), hasTaintedV4Object(false), isQueuedForDeletion(false), rootObjectInCreation(false), hasInterceptorMetaObject(false), hasVMEMetaObject(false), parentFrozen(false), - bindingBitsSize(MaxInlineBits), bindingBitsValue(0), notifyList(0), - bindings(0), signalHandlers(0), nextContextObject(0), prevContextObject(0), - lineNumber(0), columnNumber(0), jsEngineId(0), compilationUnit(0), - propertyCache(0), guards(0), extendedData(0) + bindingBitsArraySize(InlineBindingArraySize), notifyList(nullptr), + bindings(nullptr), signalHandlers(nullptr), nextContextObject(nullptr), prevContextObject(nullptr), + lineNumber(0), columnNumber(0), jsEngineId(0), + propertyCache(nullptr), guards(nullptr), extendedData(nullptr) { + memset(bindingBitsValue, 0, sizeof(bindingBitsValue)); init(); } +QQmlData::~QQmlData() +{ +} + void QQmlData::destroyed(QAbstractDeclarativeData *d, QObject *o) { QQmlData *ddata = static_cast<QQmlData *>(d); @@ -815,7 +826,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in void **args = (void **) malloc((parameterTypes.count() + 1) *sizeof(void *)); types[0] = 0; // return type - args[0] = 0; // return value + args[0] = nullptr; // return value for (int ii = 0; ii < parameterTypes.count(); ++ii) { const QByteArray &typeName = parameterTypes.at(ii); @@ -836,7 +847,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in args[ii + 1] = QMetaType::create(types[ii + 1], a[ii + 1]); } - QMetaCallEvent *ev = new QMetaCallEvent(m.methodIndex(), 0, 0, object, index, + QMetaCallEvent *ev = new QMetaCallEvent(m.methodIndex(), 0, nullptr, object, index, parameterTypes.count() + 1, types, args); QQmlThreadNotifierProxyObject *mpo = new QQmlThreadNotifierProxyObject; @@ -897,8 +908,10 @@ void QQmlData::setQueuedForDeletion(QObject *object) if (ddata->ownContext) { Q_ASSERT(ddata->ownContext == ddata->context); ddata->context->emitDestruction(); - ddata->ownContext = 0; - ddata->context = 0; + if (ddata->ownContext->contextObject == object) + ddata->ownContext->contextObject = nullptr; + ddata->ownContext = nullptr; + ddata->context = nullptr; } ddata->isQueuedForDeletion = true; } @@ -921,6 +934,14 @@ void QQmlData::flushPendingBindingImpl(QQmlPropertyIndex index) QQmlPropertyData::DontRemoveBinding); } +QQmlData::DeferredData::DeferredData() +{ +} + +QQmlData::DeferredData::~DeferredData() +{ +} + bool QQmlEnginePrivate::baseModulesUninitialized = true; void QQmlEnginePrivate::init() { @@ -1041,7 +1062,7 @@ QQmlEngine::~QQmlEngine() currType.singletonInstanceInfo()->destroy(this); delete d->rootContext; - d->rootContext = 0; + d->rootContext = nullptr; } /*! \fn void QQmlEngine::quit() @@ -1154,7 +1175,7 @@ void QQmlEnginePrivate::registerFinalizeCallback(QObject *obj, int index) if (activeObjectCreator) { activeObjectCreator->finalizeCallbacks()->append(qMakePair(QPointer<QObject>(obj), index)); } else { - void *args[] = { 0 }; + void *args[] = { nullptr }; QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, index, args); } } @@ -1371,13 +1392,13 @@ void QQmlEngine::retranslate() QQmlContext *QQmlEngine::contextForObject(const QObject *object) { if(!object) - return 0; + return nullptr; QQmlData *data = QQmlData::get(object); if (data && data->outerContext) return data->outerContext->asQQmlContext(); - return 0; + return nullptr; } /*! @@ -1525,7 +1546,7 @@ QQmlEngine *qmlEngine(const QObject *obj) { QQmlData *data = QQmlData::get(obj, false); if (!data || !data->context) - return 0; + return nullptr; return data->context->engine; } @@ -1533,7 +1554,7 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre { QQmlData *data = QQmlData::get(object, create); if (!data) - return 0; // Attached properties are only on objects created by QML, unless explicitly requested (create==true) + return nullptr; // Attached properties are only on objects created by QML, unless explicitly requested (create==true) QObject *rv = data->hasExtendedData()?data->attachedProperties()->value(id):0; if (rv || !create) @@ -1542,7 +1563,7 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre QQmlEnginePrivate *engine = QQmlEnginePrivate::get(data->context); QQmlAttachedPropertiesFunc pf = QQmlMetaType::attachedPropertiesFuncById(engine, id); if (!pf) - return 0; + return nullptr; rv = pf(const_cast<QObject *>(object)); @@ -1556,12 +1577,12 @@ QObject *qmlAttachedPropertiesObject(int *idCache, const QObject *object, const QMetaObject *attachedMetaObject, bool create) { if (*idCache == -1) { - QQmlEngine *engine = object ? qmlEngine(object) : 0; - *idCache = QQmlMetaType::attachedPropertiesFuncId(engine ? QQmlEnginePrivate::get(engine) : 0, attachedMetaObject); + QQmlEngine *engine = object ? qmlEngine(object) : nullptr; + *idCache = QQmlMetaType::attachedPropertiesFuncId(engine ? QQmlEnginePrivate::get(engine) : nullptr, attachedMetaObject); } if (*idCache == -1 || !object) - return 0; + return nullptr; return qmlAttachedPropertiesObjectById(*idCache, object, create); } @@ -1621,7 +1642,7 @@ void QQmlData::NotifyList::layout(QQmlNotifierEndpoint *endpoint) { // Add a temporary sentinel at beginning of list. This will be overwritten // when the end point is inserted into the notifies further down. - endpoint->prev = 0; + endpoint->prev = nullptr; while (endpoint->next) { Q_ASSERT(reinterpret_cast<QQmlNotifierEndpoint *>(endpoint->next->prev) == endpoint); @@ -1667,16 +1688,41 @@ void QQmlData::NotifyList::layout() } maximumTodoIndex = 0; - todo = 0; + todo = nullptr; +} + +void QQmlData::deferData(int objectIndex, QV4::CompiledData::CompilationUnit *compilationUnit, QQmlContextData *context) +{ + QQmlData::DeferredData *deferData = new QQmlData::DeferredData; + deferData->deferredIdx = objectIndex; + deferData->compilationUnit = compilationUnit; + deferData->context = context; + + const QV4::CompiledData::Object *compiledObject = compilationUnit->objectAt(objectIndex); + const QV4::CompiledData::BindingPropertyData &propertyData = compilationUnit->bindingPropertyDataPerObject.at(objectIndex); + + const QV4::CompiledData::Binding *binding = compiledObject->bindingTable(); + for (quint32 i = 0; i < compiledObject->nBindings; ++i, ++binding) { + const QQmlPropertyData *property = propertyData.at(i); + if (property && binding->flags & QV4::CompiledData::Binding::IsDeferredBinding) + deferData->bindings.insert(property->coreIndex(), binding); + } + + deferredData.append(deferData); } void QQmlData::releaseDeferredData() { - for (DeferredData *deferData : qAsConst(deferredData)) { - deferData->compilationUnit->release(); - delete deferData; + auto it = deferredData.begin(); + while (it != deferredData.end()) { + DeferredData *deferData = *it; + if (deferData->bindings.isEmpty()) { + delete deferData; + it = deferredData.erase(it); + } else { + ++it; + } } - deferredData.clear(); } void QQmlData::addNotify(int index, QQmlNotifierEndpoint *endpoint) @@ -1686,8 +1732,8 @@ void QQmlData::addNotify(int index, QQmlNotifierEndpoint *endpoint) notifyList->connectionMask = 0; notifyList->maximumTodoIndex = 0; notifyList->notifiesSize = 0; - notifyList->todo = 0; - notifyList->notifies = 0; + notifyList->todo = nullptr; + notifyList->notifies = nullptr; } Q_ASSERT(!endpoint->isConnected()); @@ -1723,7 +1769,7 @@ void QQmlData::disconnectNotifiers() } free(notifyList->notifies); free(notifyList); - notifyList = 0; + notifyList = nullptr; } } @@ -1748,12 +1794,10 @@ void QQmlData::destroyed(QObject *object) if (bindings && !bindings->ref.deref()) delete bindings; - if (compilationUnit) { - compilationUnit->release(); - compilationUnit = 0; - } + compilationUnit = nullptr; - releaseDeferredData(); + qDeleteAll(deferredData); + deferredData.clear(); QQmlBoundSignal *signalHandler = signalHandlers; while (signalHandler) { @@ -1787,23 +1831,23 @@ void QQmlData::destroyed(QObject *object) } QQmlBoundSignal *next = signalHandler->m_nextSignal; - signalHandler->m_prevSignal = 0; - signalHandler->m_nextSignal = 0; + signalHandler->m_prevSignal = nullptr; + signalHandler->m_nextSignal = nullptr; delete signalHandler; signalHandler = next; } - if (bindingBitsSize > MaxInlineBits) + if (bindingBitsArraySize > InlineBindingArraySize) free(bindingBits); if (propertyCache) propertyCache->release(); - ownContext = 0; + ownContext = nullptr; while (guards) { QQmlGuard<QObject> *guard = static_cast<QQmlGuard<QObject> *>(guards); - *guard = (QObject *)0; + *guard = (QObject *)nullptr; guard->objectDestroyed(object); } @@ -1842,47 +1886,35 @@ void QQmlData::parentChanged(QObject *object, QObject *parent) static void QQmlData_setBit(QQmlData *data, QObject *obj, int bit) { - if (Q_UNLIKELY(data->bindingBitsSize <= bit)) { + uint offset = QQmlData::offsetForBit(bit); + BindingBitsType *bits = (data->bindingBitsArraySize == InlineBindingArraySize) ? data->bindingBitsValue : data->bindingBits; + if (Q_UNLIKELY(data->bindingBitsArraySize <= offset)) { int props = QQmlMetaObject(obj).propertyCount(); Q_ASSERT(bit < 2 * props); - int arraySize = (2 * props + MaxInlineBits - 1) / MaxInlineBits; - Q_ASSERT(arraySize > 1); - - // special handling for 32 here is to make sure we wipe the first byte - // when going from bindingBitsValue to bindingBits, and preserve the old - // set bits so we can restore them after the allocation - int oldArraySize = data->bindingBitsSize > MaxInlineBits ? data->bindingBitsSize / MaxInlineBits : 0; - quintptr oldValue = data->bindingBitsSize == MaxInlineBits ? data->bindingBitsValue : 0; + uint arraySize = (2 * static_cast<uint>(props) + BitsPerType - 1) / BitsPerType; + Q_ASSERT(arraySize > InlineBindingArraySize && arraySize > data->bindingBitsArraySize); - data->bindingBits = static_cast<BindingBitsType *>(realloc((data->bindingBitsSize == MaxInlineBits) ? 0 : data->bindingBits, - arraySize * sizeof(BindingBitsType))); + BindingBitsType *newBits = static_cast<BindingBitsType *>(malloc(arraySize*sizeof(BindingBitsType))); + memcpy(newBits, bits, data->bindingBitsArraySize * sizeof(BindingBitsType)); + memset(newBits + data->bindingBitsArraySize, 0, sizeof(BindingBitsType) * (arraySize - data->bindingBitsArraySize)); - memset(data->bindingBits + oldArraySize, - 0x00, - sizeof(BindingBitsType) * (arraySize - oldArraySize)); - - data->bindingBitsSize = arraySize * MaxInlineBits; - - // reinstate bindingBitsValue after we dropped it - if (oldValue) { - memcpy(data->bindingBits, &oldValue, sizeof(oldValue)); - } + if (data->bindingBitsArraySize > InlineBindingArraySize) + free(bits); + data->bindingBits = newBits; + bits = newBits; + data->bindingBitsArraySize = arraySize; } - - if (data->bindingBitsSize == MaxInlineBits) - data->bindingBitsValue |= BindingBitsType(1) << bit; - else - data->bindingBits[bit / MaxInlineBits] |= (BindingBitsType(1) << (bit % MaxInlineBits)); + Q_ASSERT(offset < data->bindingBitsArraySize); + bits[offset] |= QQmlData::bitFlagForBit(bit); } static void QQmlData_clearBit(QQmlData *data, int bit) { - if (data->bindingBitsSize > bit) { - if (data->bindingBitsSize == MaxInlineBits) - data->bindingBitsValue &= ~(BindingBitsType(1) << (bit % MaxInlineBits)); - else - data->bindingBits[bit / MaxInlineBits] &= ~(BindingBitsType(1) << (bit % MaxInlineBits)); + uint offset = QQmlData::offsetForBit(bit); + if (data->bindingBitsArraySize > offset) { + BindingBitsType *bits = (data->bindingBitsArraySize == InlineBindingArraySize) ? data->bindingBitsValue : data->bindingBits; + bits[offset] &= ~QQmlData::bitFlagForBit(bit); } } @@ -1953,23 +1985,23 @@ static void dumpwarning(const QQmlError &error) switch (error.messageType()) { case QtDebugMsg: QMessageLogger(error.url().toString().toLatin1().constData(), - error.line(), 0).debug().nospace() + error.line(), nullptr).debug().nospace() << qPrintable(error.toString()); break; case QtInfoMsg: QMessageLogger(error.url().toString().toLatin1().constData(), - error.line(), 0).info().nospace() + error.line(), nullptr).info().nospace() << qPrintable(error.toString()); break; case QtWarningMsg: case QtFatalMsg: // fatal does not support streaming, and furthermore, is actually fatal. Probably not desirable for QML. QMessageLogger(error.url().toString().toLatin1().constData(), - error.line(), 0).warning().nospace() + error.line(), nullptr).warning().nospace() << qPrintable(error.toString()); break; case QtCriticalMsg: QMessageLogger(error.url().toString().toLatin1().constData(), - error.line(), 0).critical().nospace() + error.line(), nullptr).critical().nospace() << qPrintable(error.toString()); break; } @@ -2048,7 +2080,7 @@ void QQmlEnginePrivate::cleanupScarceResources() // note that the actual SRD is owned by the JS engine, // so we cannot delete the SRD; but we can free the // memory used by the variant in the SRD. - QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine()); + QV4::ExecutionEngine *engine = v4engine(); while (QV4::ExecutionEngine::ScarceResourceData *sr = engine->scarceResources.first()) { sr->data = QVariant(); engine->scarceResources.remove(sr); @@ -2306,11 +2338,11 @@ QQmlPropertyCache *QQmlEnginePrivate::propertyCacheForType(int t) } else { QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); - return type.isValid() ? cache(type.metaObject()) : 0; + return type.isValid() ? cache(type.metaObject()) : nullptr; } } -QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t) +QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t, int minorVersion) { Locker locker(this); auto iter = m_compositeTypes.constFind(t); @@ -2319,7 +2351,11 @@ QQmlPropertyCache *QQmlEnginePrivate::rawPropertyCacheForType(int t) } else { QQmlType type = QQmlMetaType::qmlType(t); locker.unlock(); - return type.isValid() ? cache(type.baseMetaObject()) : 0; + + if (minorVersion >= 0) + return type.isValid() ? cache(type, minorVersion) : nullptr; + else + return type.isValid() ? cache(type.baseMetaObject()) : nullptr; } } diff --git a/src/qml/qml/qqmlengine.h b/src/qml/qml/qqmlengine.h index 937920e191..73ad2754c8 100644 --- a/src/qml/qml/qqmlengine.h +++ b/src/qml/qml/qqmlengine.h @@ -97,7 +97,7 @@ class Q_QML_EXPORT QQmlEngine : public QJSEngine Q_OBJECT public: explicit QQmlEngine(QObject *p = nullptr); - virtual ~QQmlEngine(); + ~QQmlEngine() override; QQmlContext *rootContext() const; diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h index 791660cac7..d6110c6699 100644 --- a/src/qml/qml/qqmlengine_p.h +++ b/src/qml/qml/qqmlengine_p.h @@ -122,7 +122,7 @@ class Q_QML_PRIVATE_EXPORT QQmlEnginePrivate : public QJSEnginePrivate Q_DECLARE_PUBLIC(QQmlEngine) public: QQmlEnginePrivate(QQmlEngine *); - ~QQmlEnginePrivate(); + ~QQmlEnginePrivate() override; void init(); // No mutex protecting baseModulesUninitialized, because use outside QQmlEngine @@ -150,8 +150,8 @@ public: QQmlDelayedError *erroredBindings; int inProgressCreations; - QV8Engine *v8engine() const { return q_func()->handle(); } - QV4::ExecutionEngine *v4engine() const { return QV8Engine::getV4(q_func()->handle()); } + QV8Engine *v8engine() const { return q_func()->handle()->v8Engine; } + QV4::ExecutionEngine *v4engine() const { return q_func()->handle(); } QQuickWorkerScriptEngine *getWorkerScriptEngine(); QQuickWorkerScriptEngine *workerScriptEngine; @@ -213,14 +213,14 @@ public: // These methods may be called from the loader thread bool isQObject(int); - QObject *toQObject(const QVariant &, bool *ok = 0) const; + QObject *toQObject(const QVariant &, bool *ok = nullptr) const; QQmlMetaType::TypeCategory typeCategory(int) const; bool isList(int) const; int listType(int) const; QQmlMetaObject rawMetaObjectForType(int) const; QQmlMetaObject metaObjectForType(int) const; QQmlPropertyCache *propertyCacheForType(int); - QQmlPropertyCache *rawPropertyCacheForType(int); + QQmlPropertyCache *rawPropertyCacheForType(int, int minorVersion = -1); void registerInternalCompositeType(QV4::CompiledData::CompilationUnit *compilationUnit); void unregisterInternalCompositeType(QV4::CompiledData::CompilationUnit *compilationUnit); @@ -265,7 +265,7 @@ private: static bool s_designerMode; // These members is protected by the full QQmlEnginePrivate::mutex mutex - struct Deletable { Deletable():next(0) {} virtual ~Deletable() {} Deletable *next; }; + struct Deletable { Deletable():next(nullptr) {} virtual ~Deletable() {} Deletable *next; }; QFieldList<Deletable, &Deletable::next> toDeleteInEngineThread; void doDeleteInEngineThread(); @@ -295,7 +295,7 @@ inline void QQmlEnginePrivate::dereferenceScarceResources() // expression must have completed. We can safely release the // scarce resources. if (Q_LIKELY(scarceResourcesRefCount == 0)) { - QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine()); + QV4::ExecutionEngine *engine = v4engine(); if (Q_UNLIKELY(!engine->scarceResources.isEmpty())) { cleanupScarceResources(); } @@ -341,7 +341,7 @@ void QQmlEnginePrivate::deleteInEngineThread(T *value) } else { struct I : public Deletable { I(T *value) : value(value) {} - ~I() { delete value; } + ~I() override { delete value; } T *value; }; I *i = new I(value); @@ -385,14 +385,14 @@ QV8Engine *QQmlEnginePrivate::getV8Engine(QQmlEngine *e) { Q_ASSERT(e); - return e->d_func()->v8engine(); + return e->handle()->v8Engine; } QV4::ExecutionEngine *QQmlEnginePrivate::getV4Engine(QQmlEngine *e) { Q_ASSERT(e); - return e->d_func()->v4engine(); + return e->handle(); } QQmlEnginePrivate *QQmlEnginePrivate::get(QQmlEngine *e) @@ -411,12 +411,12 @@ const QQmlEnginePrivate *QQmlEnginePrivate::get(const QQmlEngine *e) QQmlEnginePrivate *QQmlEnginePrivate::get(QQmlContext *c) { - return (c && c->engine()) ? QQmlEnginePrivate::get(c->engine()) : 0; + return (c && c->engine()) ? QQmlEnginePrivate::get(c->engine()) : nullptr; } QQmlEnginePrivate *QQmlEnginePrivate::get(QQmlContextData *c) { - return (c && c->engine) ? QQmlEnginePrivate::get(c->engine) : 0; + return (c && c->engine) ? QQmlEnginePrivate::get(c->engine) : nullptr; } QQmlEngine *QQmlEnginePrivate::get(QQmlEnginePrivate *p) @@ -428,11 +428,9 @@ QQmlEngine *QQmlEnginePrivate::get(QQmlEnginePrivate *p) QQmlEnginePrivate *QQmlEnginePrivate::get(QV4::ExecutionEngine *e) { - if (!e->v8Engine) - return 0; - QQmlEngine *qmlEngine = e->v8Engine->engine(); + QQmlEngine *qmlEngine = e->qmlEngine(); if (!qmlEngine) - return 0; + return nullptr; return get(qmlEngine); } diff --git a/src/qml/qml/qqmlerror.cpp b/src/qml/qml/qqmlerror.cpp index 64f008cd32..fc5b186b29 100644 --- a/src/qml/qml/qqmlerror.cpp +++ b/src/qml/qml/qqmlerror.cpp @@ -99,7 +99,7 @@ QQmlErrorPrivate::QQmlErrorPrivate() Creates an empty error object. */ QQmlError::QQmlError() -: d(0) +: d(nullptr) { } @@ -107,7 +107,7 @@ QQmlError::QQmlError() Creates a copy of \a other. */ QQmlError::QQmlError(const QQmlError &other) -: d(0) +: d(nullptr) { *this = other; } @@ -119,7 +119,7 @@ QQmlError &QQmlError::operator=(const QQmlError &other) { if (!other.d) { delete d; - d = 0; + d = nullptr; } else { if (!d) d = new QQmlErrorPrivate; @@ -138,7 +138,7 @@ QQmlError &QQmlError::operator=(const QQmlError &other) */ QQmlError::~QQmlError() { - delete d; d = 0; + delete d; d = nullptr; } /*! @@ -146,7 +146,7 @@ QQmlError::~QQmlError() */ bool QQmlError::isValid() const { - return d != 0; + return d != nullptr; } /*! @@ -239,7 +239,7 @@ QObject *QQmlError::object() const { if (d) return d->object; - return 0; + return nullptr; } /*! @@ -268,7 +268,7 @@ QtMsgType QQmlError::messageType() const \since 5.9 Sets the \a messageType for this message. The message type determines which - QDebug handlers are responsible for recieving the message. + QDebug handlers are responsible for receiving the message. */ void QQmlError::setMessageType(QtMsgType messageType) { diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index 35dbaccbbe..59cc9bb09f 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -74,7 +74,7 @@ void QQmlExpressionPrivate::init(QQmlContextData *ctxt, const QString &expr, QOb void QQmlExpressionPrivate::init(QQmlContextData *ctxt, QV4::Function *runtimeFunction, QObject *me) { expressionFunctionValid = true; - QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine); + QV4::ExecutionEngine *engine = ctxt->engine->handle(); QV4::Scope scope(engine); QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(engine->rootContext(), ctxt, me)); setupFunction(qmlContext, runtimeFunction); @@ -121,7 +121,7 @@ void QQmlExpressionPrivate::init(QQmlContextData *ctxt, QV4::Function *runtimeFu null expression object and its value will always be an invalid QVariant. */ QQmlExpression::QQmlExpression() -: QObject(*new QQmlExpressionPrivate, 0) +: QObject(*new QQmlExpressionPrivate, nullptr) { } @@ -147,7 +147,7 @@ QQmlExpression::QQmlExpression(const QQmlScriptString &script, QQmlContext *ctxt QQmlContextData *evalCtxtData = QQmlContextData::get(ctxt ? ctxt : scriptPrivate->context); QObject *scopeObject = scope ? scope : scriptPrivate->scope; - QV4::Function *runtimeFunction = 0; + QV4::Function *runtimeFunction = nullptr; if (scriptPrivate->context) { QQmlContextData *ctxtdata = QQmlContextData::get(scriptPrivate->context); @@ -191,7 +191,7 @@ QQmlExpression::QQmlExpression(QQmlContext *ctxt, */ QQmlExpression::QQmlExpression(QQmlContextData *ctxt, QObject *scope, const QString &expression) -: QObject(*new QQmlExpressionPrivate, 0) +: QObject(*new QQmlExpressionPrivate, nullptr) { Q_D(QQmlExpression); d->init(ctxt, expression, scope); @@ -211,7 +211,7 @@ QQmlExpression::~QQmlExpression() QQmlEngine *QQmlExpression::engine() const { Q_D(const QQmlExpression); - return d->context()?d->context()->engine:0; + return d->context()?d->context()->engine:nullptr; } /*! @@ -222,7 +222,7 @@ QQmlContext *QQmlExpression::context() const { Q_D(const QQmlExpression); QQmlContextData *data = d->context(); - return data?data->asQQmlContext():0; + return data?data->asQQmlContext():nullptr; } /*! @@ -266,13 +266,14 @@ QVariant QQmlExpressionPrivate::value(bool *isUndefined) return QVariant(); } - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(q->engine()); + QQmlEngine *engine = q->engine(); + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); QVariant rv; ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. { - QV4::Scope scope(QV8Engine::getV4(ep->v8engine())); + QV4::Scope scope(engine->handle()); QV4::ScopedValue result(scope, v4value(isUndefined)); if (!hasError()) rv = scope.engine->toVariant(result, -1); diff --git a/src/qml/qml/qqmlexpression.h b/src/qml/qml/qqmlexpression.h index e9c8770e92..0eceeb12e1 100644 --- a/src/qml/qml/qqmlexpression.h +++ b/src/qml/qml/qqmlexpression.h @@ -62,7 +62,7 @@ public: QQmlExpression(); QQmlExpression(QQmlContext *, QObject *, const QString &, QObject * = nullptr); explicit QQmlExpression(const QQmlScriptString &, QQmlContext * = nullptr, QObject * = nullptr, QObject * = nullptr); - virtual ~QQmlExpression(); + ~QQmlExpression() override; QQmlEngine *engine() const; QQmlContext *context() const; diff --git a/src/qml/qml/qqmlexpression_p.h b/src/qml/qml/qqmlexpression_p.h index a94ca0fc2d..da10b31b2c 100644 --- a/src/qml/qml/qqmlexpression_p.h +++ b/src/qml/qml/qqmlexpression_p.h @@ -68,14 +68,14 @@ class QQmlExpressionPrivate : public QObjectPrivate, Q_DECLARE_PUBLIC(QQmlExpression) public: QQmlExpressionPrivate(); - ~QQmlExpressionPrivate(); + ~QQmlExpressionPrivate() override; void init(QQmlContextData *, const QString &, QObject *); void init(QQmlContextData *, QV4::Function *runtimeFunction, QObject *); - QVariant value(bool *isUndefined = 0); + QVariant value(bool *isUndefined = nullptr); - QV4::ReturnedValue v4value(bool *isUndefined = 0); + QV4::ReturnedValue v4value(bool *isUndefined = nullptr); static inline QQmlExpressionPrivate *get(QQmlExpression *expr); static inline QQmlExpression *get(QQmlExpressionPrivate *expr); diff --git a/src/qml/qml/qqmlextensioninterface.h b/src/qml/qml/qqmlextensioninterface.h index 62b9b26569..c2d20ef0a3 100644 --- a/src/qml/qml/qqmlextensioninterface.h +++ b/src/qml/qml/qqmlextensioninterface.h @@ -58,7 +58,7 @@ public: class Q_QML_EXPORT QQmlExtensionInterface : public QQmlTypesExtensionInterface { public: - virtual ~QQmlExtensionInterface() {} + ~QQmlExtensionInterface() override {} virtual void initializeEngine(QQmlEngine *engine, const char *uri) = 0; }; diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp index b0e6a24616..818ff7c34f 100644 --- a/src/qml/qml/qqmlextensionplugin.cpp +++ b/src/qml/qml/qqmlextensionplugin.cpp @@ -121,7 +121,9 @@ void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri) \class QQmlExtensionInterface \internal \inmodule QtQml +*/ +/*! \class QQmlTypesExtensionInterface \internal \inmodule QtQml diff --git a/src/qml/qml/qqmlextensionplugin.h b/src/qml/qml/qqmlextensionplugin.h index 84a46fb93e..55e9b89dae 100644 --- a/src/qml/qml/qqmlextensionplugin.h +++ b/src/qml/qml/qqmlextensionplugin.h @@ -59,7 +59,7 @@ class Q_QML_EXPORT QQmlExtensionPlugin Q_INTERFACES(QQmlTypesExtensionInterface) public: explicit QQmlExtensionPlugin(QObject *parent = nullptr); - ~QQmlExtensionPlugin(); + ~QQmlExtensionPlugin() override; QUrl baseUrl() const; diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp index 93c3e8e00c..99031e1e74 100644 --- a/src/qml/qml/qqmlfile.cpp +++ b/src/qml/qml/qqmlfile.cpp @@ -131,7 +131,7 @@ int QQmlFileNetworkReply::replyFinishedIndex = -1; int QQmlFileNetworkReply::replyDownloadProgressIndex = -1; QQmlFileNetworkReply::QQmlFileNetworkReply(QQmlEngine *e, QQmlFilePrivate *p, const QUrl &url) -: m_engine(e), m_p(p), m_redirectCount(0), m_reply(0) +: m_engine(e), m_p(p), m_redirectCount(0), m_reply(nullptr) { if (finishedIndex == -1) { finishedIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::finished).methodIndex(); @@ -194,9 +194,9 @@ void QQmlFileNetworkReply::networkFinished() } m_reply->deleteLater(); - m_reply = 0; + m_reply = nullptr; - m_p->reply = 0; + m_p->reply = nullptr; emit finished(); delete this; } @@ -210,7 +210,7 @@ void QQmlFileNetworkReply::networkDownloadProgress(qint64 a, qint64 b) QQmlFilePrivate::QQmlFilePrivate() : error(None) #if QT_CONFIG(qml_network) -, reply(0) +, reply(nullptr) #endif { } @@ -237,7 +237,7 @@ QQmlFile::~QQmlFile() delete d->reply; #endif delete d; - d = 0; + d = nullptr; } bool QQmlFile::isNull() const diff --git a/src/qml/qml/qqmlfileselector.cpp b/src/qml/qml/qqmlfileselector.cpp index be6216d3ff..8666144096 100644 --- a/src/qml/qml/qqmlfileselector.cpp +++ b/src/qml/qml/qqmlfileselector.cpp @@ -115,8 +115,8 @@ QQmlFileSelector::~QQmlFileSelector() { Q_D(QQmlFileSelector); if (d->engine && QQmlFileSelector::get(d->engine) == this) { - d->engine->setUrlInterceptor(0); - d->engine = 0; + d->engine->setUrlInterceptor(nullptr); + d->engine = nullptr; } interceptorInstances()->remove(d->myInstance.data()); } @@ -200,7 +200,7 @@ QQmlFileSelector* QQmlFileSelector::get(QQmlEngine* engine) QQmlAbstractUrlInterceptor* current = engine->urlInterceptor(); if (current && interceptorInstances()->contains(current)) return interceptorInstances()->value(current); - return 0; + return nullptr; } /*! diff --git a/src/qml/qml/qqmlfileselector.h b/src/qml/qml/qqmlfileselector.h index 4eaf92c918..9b70e3936d 100644 --- a/src/qml/qml/qqmlfileselector.h +++ b/src/qml/qml/qqmlfileselector.h @@ -55,7 +55,7 @@ class Q_QML_EXPORT QQmlFileSelector : public QObject Q_DECLARE_PRIVATE(QQmlFileSelector) public: explicit QQmlFileSelector(QQmlEngine *engine, QObject *parent = nullptr); - ~QQmlFileSelector(); + ~QQmlFileSelector() override; QFileSelector *selector() const Q_DECL_NOTHROW; void setSelector(QFileSelector *selector); void setExtraSelectors(QStringList &strings); // TODO Qt6: remove diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp index 6418812bae..1d60c518c4 100644 --- a/src/qml/qml/qqmlglobal.cpp +++ b/src/qml/qml/qqmlglobal.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE QQmlValueTypeProvider::QQmlValueTypeProvider() - : next(0) + : next(nullptr) { } @@ -65,7 +65,7 @@ const QMetaObject *QQmlValueTypeProvider::metaObjectForMetaType(int type) return mo; } while ((p = p->next)); - return 0; + return nullptr; } bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst) @@ -218,7 +218,7 @@ bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& return false; } -const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return 0; } +const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return nullptr; } bool QQmlValueTypeProvider::init(int, QVariant&) { return false; } bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; } bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; } @@ -232,11 +232,11 @@ bool QQmlValueTypeProvider::read(const QVariant&, void *, int) { return false; } bool QQmlValueTypeProvider::write(int, const void *, QVariant&) { return false; } Q_GLOBAL_STATIC(QQmlValueTypeProvider, nullValueTypeProvider) -static QQmlValueTypeProvider *valueTypeProvider = 0; +static QQmlValueTypeProvider *valueTypeProvider = nullptr; static QQmlValueTypeProvider **getValueTypeProvider(void) { - if (valueTypeProvider == 0) { + if (valueTypeProvider == nullptr) { valueTypeProvider = nullValueTypeProvider; } @@ -294,7 +294,7 @@ QVariant QQmlColorProvider::lighter(const QVariant &, qreal) { return QVariant() QVariant QQmlColorProvider::darker(const QVariant &, qreal) { return QVariant(); } QVariant QQmlColorProvider::tint(const QVariant &, const QVariant &) { return QVariant(); } -static QQmlColorProvider *colorProvider = 0; +static QQmlColorProvider *colorProvider = nullptr; Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider *newProvider) { @@ -305,7 +305,7 @@ Q_QML_PRIVATE_EXPORT QQmlColorProvider *QQml_setColorProvider(QQmlColorProvider static QQmlColorProvider **getColorProvider(void) { - if (colorProvider == 0) { + if (colorProvider == nullptr) { qWarning() << "Warning: QQml_colorProvider: no color provider has been set!"; static QQmlColorProvider nullColorProvider; colorProvider = &nullColorProvider; @@ -345,7 +345,7 @@ QObject *QQmlGuiProvider::styleHints() QString QQmlGuiProvider::pluginName() const { return QString(); } -static QQmlGuiProvider *guiProvider = 0; +static QQmlGuiProvider *guiProvider = nullptr; Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newProvider) { @@ -356,7 +356,7 @@ Q_QML_PRIVATE_EXPORT QQmlGuiProvider *QQml_setGuiProvider(QQmlGuiProvider *newPr static QQmlGuiProvider **getGuiProvider(void) { - if (guiProvider == 0) { + if (guiProvider == nullptr) { static QQmlGuiProvider nullGuiProvider; //Still provides an application with no GUI support guiProvider = &nullGuiProvider; } diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h index a6c113f5a7..302fdd56c4 100644 --- a/src/qml/qml/qqmlglobal_p.h +++ b/src/qml/qml/qqmlglobal_p.h @@ -193,16 +193,6 @@ do { \ return QObjectPrivate::get(sender)->isSignalConnected(signalIdx); \ } while (0) -struct QQmlGraphics_DerivedObject : public QObject -{ - void setParent_noEvent(QObject *parent) { - bool sce = d_ptr->sendChildEvents; - d_ptr->sendChildEvents = false; - setParent(parent); - d_ptr->sendChildEvents = sce; - } -}; - /*! Returns true if the case of \a fileName is equivalent to the file case of \a fileName on disk, and false otherwise. @@ -230,7 +220,11 @@ bool QQml_isFileCaseCorrect(const QString &fileName, int length = -1); */ inline void QQml_setParent_noEvent(QObject *object, QObject *parent) { - static_cast<QQmlGraphics_DerivedObject *>(object)->setParent_noEvent(parent); + QObjectPrivate *d_ptr = QObjectPrivate::get(object); + bool sce = d_ptr->sendChildEvents; + d_ptr->sendChildEvents = false; + object->setParent(parent); + d_ptr->sendChildEvents = sce; } class Q_QML_PRIVATE_EXPORT QQmlValueTypeProvider @@ -329,7 +323,7 @@ class Q_QML_PRIVATE_EXPORT QQmlApplication : public QObject Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged) Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged) public: - QQmlApplication(QObject* parent=0); + QQmlApplication(QObject* parent=nullptr); QStringList args(); @@ -353,7 +347,7 @@ Q_SIGNALS: void domainChanged(); protected: - QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=0); + QQmlApplication(QQmlApplicationPrivate &dd, QObject* parent=nullptr); private: Q_DISABLE_COPY(QQmlApplication) @@ -374,12 +368,12 @@ public: struct QQmlSourceLocation { - QQmlSourceLocation() : line(0), column(0) {} + QQmlSourceLocation() {} QQmlSourceLocation(const QString &sourceFile, quint16 line, quint16 column) : sourceFile(sourceFile), line(line), column(column) {} QString sourceFile; - quint16 line; - quint16 column; + quint16 line = 0; + quint16 column = 0; }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlguard_p.h b/src/qml/qml/qqmlguard_p.h index 52526276be..808bf4c709 100644 --- a/src/qml/qml/qqmlguard_p.h +++ b/src/qml/qml/qqmlguard_p.h @@ -65,9 +65,9 @@ public: inline QQmlGuardImpl(const QQmlGuardImpl &); inline ~QQmlGuardImpl(); - QObject *o; - QQmlGuardImpl *next; - QQmlGuardImpl **prev; + QObject *o = nullptr; + QQmlGuardImpl *next = nullptr; + QQmlGuardImpl **prev = nullptr; inline void addGuard(); inline void remGuard(); @@ -113,18 +113,17 @@ Q_DECLARE_METATYPE(QQmlGuard<QObject>) QT_BEGIN_NAMESPACE QQmlGuardImpl::QQmlGuardImpl() -: o(0), next(0), prev(0) { } QQmlGuardImpl::QQmlGuardImpl(QObject *g) -: o(g), next(0), prev(0) +: o(g) { if (o) addGuard(); } QQmlGuardImpl::QQmlGuardImpl(const QQmlGuardImpl &g) -: o(g.o), next(0), prev(0) +: o(g.o) { if (o) addGuard(); } @@ -132,7 +131,7 @@ QQmlGuardImpl::QQmlGuardImpl(const QQmlGuardImpl &g) QQmlGuardImpl::~QQmlGuardImpl() { if (prev) remGuard(); - o = 0; + o = nullptr; } void QQmlGuardImpl::addGuard() @@ -155,8 +154,8 @@ void QQmlGuardImpl::remGuard() if (next) next->prev = prev; *prev = next; - next = 0; - prev = 0; + next = nullptr; + prev = nullptr; } template<class T> diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 0fbe934bb9..92cecf9f0d 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -728,7 +728,7 @@ bool QQmlImports::resolveType(QQmlImportNamespace *ns, const QHashedStringRef &t QQmlType *type_return, int *vmaj, int *vmin, QQmlType::RegistrationType registrationType) const { - return ns->resolveType(d->typeLoader, type, vmaj, vmin, type_return, 0, 0, registrationType); + return ns->resolveType(d->typeLoader, type, vmaj, vmin, type_return, nullptr, nullptr, registrationType); } bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type, @@ -803,7 +803,7 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt int major = vmajor ? *vmajor : -1; int minor = vminor ? *vminor : -1; QQmlType returnType = fetchOrCreateTypeForUrl(componentUrl, type, isCompositeSingleton, - 0, major, minor); + nullptr, major, minor); if (type_return) *type_return = returnType; return returnType.isValid(); @@ -831,7 +831,7 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt *typeRecursionDetected = true; } else { QQmlType returnType = fetchOrCreateTypeForUrl( - qmlUrl, type, registrationType == QQmlType::CompositeSingletonType, 0); + qmlUrl, type, registrationType == QQmlType::CompositeSingletonType, nullptr); if (type_return) *type_return = returnType; return returnType.isValid(); @@ -847,7 +847,7 @@ bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor, QQmlType::RegistrationType registrationType, QQmlImport::RecursionRestriction recursionRestriction) { - QQmlImportNamespace *s = 0; + QQmlImportNamespace *s = nullptr; int dot = type.indexOf(Dot); if (dot >= 0) { QHashedStringRef namespaceName(type.constData(), dot); @@ -978,10 +978,10 @@ QQmlImportNamespace *QQmlImportsPrivate::findQualifiedNamespace(const QHashedStr if (prefix == ns->prefix) return ns; } - return 0; + return nullptr; } -/*! +/* Returns the list of possible versioned URI combinations. For example, if \a uri is QtQml.Models, \a vmaj is 2, and \a vmin is 0, this method returns the following: [QtQml.Models.2.0, QtQml.2.0.Models, QtQml.Models.2, QtQml.2.Models, QtQml.Models] @@ -1017,7 +1017,7 @@ static QVector<QStaticPlugin> makePlugins() return plugins; } -/*! +/* Get all static plugins that are QML plugins and has a meta data URI that matches with one of \a versionUris, which is a list of all possible versioned URI combinations - see versionUriList() above. @@ -1059,7 +1059,7 @@ static inline QString msgCannotLoadPlugin(const QString &uri, const QString &why } #endif -/*! +/* Import an extension defined by a qmldir file. \a qmldirFilePath is a raw file path. @@ -1231,10 +1231,12 @@ QString QQmlImportsPrivate::resolvedUri(const QString &dir_arg, QQmlImportDataba stableRelativePath.replace(Backslash, Slash); // remove optional versioning in dot notation from uri - int lastSlash = stableRelativePath.lastIndexOf(Slash); - if (lastSlash >= 0) { - int versionDot = stableRelativePath.indexOf(Dot, lastSlash); - if (versionDot >= 0) + int versionDot = stableRelativePath.lastIndexOf(Dot); + if (versionDot >= 0) { + int nextSlash = stableRelativePath.indexOf(Slash, versionDot); + if (nextSlash >= 0) + stableRelativePath.remove(versionDot, nextSlash - versionDot); + else stableRelativePath = stableRelativePath.left(versionDot); } @@ -1255,7 +1257,7 @@ bool QQmlImportsPrivate::locateQmldir(const QString &uri, int vmaj, int vmin, QQ // Check cache first - QQmlImportDatabase::QmldirCache *cacheHead = 0; + QQmlImportDatabase::QmldirCache *cacheHead = nullptr; { QQmlImportDatabase::QmldirCache **cachePtr = database->qmldirCache.value(uri); if (cachePtr) { @@ -1274,10 +1276,19 @@ bool QQmlImportsPrivate::locateQmldir(const QString &uri, int vmaj, int vmin, QQ QQmlTypeLoader &typeLoader = QQmlEnginePrivate::get(database->engine)->typeLoader; + // Interceptor might redirect remote files to local ones. + QQmlAbstractUrlInterceptor *interceptor = typeLoader.engine()->urlInterceptor(); + QStringList localImportPaths = database->importPathList( + interceptor ? QQmlImportDatabase::LocalOrRemote : QQmlImportDatabase::Local); // Search local import paths for a matching version - QStringList localImportPaths = database->importPathList(QQmlImportDatabase::Local); const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(uri, localImportPaths, vmaj, vmin); - for (const QString &qmldirPath : qmlDirPaths) { + for (QString qmldirPath : qmlDirPaths) { + if (interceptor) { + qmldirPath = QQmlFile::urlToLocalFileOrQrc( + interceptor->intercept(QQmlImports::urlFromLocalFileOrQrcOrUrl(qmldirPath), + QQmlAbstractUrlInterceptor::QmldirFile)); + } + QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath); if (!absoluteFilePath.isEmpty()) { QString url; @@ -1377,7 +1388,7 @@ bool QQmlImportsPrivate::validateQmldirVersion(const QQmlTypeLoaderQmldirContent QQmlImportNamespace *QQmlImportsPrivate::importNamespace(const QString &prefix) const { - QQmlImportNamespace *nameSpace = 0; + QQmlImportNamespace *nameSpace = nullptr; if (prefix.isEmpty()) { nameSpace = &unqualifiedset; @@ -1434,7 +1445,7 @@ bool QQmlImportsPrivate::addLibraryImport(const QString& uri, const QString &pre Q_ASSERT(inserted); if (!incomplete) { - const QQmlTypeLoaderQmldirContent *qmldir = 0; + const QQmlTypeLoaderQmldirContent *qmldir = nullptr; if (!qmldirIdentifier.isEmpty()) { if (!getQmldirContent(qmldirIdentifier, uri, &qmldir, errors)) @@ -1486,6 +1497,10 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix QString qmldirUrl = resolveLocalUrl(base, importUri + (importUri.endsWith(Slash) ? String_qmldir : Slash_qmldir)); + if (QQmlAbstractUrlInterceptor *interceptor = typeLoader->engine()->urlInterceptor()) { + qmldirUrl = interceptor->intercept(QUrl(qmldirUrl), + QQmlAbstractUrlInterceptor::QmldirFile).toString(); + } QString qmldirIdentifier; if (QQmlFile::isLocalFile(qmldirUrl)) { @@ -1538,7 +1553,7 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix if (isImplicitImport) { for (QList<QQmlImportInstance *>::const_iterator it = nameSpace->imports.constBegin(); it != nameSpace->imports.constEnd(); ++it) { - if ((*it)->uri == importUri) { + if ((*it)->url == url) { (*it)->implicitlyImported = true; return true; } @@ -1549,7 +1564,7 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix Q_ASSERT(inserted); if (!incomplete && !qmldirIdentifier.isEmpty()) { - const QQmlTypeLoaderQmldirContent *qmldir = 0; + const QQmlTypeLoaderQmldirContent *qmldir = nullptr; if (!getQmldirContent(qmldirIdentifier, importUri, &qmldir, errors)) return false; @@ -1573,7 +1588,7 @@ bool QQmlImportsPrivate::updateQmldirContent(const QString &uri, const QString & Q_ASSERT(nameSpace); if (QQmlImportInstance *import = nameSpace->findImport(uri)) { - const QQmlTypeLoaderQmldirContent *qmldir = 0; + const QQmlTypeLoaderQmldirContent *qmldir = nullptr; if (!getQmldirContent(qmldirIdentifier, uri, &qmldir, errors)) return false; @@ -1585,8 +1600,8 @@ bool QQmlImportsPrivate::updateQmldirContent(const QString &uri, const QString & if (import->setQmldirContent(qmldirUrl, qmldir, nameSpace, errors)) { if (import->qmlDirComponents.isEmpty() && import->qmlDirScripts.isEmpty()) { - // The implicit import qmldir can be empty - if (uri != QLatin1String(".")) { + // The implicit import qmldir can be empty, and plugins have no extra versions + if (uri != QLatin1String(".") && !QQmlMetaType::isModule(uri, vmaj, vmin)) { QQmlError error; if (QQmlMetaType::isAnyModule(uri)) error.setDescription(QQmlImportDatabase::tr("module \"%1\" version %2.%3 is not installed").arg(uri).arg(vmaj).arg(vmin)); @@ -1714,6 +1729,16 @@ bool QQmlImports::isLocal(const QUrl &url) return !QQmlFile::urlToLocalFileOrQrc(url).isEmpty(); } +QUrl QQmlImports::urlFromLocalFileOrQrcOrUrl(const QString &file) +{ + QUrl url(QLatin1String(file.at(0) == Colon ? "qrc" : "") + file); + + // We don't support single character schemes as those conflict with windows drive letters. + if (url.scheme().length() < 2) + return QUrl::fromLocalFile(file); + return url; +} + void QQmlImports::setDesignerSupportRequired(bool b) { designerSupportRequired = b; @@ -2060,29 +2085,38 @@ bool QQmlImportDatabase::importStaticPlugin(QObject *instance, const QString &ba // Dynamic plugins are differentiated by their filepath. For static plugins we // don't have that information so we use their address as key instead. const QString uniquePluginID = QString::asprintf("%p", instance); - StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); - QMutexLocker lock(&plugins->mutex); + { + StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); + QMutexLocker lock(&plugins->mutex); - // Plugin types are global across all engines and should only be - // registered once. But each engine still needs to be initialized. - bool typesRegistered = plugins->contains(uniquePluginID); - bool engineInitialized = initializedPlugins.contains(uniquePluginID); + // Plugin types are global across all engines and should only be + // registered once. But each engine still needs to be initialized. + bool typesRegistered = plugins->contains(uniquePluginID); - if (typesRegistered) { - Q_ASSERT_X(plugins->value(uniquePluginID).uri == uri, - "QQmlImportDatabase::importStaticPlugin", - "Internal error: Static plugin imported previously with different uri"); - } else { - RegisteredPlugin plugin; - plugin.uri = uri; - plugin.loader = 0; - plugins->insert(uniquePluginID, plugin); + if (typesRegistered) { + Q_ASSERT_X(plugins->value(uniquePluginID).uri == uri, + "QQmlImportDatabase::importStaticPlugin", + "Internal error: Static plugin imported previously with different uri"); + } else { + RegisteredPlugin plugin; + plugin.uri = uri; + plugin.loader = nullptr; + plugins->insert(uniquePluginID, plugin); - if (!registerPluginTypes(instance, basePath, uri, typeNamespace, vmaj, errors)) - return false; + if (!registerPluginTypes(instance, basePath, uri, typeNamespace, vmaj, errors)) + return false; + } + + // Release the lock on plugins early as we're done with the global part. Releasing the lock + // also allows other QML loader threads to acquire the lock while this thread is blocking + // in the initializeEngine call to the gui thread (which in turn may be busy waiting for + // other QML loader threads and thus not process the initializeEngine call). } - if (!engineInitialized) { + // The plugin's per-engine initialization does not need lock protection, as this function is + // only called from the engine specific loader thread and importDynamicPlugin as well as + // importStaticPlugin are the only places of access. + if (!initializedPlugins.contains(uniquePluginID)) { initializedPlugins.insert(uniquePluginID); if (QQmlExtensionInterface *eiface = qobject_cast<QQmlExtensionInterface *>(instance)) { @@ -2104,68 +2138,77 @@ bool QQmlImportDatabase::importDynamicPlugin(const QString &filePath, const QStr QFileInfo fileInfo(filePath); const QString absoluteFilePath = fileInfo.absoluteFilePath(); + QObject *instance = nullptr; bool engineInitialized = initializedPlugins.contains(absoluteFilePath); - StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); - QMutexLocker lock(&plugins->mutex); - bool typesRegistered = plugins->contains(absoluteFilePath); - - if (typesRegistered) { - Q_ASSERT_X(plugins->value(absoluteFilePath).uri == uri, - "QQmlImportDatabase::importDynamicPlugin", - "Internal error: Plugin imported previously with different uri"); - } - - if (!engineInitialized || !typesRegistered) { - if (!QQml_isFileCaseCorrect(absoluteFilePath)) { - if (errors) { - QQmlError error; - error.setDescription(tr("File name case mismatch for \"%1\"").arg(absoluteFilePath)); - errors->prepend(error); - } - return false; + { + StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes(); + QMutexLocker lock(&plugins->mutex); + bool typesRegistered = plugins->contains(absoluteFilePath); + + if (typesRegistered) { + Q_ASSERT_X(plugins->value(absoluteFilePath).uri == uri, + "QQmlImportDatabase::importDynamicPlugin", + "Internal error: Plugin imported previously with different uri"); } - QPluginLoader* loader = 0; - if (!typesRegistered) { - loader = new QPluginLoader(absoluteFilePath); - - if (!loader->load()) { + if (!engineInitialized || !typesRegistered) { + if (!QQml_isFileCaseCorrect(absoluteFilePath)) { if (errors) { QQmlError error; - error.setDescription(loader->errorString()); + error.setDescription(tr("File name case mismatch for \"%1\"").arg(absoluteFilePath)); errors->prepend(error); } - delete loader; return false; } - } else { - loader = plugins->value(absoluteFilePath).loader; - } - QObject *instance = loader->instance(); + QPluginLoader* loader = nullptr; + if (!typesRegistered) { + loader = new QPluginLoader(absoluteFilePath); - if (!typesRegistered) { - RegisteredPlugin plugin; - plugin.uri = uri; - plugin.loader = loader; - plugins->insert(absoluteFilePath, plugin); + if (!loader->load()) { + if (errors) { + QQmlError error; + error.setDescription(loader->errorString()); + errors->prepend(error); + } + delete loader; + return false; + } + } else { + loader = plugins->value(absoluteFilePath).loader; + } - // Continue with shared code path for dynamic and static plugins: - if (!registerPluginTypes(instance, fileInfo.absolutePath(), uri, typeNamespace, vmaj, errors)) - return false; + instance = loader->instance(); + + if (!typesRegistered) { + RegisteredPlugin plugin; + plugin.uri = uri; + plugin.loader = loader; + plugins->insert(absoluteFilePath, plugin); + + // Continue with shared code path for dynamic and static plugins: + if (!registerPluginTypes(instance, fileInfo.absolutePath(), uri, typeNamespace, vmaj, errors)) + return false; + } } - if (!engineInitialized) { - // things on the engine (eg. adding new global objects) have to be done for every - // engine. - // XXX protect against double initialization - initializedPlugins.insert(absoluteFilePath); - - if (QQmlExtensionInterface *eiface = qobject_cast<QQmlExtensionInterface *>(instance)) { - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); - ep->typeLoader.initializeEngine(eiface, uri.toUtf8().constData()); - } - } + // Release the lock on plugins early as we're done with the global part. Releasing the lock + // also allows other QML loader threads to acquire the lock while this thread is blocking + // in the initializeEngine call to the gui thread (which in turn may be busy waiting for + // other QML loader threads and thus not process the initializeEngine call). + } + + + if (!engineInitialized) { + // The plugin's per-engine initialization does not need lock protection, as this function is + // only called from the engine specific loader thread and importDynamicPlugin as well as + // importStaticPlugin are the only places of access. + initializedPlugins.insert(absoluteFilePath); + + if (QQmlExtensionInterface *eiface = qobject_cast<QQmlExtensionInterface *>(instance)) { + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); + ep->typeLoader.initializeEngine(eiface, uri.toUtf8().constData()); + } } return true; diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index a7b65c1048..b70bb5253c 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -92,7 +92,7 @@ struct QQmlImportInstance bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef &type, int *vmajor, int *vminor, QQmlType* type_return, - QString *base = 0, bool *typeRecursionDetected = 0, + QString *base = nullptr, bool *typeRecursionDetected = nullptr, QQmlType::RegistrationType = QQmlType::AnyRegistrationType, QQmlImport::RecursionRestriction recursionRestriction = QQmlImport::PreventRecursion) const; }; @@ -100,7 +100,7 @@ struct QQmlImportInstance class QQmlImportNamespace { public: - QQmlImportNamespace() : nextNamespace(0) {} + QQmlImportNamespace() : nextNamespace(nullptr) {} ~QQmlImportNamespace() { qDeleteAll(imports); } QList<QQmlImportInstance *> imports; @@ -109,7 +109,7 @@ public: bool resolveType(QQmlTypeLoader *typeLoader, const QHashedStringRef& type, int *vmajor, int *vminor, QQmlType* type_return, - QString *base = 0, QList<QQmlError> *errors = 0, + QString *base = nullptr, QList<QQmlError> *errors = nullptr, QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType, QQmlImport::RecursionRestriction recursionRestriction = QQmlImport::PreventRecursion); @@ -137,7 +137,7 @@ public: QQmlType *type_return, int *version_major, int *version_minor, QQmlImportNamespace **ns_return, - QList<QQmlError> *errors = 0, + QList<QQmlError> *errors = nullptr, QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType, QQmlImport::RecursionRestriction recursionRestriction = QQmlImport::PreventRecursion) const; @@ -191,6 +191,7 @@ public: static bool isLocal(const QString &url); static bool isLocal(const QUrl &url); + static QUrl urlFromLocalFileOrQrcOrUrl(const QString &); static void setDesignerSupportRequired(bool b); diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index 6d0e4b915a..4546a4423f 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -110,7 +110,7 @@ void QQmlEngine::setIncubationController(QQmlIncubationController *controller) { Q_D(QQmlEngine); if (d->incubationController) - d->incubationController->d = 0; + d->incubationController->d = nullptr; d->incubationController = controller; if (controller) controller->d = d; } @@ -128,7 +128,7 @@ QQmlIncubationController *QQmlEngine::incubationController() const QQmlIncubatorPrivate::QQmlIncubatorPrivate(QQmlIncubator *q, QQmlIncubator::IncubationMode m) : q(q), status(QQmlIncubator::Null), mode(m), isAsynchronous(false), progress(Execute), - result(0), enginePriv(0), waitingOnMe(0) + result(nullptr), enginePriv(nullptr), waitingOnMe(nullptr) { } @@ -147,16 +147,16 @@ void QQmlIncubatorPrivate::clear() if (controller) controller->incubatingObjectCountChanged(enginePriv->incubatorCount); } - enginePriv = 0; + enginePriv = nullptr; if (!rootContext.isNull()) { - rootContext->incubator = 0; - rootContext = 0; + rootContext->incubator = nullptr; + rootContext = nullptr; } if (nextWaitingFor.isInList()) { Q_ASSERT(waitingOnMe); nextWaitingFor.remove(); - waitingOnMe = 0; + waitingOnMe = nullptr; } // if we're waiting on any incubators then they should be cleared too. @@ -171,7 +171,7 @@ void QQmlIncubatorPrivate::clear() vmeGuard.clear(); if (creator && guardOk) creator->clear(); - creator.reset(0); + creator.reset(nullptr); } /*! @@ -218,15 +218,15 @@ than a static amount like 5 milliseconds - while not disturbing the application. Create a new incubation controller. */ QQmlIncubationController::QQmlIncubationController() -: d(0) +: d(nullptr) { } /*! \internal */ QQmlIncubationController::~QQmlIncubationController() { - if (d) QQmlEnginePrivate::get(d)->setIncubationController(0); - d = 0; + if (d) QQmlEnginePrivate::get(d)->setIncubationController(nullptr); + d = nullptr; } /*! @@ -272,7 +272,7 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) if (!compilationUnit) return; - QML_MEMORY_SCOPE_URL(compilationUnit->url()); + QML_MEMORY_SCOPE_URL(compilationUnit->finalUrl()); QExplicitlySharedDataPointer<QQmlIncubatorPrivate> protectThis(this); @@ -294,8 +294,8 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) if (progress == QQmlIncubatorPrivate::Execute) { enginePriv->referenceScarceResources(); - QObject *tresult = 0; - tresult = creator->create(subComponentToCreate, /*parent*/0, &i); + QObject *tresult = nullptr; + tresult = creator->create(subComponentToCreate, /*parent*/nullptr, &i); if (!tresult) errors = creator->errors; enginePriv->dereferenceScarceResources(); @@ -304,7 +304,7 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) return; result = tresult; - if (errors.isEmpty() && result == 0) + if (errors.isEmpty() && result == nullptr) goto finishIncubate; if (result) { @@ -340,7 +340,7 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) if (watcher.hasRecursed()) return; - QQmlContextData *ctxt = 0; + QQmlContextData *ctxt = nullptr; ctxt = creator->finalize(i); if (ctxt) { rootContext = ctxt; @@ -377,23 +377,6 @@ finishIncubate: } } -void QQmlIncubatorPrivate::cancel(QObject *object, QQmlContext *context) -{ - if (!context) - context = qmlContext(object); - if (!context) - return; - - QQmlContextData *data = QQmlContextData::get(context); - QQmlIncubatorPrivate *p = data->incubator; - if (!p) - return; - - p->vmeGuard.unguard(object); - if (!p->creator.isNull()) - p->creator->cancel(object); -} - /*! Incubate objects for \a msecs, or until there are no more objects to incubate. */ @@ -523,12 +506,12 @@ QQmlIncubator::QQmlIncubator(IncubationMode mode) /*! \internal */ QQmlIncubator::~QQmlIncubator() { - d->q = 0; + d->q = nullptr; if (!d->ref.deref()) { delete d; } - d = 0; + d = nullptr; } /*! @@ -574,18 +557,18 @@ void QQmlIncubator::clear() if (s == Loading) { Q_ASSERT(d->compilationUnit); if (d->result) d->result->deleteLater(); - d->result = 0; + d->result = nullptr; } d->clear(); Q_ASSERT(d->compilationUnit.isNull()); - Q_ASSERT(d->waitingOnMe.data() == 0); + Q_ASSERT(d->waitingOnMe.data() == nullptr); Q_ASSERT(d->waitingFor.isEmpty()); d->errors.clear(); d->progress = QQmlIncubatorPrivate::Execute; - d->result = 0; + d->result = nullptr; if (s == Loading) { Q_ASSERT(enginePriv); @@ -674,7 +657,7 @@ Return the incubated object if the status is Ready, otherwise 0. QObject *QQmlIncubator::object() const { if (status() != Ready) - return 0; + return nullptr; else return d->result; } diff --git a/src/qml/qml/qqmlincubator_p.h b/src/qml/qml/qqmlincubator_p.h index 758e0a29f6..676ba1a29a 100644 --- a/src/qml/qml/qqmlincubator_p.h +++ b/src/qml/qml/qqmlincubator_p.h @@ -102,9 +102,6 @@ public: void forceCompletion(QQmlInstantiationInterrupt &i); void incubate(QQmlInstantiationInterrupt &i); - - // used by Qt Quick Controls 2 - Q_QML_PRIVATE_EXPORT static void cancel(QObject *object, QQmlContext *context = 0); }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlinfo.cpp b/src/qml/qml/qqmlinfo.cpp index dae15e2eca..c8f5ba506f 100644 --- a/src/qml/qml/qqmlinfo.cpp +++ b/src/qml/qml/qqmlinfo.cpp @@ -182,7 +182,7 @@ QQmlInfo::~QQmlInfo() if (0 == --d->ref) { QList<QQmlError> errors = d->errors; - QQmlEngine *engine = 0; + QQmlEngine *engine = nullptr; if (!d->buffer.isEmpty()) { QQmlError error; diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 006611e089..74148e3ca4 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -93,12 +93,12 @@ void QQmlDelayedError::catchJavaScriptException(QV4::ExecutionEngine *engine) QQmlJavaScriptExpression::QQmlJavaScriptExpression() - : m_error(0), - m_context(0), - m_prevExpression(0), - m_nextExpression(0), - m_v4Function(0), - m_sourceLocation(0) + : m_error(nullptr), + m_context(nullptr), + m_prevExpression(nullptr), + m_nextExpression(nullptr), + m_v4Function(nullptr), + m_sourceLocation(nullptr) { } @@ -114,7 +114,7 @@ QQmlJavaScriptExpression::~QQmlJavaScriptExpression() clearPermanentGuards(); clearError(); if (m_scopeObject.isT2()) // notify DeleteWatcher of our deletion. - m_scopeObject.asT2()->_s = 0; + m_scopeObject.asT2()->_s = nullptr; delete m_sourceLocation; } @@ -157,8 +157,8 @@ void QQmlJavaScriptExpression::setContext(QQmlContextData *context) *m_prevExpression = m_nextExpression; if (m_nextExpression) m_nextExpression->m_prevExpression = m_prevExpression; - m_prevExpression = 0; - m_nextExpression = 0; + m_prevExpression = nullptr; + m_nextExpression = nullptr; } m_context = context; @@ -183,7 +183,7 @@ void QQmlJavaScriptExpression::refresh() QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(bool *isUndefined) { - QV4::ExecutionEngine *v4 = QV8Engine::getV4(m_context->engine); + QV4::ExecutionEngine *v4 = m_context->engine->handle(); QV4::Scope scope(v4); QV4::JSCallData jsCall(scope); @@ -211,13 +211,13 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QV4::CallData *callData, b QQmlPropertyCapture capture(m_context->engine, this, &watcher); QQmlPropertyCapture *lastPropertyCapture = ep->propertyCapture; - ep->propertyCapture = notifyOnValueChanged() ? &capture : 0; + ep->propertyCapture = notifyOnValueChanged() ? &capture : nullptr; if (notifyOnValueChanged()) capture.guards.copyAndClearPrepend(activeGuards); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); + QV4::ExecutionEngine *v4 = m_context->engine->handle(); callData->thisObject = v4->globalObject; if (scopeObject()) { QV4::ReturnedValue scope = QV4::QObjectWrapper::wrap(v4, scopeObject()); @@ -253,7 +253,7 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QV4::CallData *callData, b for (int ii = 0; ii < capture.errorString->count(); ++ii) qWarning("%s", qPrintable(capture.errorString->at(ii))); delete capture.errorString; - capture.errorString = 0; + capture.errorString = nullptr; } while (QQmlJavaScriptExpressionGuard *g = capture.guards.takeFirst()) @@ -274,7 +274,7 @@ void QQmlPropertyCapture::captureProperty(QQmlNotifier *n, Duration duration) while (!guards.isEmpty() && !guards.first()->isConnected(n)) guards.takeFirst()->Delete(); - QQmlJavaScriptExpressionGuard *g = 0; + QQmlJavaScriptExpressionGuard *g = nullptr; if (!guards.isEmpty()) { g = guards.takeFirst(); g->cancelNotify(); @@ -323,7 +323,7 @@ void QQmlPropertyCapture::captureProperty(QObject *o, int c, int n, Duration dur while (!guards.isEmpty() && !guards.first()->isConnected(o, n)) guards.takeFirst()->Delete(); - QQmlJavaScriptExpressionGuard *g = 0; + QQmlJavaScriptExpressionGuard *g = nullptr; if (!guards.isEmpty()) { g = guards.takeFirst(); g->cancelNotify(); @@ -414,7 +414,7 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scopeObje QQmlEngine *engine = ctxt->engine; QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); + QV4::ExecutionEngine *v4 = engine->handle(); QV4::Scope scope(v4); QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxt, scopeObject)); @@ -444,7 +444,7 @@ void QQmlJavaScriptExpression::createQmlBinding(QQmlContextData *ctxt, QObject * QQmlEngine *engine = ctxt->engine; QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); + QV4::ExecutionEngine *v4 = engine->handle(); QV4::Scope scope(v4); QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxt, qmlScope)); diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index 1cb6d7bfd1..a028850074 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -62,7 +62,7 @@ struct QQmlSourceLocation; class QQmlDelayedError { public: - inline QQmlDelayedError() : nextError(0), prevError(0) {} + inline QQmlDelayedError() : nextError(nullptr), prevError(nullptr) {} inline ~QQmlDelayedError() { removeError(); } bool addError(QQmlEnginePrivate *); @@ -71,8 +71,8 @@ public: if (!prevError) return; if (nextError) nextError->prevError = prevError; *prevError = nextError; - nextError = 0; - prevError = 0; + nextError = nullptr; + prevError = nullptr; } inline bool isValid() const { return m_error.isValid(); } @@ -117,7 +117,7 @@ public: QQmlSourceLocation sourceLocation() const; void setSourceLocation(const QQmlSourceLocation &location); - bool isValid() const { return context() != 0; } + bool isValid() const { return context() != nullptr; } QQmlContextData *context() const { return m_context; } void setContext(QQmlContextData *context); @@ -193,11 +193,11 @@ class QQmlPropertyCapture { public: QQmlPropertyCapture(QQmlEngine *engine, QQmlJavaScriptExpression *e, QQmlJavaScriptExpression::DeleteWatcher *w) - : engine(engine), expression(e), watcher(w), errorString(0) { } + : engine(engine), expression(e), watcher(w), errorString(nullptr) { } ~QQmlPropertyCapture() { Q_ASSERT(guards.isEmpty()); - Q_ASSERT(errorString == 0); + Q_ASSERT(errorString == nullptr); } enum Duration { @@ -217,7 +217,7 @@ public: }; QQmlJavaScriptExpression::DeleteWatcher::DeleteWatcher(QQmlJavaScriptExpression *e) -: _c(0), _w(0), _s(e) +: _c(nullptr), _w(nullptr), _s(e) { if (e->m_scopeObject.isT1()) { _w = &_s; @@ -231,14 +231,14 @@ QQmlJavaScriptExpression::DeleteWatcher::DeleteWatcher(QQmlJavaScriptExpression QQmlJavaScriptExpression::DeleteWatcher::~DeleteWatcher() { - Q_ASSERT(*_w == 0 || (*_w == _s && _s->m_scopeObject.isT2())); + Q_ASSERT(*_w == nullptr || (*_w == _s && _s->m_scopeObject.isT2())); if (*_w && _s->m_scopeObject.asT2() == this) _s->m_scopeObject = _c; } bool QQmlJavaScriptExpression::DeleteWatcher::wasDeleted() const { - return *_w == 0; + return *_w == nullptr; } bool QQmlJavaScriptExpression::notifyOnValueChanged() const @@ -272,12 +272,12 @@ inline void QQmlJavaScriptExpression::clearError() { if (m_error) delete m_error; - m_error = 0; + m_error = nullptr; } QQmlJavaScriptExpressionGuard::QQmlJavaScriptExpressionGuard(QQmlJavaScriptExpression *e) : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlJavaScriptExpressionGuard), - expression(e), next(0) + expression(e), next(nullptr) { } diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp index 71be2e82a3..ac6e3695fe 100644 --- a/src/qml/qml/qqmllist.cpp +++ b/src/qml/qml/qqmllist.cpp @@ -55,7 +55,7 @@ QQmlListReference QQmlListReferencePrivate::init(const QQmlListProperty<QObject> if (!prop.object) return rv; - QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):0; + QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):nullptr; int listType = p?p->listType(propType):QQmlMetaType::listType(propType); if (listType == -1) return rv; @@ -117,7 +117,7 @@ The \l {Qt Quick 1} version of this class is named QDeclarativeListReference. Constructs an invalid instance. */ QQmlListReference::QQmlListReference() -: d(0) +: d(nullptr) { } @@ -131,17 +131,17 @@ Passing \a engine is required to access some QML created list properties. If in is available, pass it. */ QQmlListReference::QQmlListReference(QObject *object, const char *property, QQmlEngine *engine) -: d(0) +: d(nullptr) { if (!object || !property) return; QQmlPropertyData local; QQmlPropertyData *data = - QQmlPropertyCache::property(engine, object, QLatin1String(property), 0, local); + QQmlPropertyCache::property(engine, object, QLatin1String(property), nullptr, local); if (!data || !data->isQList()) return; - QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):0; + QQmlEnginePrivate *p = engine?QQmlEnginePrivate::get(engine):nullptr; int listType = p?p->listType(data->propType()):QQmlMetaType::listType(data->propType()); if (listType == -1) return; @@ -151,7 +151,7 @@ QQmlListReference::QQmlListReference(QObject *object, const char *property, QQml d->elementType = p ? p->rawMetaObjectForType(listType) : QQmlMetaType::qmlType(listType).baseMetaObject(); d->propertyType = data->propType(); - void *args[] = { &d->property, 0 }; + void *args[] = { &d->property, nullptr }; QMetaObject::metacall(object, QMetaObject::ReadProperty, data->coreIndex(), args); } @@ -191,7 +191,7 @@ Returns the list property's object. Returns 0 if the reference is invalid. QObject *QQmlListReference::object() const { if (isValid()) return d->object; - else return 0; + else return nullptr; } /*! @@ -204,7 +204,7 @@ to a list. const QMetaObject *QQmlListReference::listElementType() const { if (isValid()) return d->elementType.metaObject(); - else return 0; + else return nullptr; } /*! @@ -301,7 +301,7 @@ Returns the list element at \a index, or 0 if the operation failed. */ QObject *QQmlListReference::at(int index) const { - if (!canAt()) return 0; + if (!canAt()) return nullptr; return d->property.at(&d->property, index); } @@ -374,12 +374,12 @@ The \l {Qt Quick 1} version of this class is named QDeclarativeListProperty. */ /*! -\fn QQmlListProperty::QQmlListProperty() +\fn template<typename T> QQmlListProperty<T>::QQmlListProperty() \internal */ /*! -\fn QQmlListProperty::QQmlListProperty(QObject *object, QList<T *> &list) +\fn template<typename T> QQmlListProperty<T>::QQmlListProperty(QObject *object, QList<T *> &list) Convenience constructor for making a QQmlListProperty value from an existing QList \a list. The \a list reference must remain valid for as long as \a object @@ -391,7 +391,7 @@ can be very useful while prototyping. */ /*! -\fn QQmlListProperty::QQmlListProperty(QObject *object, void *data, +\fn template<typename T> QQmlListProperty<T>::QQmlListProperty(QObject *object, void *data, CountFunction count, AtFunction at) Construct a readonly QQmlListProperty from a set of operation functions @@ -401,7 +401,7 @@ remains valid while \a object exists. */ /*! -\fn QQmlListProperty::QQmlListProperty(QObject *object, void *data, AppendFunction append, +\fn template<typename T> QQmlListProperty<T>::QQmlListProperty(QObject *object, void *data, AppendFunction append, CountFunction count, AtFunction at, ClearFunction clear) @@ -432,7 +432,7 @@ Return the number of elements in the list \a property. */ /*! -\fn bool QQmlListProperty::operator==(const QQmlListProperty &other) const +\fn template<typename T> bool QQmlListProperty<T>::operator==(const QQmlListProperty &other) const Returns true if this QQmlListProperty is equal to \a other, otherwise false. */ diff --git a/src/qml/qml/qqmllist.h b/src/qml/qml/qqmllist.h index 4c6ae0cb8f..90ec57c911 100644 --- a/src/qml/qml/qqmllist.h +++ b/src/qml/qml/qqmllist.h @@ -61,20 +61,15 @@ public: typedef void (*ClearFunction)(QQmlListProperty<T> *); QQmlListProperty() - : object(nullptr), - data(nullptr), - append(nullptr), + : append(nullptr), count(nullptr), at(nullptr), - clear(nullptr), - dummy1(nullptr), - dummy2(nullptr) + clear(nullptr) {} QQmlListProperty(QObject *o, QList<T *> &list) : object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at), - clear(qlist_clear), - dummy1(nullptr), - dummy2(nullptr) + clear(qlist_clear) + {} QQmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c, AtFunction t, ClearFunction r ) @@ -83,18 +78,15 @@ public: append(a), count(c), at(t), - clear(r), - dummy1(nullptr), - dummy2(nullptr) + clear(r) + {} QQmlListProperty(QObject *o, void *d, CountFunction c, AtFunction t) : object(o), data(d), append(nullptr), count(c), at(t), - clear(nullptr), - dummy1(nullptr), - dummy2(nullptr) + clear(nullptr) {} bool operator==(const QQmlListProperty &o) const { return object == o.object && @@ -105,8 +97,8 @@ public: clear == o.clear; } - QObject *object; - void *data; + QObject *object = nullptr; + void *data = nullptr; AppendFunction append; @@ -115,8 +107,8 @@ public: ClearFunction clear; - void *dummy1; - void *dummy2; + void *dummy1 = nullptr; + void *dummy2 = nullptr; private: static void qlist_append(QQmlListProperty *p, T *v) { diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index b4be83a156..3fbe3df2ab 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -77,7 +77,7 @@ ReturnedValue QmlListWrapper::create(ExecutionEngine *engine, QObject *object, i Scoped<QmlListWrapper> r(scope, engine->memoryManager->allocObject<QmlListWrapper>()); r->d()->object = object; r->d()->propertyType = propType; - void *args[] = { &r->d()->property(), 0 }; + void *args[] = { &r->d()->property(), nullptr }; QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args); return r.asReturnedValue(); } @@ -151,7 +151,7 @@ bool QmlListWrapper::put(Managed *m, String *name, const Value &value) void QmlListWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attrs) { - name->setM(0); + name->setM(nullptr); *index = UINT_MAX; Q_ASSERT(m->as<QmlListWrapper>()); QmlListWrapper *w = static_cast<QmlListWrapper *>(m); @@ -171,10 +171,10 @@ void PropertyListPrototype::init(ExecutionEngine *) defineDefaultProperty(QStringLiteral("push"), method_push, 1); } -ReturnedValue PropertyListPrototype::method_push(const BuiltinFunction *b, CallData *callData) +ReturnedValue PropertyListPrototype::method_push(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - ScopedObject instance(scope, callData->thisObject.toObject(scope.engine)); + ScopedObject instance(scope, thisObject->toObject(scope.engine)); if (!instance) RETURN_UNDEFINED(); QmlListWrapper *w = instance->as<QmlListWrapper>(); @@ -184,9 +184,9 @@ ReturnedValue PropertyListPrototype::method_push(const BuiltinFunction *b, CallD THROW_GENERIC_ERROR("List doesn't define an Append function"); QV4::ScopedObject so(scope); - for (int i = 0, ei = callData->argc(); i < ei; ++i) + for (int i = 0, ei = argc; i < ei; ++i) { - so = callData->args[i].toObject(scope.engine); + so = argv[i].toObject(scope.engine); if (QV4::QObjectWrapper *wrapper = so->as<QV4::QObjectWrapper>()) w->d()->property().append(&w->d()->property(), wrapper->object() ); } diff --git a/src/qml/qml/qqmllistwrapper_p.h b/src/qml/qml/qqmllistwrapper_p.h index 0b53395d2b..e02831c8d1 100644 --- a/src/qml/qml/qqmllistwrapper_p.h +++ b/src/qml/qml/qqmllistwrapper_p.h @@ -103,7 +103,7 @@ struct PropertyListPrototype : Object { void init(ExecutionEngine *engine); - static ReturnedValue method_push(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_push(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); }; } diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 3f2a373966..2a5c58b47b 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -86,37 +86,37 @@ void QQmlDateExtension::registerExtension(QV4::ExecutionEngine *engine) engine->dateCtor()->defineDefaultProperty(QStringLiteral("timeZoneUpdated"), method_timeZoneUpdated); } -ReturnedValue QQmlDateExtension::method_toLocaleString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_toLocaleString(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { Scope scope(b); - if (callData->argc() > 2) - return QV4::DatePrototype::method_toLocaleString(b, &callData->thisObject, callData->args, callData->argc()); + if (argc > 2) + return QV4::DatePrototype::method_toLocaleString(b, thisObject, argv, argc); - QV4::DateObject *date = callData->thisObject.as<DateObject>(); + const QV4::DateObject *date = thisObject->as<DateObject>(); if (!date) - return QV4::DatePrototype::method_toLocaleString(b, &callData->thisObject, callData->args, callData->argc()); + return QV4::DatePrototype::method_toLocaleString(b, thisObject, argv, argc); QDateTime dt = date->toQDateTime(); - if (callData->argc() == 0) { + if (argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; RETURN_RESULT(scope.engine->newString(locale.toString(dt))); } - if (!isLocaleObject(callData->args[0])) - return QV4::DatePrototype::method_toLocaleString(b, &callData->thisObject, callData->args, callData->argc()); // Use the default Date toLocaleString() + if (!isLocaleObject(argv[0])) + return QV4::DatePrototype::method_toLocaleString(b, thisObject, argv, argc); // Use the default Date toLocaleString() - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedDt; - if (callData->argc() == 2) { - if (String *s = callData->args[1].stringValue()) { + if (argc == 2) { + if (String *s = argv[1].stringValue()) { QString format = s->toQString(); formattedDt = r->d()->locale->toString(dt, format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].toNumber(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedDt = r->d()->locale->toString(dt, format); } else { @@ -129,38 +129,38 @@ ReturnedValue QQmlDateExtension::method_toLocaleString(const BuiltinFunction *b, RETURN_RESULT(scope.engine->newString(formattedDt)); } -ReturnedValue QQmlDateExtension::method_toLocaleTimeString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_toLocaleTimeString(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { Scope scope(b); - if (callData->argc() > 2) - return QV4::DatePrototype::method_toLocaleTimeString(b, &callData->thisObject, callData->args, callData->argc()); + if (argc > 2) + return QV4::DatePrototype::method_toLocaleTimeString(b, thisObject, argv, argc); - QV4::DateObject *date = callData->thisObject.as<DateObject>(); + const QV4::DateObject *date = thisObject->as<DateObject>(); if (!date) - return QV4::DatePrototype::method_toLocaleTimeString(b, &callData->thisObject, callData->args, callData->argc()); + return QV4::DatePrototype::method_toLocaleTimeString(b, thisObject, argv, argc); QDateTime dt = date->toQDateTime(); QTime time = dt.time(); - if (callData->argc() == 0) { + if (argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; RETURN_RESULT(scope.engine->newString(locale.toString(time))); } - if (!isLocaleObject(callData->args[0])) - return QV4::DatePrototype::method_toLocaleTimeString(b, &callData->thisObject, callData->args, callData->argc()); // Use the default Date toLocaleTimeString() + if (!isLocaleObject(argv[0])) + return QV4::DatePrototype::method_toLocaleTimeString(b, thisObject, argv, argc); // Use the default Date toLocaleTimeString() - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedTime; - if (callData->argc() == 2) { - if (String *s = callData->args[1].stringValue()) { + if (argc == 2) { + if (String *s = argv[1].stringValue()) { QString format = s->toQString(); formattedTime = r->d()->locale->toString(time, format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].toNumber(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedTime = r->d()->locale->toString(time, format); } else { @@ -173,38 +173,38 @@ ReturnedValue QQmlDateExtension::method_toLocaleTimeString(const BuiltinFunction RETURN_RESULT(scope.engine->newString(formattedTime)); } -ReturnedValue QQmlDateExtension::method_toLocaleDateString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_toLocaleDateString(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { Scope scope(b); - if (callData->argc() > 2) - return QV4::DatePrototype::method_toLocaleDateString(b, &callData->thisObject, callData->args, callData->argc()); + if (argc > 2) + return QV4::DatePrototype::method_toLocaleDateString(b, thisObject, argv, argc); - QV4::DateObject *dateObj = callData->thisObject.as<DateObject>(); + const QV4::DateObject *dateObj = thisObject->as<DateObject>(); if (!dateObj) - return QV4::DatePrototype::method_toLocaleDateString(b, &callData->thisObject, callData->args, callData->argc()); + return QV4::DatePrototype::method_toLocaleDateString(b, thisObject, argv, argc); QDateTime dt = dateObj->toQDateTime(); QDate date = dt.date(); - if (callData->argc() == 0) { + if (argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; RETURN_RESULT(scope.engine->newString(locale.toString(date))); } - if (!isLocaleObject(callData->args[0])) - return QV4::DatePrototype::method_toLocaleDateString(b, &callData->thisObject, callData->args, callData->argc()); // Use the default Date toLocaleDateString() + if (!isLocaleObject(argv[0])) + return QV4::DatePrototype::method_toLocaleDateString(b, thisObject, argv, argc); // Use the default Date toLocaleDateString() - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QString formattedDate; - if (callData->argc() == 2) { - if (String *s = callData->args[1].stringValue()) { + if (argc == 2) { + if (String *s = argv[1].stringValue()) { QString format = s->toQString(); formattedDate = r->d()->locale->toString(date, format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].toNumber(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); formattedDate = r->d()->locale->toString(date, format); } else { @@ -217,12 +217,12 @@ ReturnedValue QQmlDateExtension::method_toLocaleDateString(const BuiltinFunction RETURN_RESULT(scope.engine->newString(formattedDate)); } -ReturnedValue QQmlDateExtension::method_fromLocaleString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_fromLocaleString(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); QV4::ExecutionEngine * const engine = scope.engine; - if (callData->argc() == 1) { - if (String *s = callData->args[0].stringValue()) { + if (argc == 1) { + if (String *s = argv[0].stringValue()) { QLocale locale; QString dateString = s->toQString(); QDateTime dt = locale.toDateTime(dateString); @@ -230,20 +230,20 @@ ReturnedValue QQmlDateExtension::method_fromLocaleString(const BuiltinFunction * } } - if (callData->argc() < 1 || callData->argc() > 3 || !isLocaleObject(callData->args[0])) + if (argc < 1 || argc > 3 || !isLocaleObject(argv[0])) THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QDateTime dt; - QString dateString = callData->args[1].toQStringNoThrow(); - if (callData->argc() == 3) { - if (String *s = callData->args[2].stringValue()) { + QString dateString = argv[1].toQStringNoThrow(); + if (argc == 3) { + if (String *s = argv[2].stringValue()) { QString format = s->toQString(); dt = r->d()->locale->toDateTime(dateString, format); - } else if (callData->args[2].isNumber()) { - quint32 intFormat = callData->args[2].toNumber(); + } else if (argv[2].isNumber()) { + quint32 intFormat = argv[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); dt = r->d()->locale->toDateTime(dateString, format); } else { @@ -256,13 +256,13 @@ ReturnedValue QQmlDateExtension::method_fromLocaleString(const BuiltinFunction * RETURN_RESULT(engine->newDateObject(dt)); } -ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); QV4::ExecutionEngine * const engine = scope.engine; - if (callData->argc() == 1) { - if (String *s = callData->args[0].stringValue()) { + if (argc == 1) { + if (String *s = argv[0].stringValue()) { QLocale locale; QString timeString = s->toQString(); QTime time = locale.toTime(timeString); @@ -272,20 +272,20 @@ ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(const BuiltinFuncti } } - if (callData->argc() < 1 || callData->argc() > 3 || !isLocaleObject(callData->args[0])) + if (argc < 1 || argc > 3 || !isLocaleObject(argv[0])) THROW_ERROR("Locale: Date.fromLocaleTimeString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QTime tm; - QString dateString = callData->args[1].toQStringNoThrow(); - if (callData->argc() == 3) { - if (String *s = callData->args[2].stringValue()) { + QString dateString = argv[1].toQStringNoThrow(); + if (argc == 3) { + if (String *s = argv[2].stringValue()) { QString format = s->toQString(); tm = r->d()->locale->toTime(dateString, format); - } else if (callData->args[2].isNumber()) { - quint32 intFormat = callData->args[2].toNumber(); + } else if (argv[2].isNumber()) { + quint32 intFormat = argv[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); tm = r->d()->locale->toTime(dateString, format); } else { @@ -304,13 +304,13 @@ ReturnedValue QQmlDateExtension::method_fromLocaleTimeString(const BuiltinFuncti RETURN_RESULT(engine->newDateObject(dt)); } -ReturnedValue QQmlDateExtension::method_fromLocaleDateString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_fromLocaleDateString(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); QV4::ExecutionEngine * const engine = scope.engine; - if (callData->argc() == 1) { - if (String *s = callData->args[0].stringValue()) { + if (argc == 1) { + if (String *s = argv[0].stringValue()) { QLocale locale; QString dateString = s->toQString(); QDate date = locale.toDate(dateString); @@ -318,20 +318,20 @@ ReturnedValue QQmlDateExtension::method_fromLocaleDateString(const BuiltinFuncti } } - if (callData->argc() < 1 || callData->argc() > 3 || !isLocaleObject(callData->args[0])) + if (argc < 1 || argc > 3 || !isLocaleObject(argv[0])) THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QLocale::FormatType enumFormat = QLocale::LongFormat; QDate dt; - QString dateString = callData->args[1].toQStringNoThrow(); - if (callData->argc() == 3) { - if (String *s = callData->args[2].stringValue()) { + QString dateString = argv[1].toQStringNoThrow(); + if (argc == 3) { + if (String *s = argv[2].stringValue()) { QString format = s->toQString(); dt = r->d()->locale->toDate(dateString, format); - } else if (callData->args[2].isNumber()) { - quint32 intFormat = callData->args[2].toNumber(); + } else if (argv[2].isNumber()) { + quint32 intFormat = argv[2].toNumber(); QLocale::FormatType format = QLocale::FormatType(intFormat); dt = r->d()->locale->toDate(dateString, format); } else { @@ -344,10 +344,10 @@ ReturnedValue QQmlDateExtension::method_fromLocaleDateString(const BuiltinFuncti RETURN_RESULT(engine->newDateObject(QDateTime(dt))); } -ReturnedValue QQmlDateExtension::method_timeZoneUpdated(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlDateExtension::method_timeZoneUpdated(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *, int argc) { QV4::Scope scope(b); - if (callData->argc() != 0) + if (argc != 0) THROW_ERROR("Locale: Date.timeZoneUpdated(): Invalid arguments"); QV4::DatePrototype::timezoneUpdated(); @@ -365,92 +365,92 @@ void QQmlNumberExtension::registerExtension(QV4::ExecutionEngine *engine) engine->numberCtor()->defineDefaultProperty(QStringLiteral("fromLocaleString"), method_fromLocaleString); } -QV4::ReturnedValue QQmlNumberExtension::method_toLocaleString(const BuiltinFunction *b, CallData *callData) +QV4::ReturnedValue QQmlNumberExtension::method_toLocaleString(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() > 3) + if (argc > 3) THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - double number = callData->thisObject.toNumber(); + double number = thisObject->toNumber(); - if (callData->argc() == 0) { + if (argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; RETURN_RESULT(scope.engine->newString(locale.toString(number))); } - if (!isLocaleObject(callData->args[0])) - return QV4::NumberPrototype::method_toLocaleString(b, &callData->thisObject, callData->args, callData->argc()); // Use the default Number toLocaleString() + if (!isLocaleObject(argv[0])) + return QV4::NumberPrototype::method_toLocaleString(b, thisObject, argv, argc); // Use the default Number toLocaleString() - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); quint16 format = 'f'; - if (callData->argc() > 1) { - if (!callData->args[1].isString()) + if (argc > 1) { + if (!argv[1].isString()) THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - QString fs = callData->args[1].toQString(); + QString fs = argv[1].toQString(); if (fs.length()) format = fs.at(0).unicode(); } int prec = 2; - if (callData->argc() > 2) { - if (!callData->args[2].isNumber()) + if (argc > 2) { + if (!argv[2].isNumber()) THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - prec = callData->args[2].toInt32(); + prec = argv[2].toInt32(); } RETURN_RESULT(scope.engine->newString(r->d()->locale->toString(number, (char)format, prec))); } -ReturnedValue QQmlNumberExtension::method_toLocaleCurrencyString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlNumberExtension::method_toLocaleCurrencyString(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() > 2) + if (argc > 2) THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); - double number = callData->thisObject.toNumber(); + double number = thisObject->toNumber(); - if (callData->argc() == 0) { + if (argc == 0) { // Use QLocale for standard toLocaleString() function QLocale locale; RETURN_RESULT(scope.engine->newString(locale.toString(number))); } - if (!isLocaleObject(callData->args[0])) + if (!isLocaleObject(argv[0])) THROW_ERROR("Locale: Number.toLocaleCurrencyString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); QString symbol; - if (callData->argc() > 1) { - if (!callData->args[1].isString()) + if (argc > 1) { + if (!argv[1].isString()) THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); - symbol = callData->args[1].toQStringNoThrow(); + symbol = argv[1].toQStringNoThrow(); } RETURN_RESULT(scope.engine->newString(r->d()->locale->toCurrencyString(number, symbol))); } -ReturnedValue QQmlNumberExtension::method_fromLocaleString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlNumberExtension::method_fromLocaleString(const QV4::FunctionObject *b, const QV4::Value *, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1 || callData->argc() > 2) + if (argc < 1 || argc > 2) THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); int numberIdx = 0; QLocale locale; - if (callData->argc() == 2) { - if (!isLocaleObject(callData->args[0])) + if (argc == 2) { + if (!isLocaleObject(argv[0])) THROW_ERROR("Locale: Number.fromLocaleString(): Invalid arguments"); - GET_LOCALE_DATA_RESOURCE(callData->args[0]); + GET_LOCALE_DATA_RESOURCE(argv[0]); locale = *r->d()->locale; numberIdx = 1; } - QString ns = callData->args[numberIdx].toQString(); + QString ns = argv[numberIdx].toQString(); if (!ns.length()) RETURN_RESULT(QV4::Encode(Q_QNAN)); @@ -466,10 +466,10 @@ ReturnedValue QQmlNumberExtension::method_fromLocaleString(const BuiltinFunction //-------------- // Locale object -ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); int fdow = int(locale->firstDayOfWeek()); @@ -478,29 +478,29 @@ ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(const BuiltinFunction *b RETURN_RESULT(fdow); } -ReturnedValue QQmlLocaleData::method_get_measurementSystem(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_get_measurementSystem(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); return QV4::Encode(locale->measurementSystem()); } -ReturnedValue QQmlLocaleData::method_get_textDirection(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_get_textDirection(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); return QV4::Encode(locale->textDirection()); } -ReturnedValue QQmlLocaleData::method_get_weekDays(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_get_weekDays(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); @@ -519,10 +519,10 @@ ReturnedValue QQmlLocaleData::method_get_weekDays(const BuiltinFunction *b, Call return result.asReturnedValue(); } -ReturnedValue QQmlLocaleData::method_get_uiLanguages(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_get_uiLanguages(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); @@ -538,19 +538,19 @@ ReturnedValue QQmlLocaleData::method_get_uiLanguages(const BuiltinFunction *b, C return result.asReturnedValue(); } -ReturnedValue QQmlLocaleData::method_currencySymbol(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocaleData::method_currencySymbol(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { QV4::Scope scope(b); - QLocale *locale = getThisLocale(scope, callData); + const QLocale *locale = getThisLocale(scope, thisObject); if (!locale) return Encode::undefined(); - if (callData->argc() > 1) + if (argc > 1) THROW_ERROR("Locale: currencySymbol(): Invalid arguments"); QLocale::CurrencySymbolFormat format = QLocale::CurrencySymbol; - if (callData->argc() == 1) { - quint32 intFormat = callData->args[0].toNumber(); + if (argc == 1) { + quint32 intFormat = argv[0].toNumber(); format = QLocale::CurrencySymbolFormat(intFormat); } @@ -558,16 +558,16 @@ ReturnedValue QQmlLocaleData::method_currencySymbol(const BuiltinFunction *b, Ca } #define LOCALE_FORMAT(FUNC) \ -ReturnedValue QQmlLocaleData::method_ ##FUNC (const BuiltinFunction *b, CallData *callData) { \ +ReturnedValue QQmlLocaleData::method_ ##FUNC (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { \ QV4::Scope scope(b); \ - QLocale *locale = getThisLocale(scope, callData); \ + const QLocale *locale = getThisLocale(scope, thisObject); \ if (!locale) \ return Encode::undefined(); \ - if (callData->argc() > 1) \ + if (argc > 1) \ THROW_ERROR("Locale: " #FUNC "(): Invalid arguments"); \ QLocale::FormatType format = QLocale::LongFormat;\ - if (callData->argc() == 1) { \ - quint32 intFormat = callData->args[0].toUInt32(); \ + if (argc == 1) { \ + quint32 intFormat = argv[0].toUInt32(); \ format = QLocale::FormatType(intFormat); \ } \ RETURN_RESULT(scope.engine->newString(locale-> FUNC (format))); \ @@ -579,21 +579,21 @@ LOCALE_FORMAT(dateFormat) // +1 added to idx because JS is 0-based, whereas QLocale months begin at 1. #define LOCALE_FORMATTED_MONTHNAME(VARIABLE) \ -ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *b, CallData *callData) {\ +ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) {\ Scope scope(b); \ - QLocale *locale = getThisLocale(scope, callData); \ + const QLocale *locale = getThisLocale(scope, thisObject); \ if (!locale) \ return Encode::undefined(); \ - if (callData->argc() < 1 || callData->argc() > 2) \ + if (argc < 1 || argc > 2) \ THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ QLocale::FormatType enumFormat = QLocale::LongFormat; \ - int idx = callData->args[0].toInt32() + 1; \ + int idx = argv[0].toInt32() + 1; \ if (idx < 1 || idx > 12) \ THROW_ERROR("Locale: Invalid month"); \ QString name; \ - if (callData->argc() == 2) { \ - if (callData->args[1].isNumber()) { \ - quint32 intFormat = callData->args[1].toUInt32(); \ + if (argc == 2) { \ + if (argv[1].isNumber()) { \ + quint32 intFormat = argv[1].toUInt32(); \ QLocale::FormatType format = QLocale::FormatType(intFormat); \ name = locale-> VARIABLE(idx, format); \ } else { \ @@ -607,22 +607,22 @@ ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *b, Cal // 0 -> 7 as Qt::Sunday is 7, but Sunday is 0 in JS Date #define LOCALE_FORMATTED_DAYNAME(VARIABLE) \ -ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const BuiltinFunction *b, CallData *callData) {\ +ReturnedValue QQmlLocaleData::method_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) {\ Scope scope(b); \ - QLocale *locale = getThisLocale(scope, callData); \ + const QLocale *locale = getThisLocale(scope, thisObject); \ if (!locale) \ return Encode::undefined(); \ - if (callData->argc() < 1 || callData->argc() > 2) \ + if (argc < 1 || argc > 2) \ THROW_ERROR("Locale: " #VARIABLE "(): Invalid arguments"); \ QLocale::FormatType enumFormat = QLocale::LongFormat; \ - int idx = callData->args[0].toInt32(); \ + int idx = argv[0].toInt32(); \ if (idx < 0 || idx > 7) \ THROW_ERROR("Locale: Invalid day"); \ if (idx == 0) idx = 7; \ QString name; \ - if (callData->argc() == 2) { \ - if (callData->args[1].isNumber()) { \ - quint32 intFormat = callData->args[1].toUInt32(); \ + if (argc == 2) { \ + if (argv[1].isNumber()) { \ + quint32 intFormat = argv[1].toUInt32(); \ QLocale::FormatType format = QLocale::FormatType(intFormat); \ name = locale-> VARIABLE(idx, format); \ } else { \ @@ -640,10 +640,10 @@ LOCALE_FORMATTED_DAYNAME(dayName) LOCALE_FORMATTED_DAYNAME(standaloneDayName) #define LOCALE_STRING_PROPERTY(VARIABLE) \ -ReturnedValue QQmlLocaleData::method_get_ ## VARIABLE (const BuiltinFunction *b, CallData *callData) \ +ReturnedValue QQmlLocaleData::method_get_ ## VARIABLE (const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) \ { \ Scope scope(b); \ - QLocale *locale = getThisLocale(scope, callData); \ + const QLocale *locale = getThisLocale(scope, thisObject); \ if (!locale) \ return Encode::undefined(); \ RETURN_RESULT(scope.engine->newString(locale-> VARIABLE()));\ @@ -684,23 +684,23 @@ QV4LocaleDataDeletable::QV4LocaleDataDeletable(QV4::ExecutionEngine *engine) o->defineDefaultProperty(QStringLiteral("monthName"), QQmlLocaleData::method_monthName, 0); o->defineDefaultProperty(QStringLiteral("currencySymbol"), QQmlLocaleData::method_currencySymbol, 0); o->defineDefaultProperty(QStringLiteral("dateTimeFormat"), QQmlLocaleData::method_dateTimeFormat, 0); - o->defineAccessorProperty(QStringLiteral("name"), QQmlLocaleData::method_get_name, 0); - o->defineAccessorProperty(QStringLiteral("positiveSign"), QQmlLocaleData::method_get_positiveSign, 0); - o->defineAccessorProperty(QStringLiteral("uiLanguages"), QQmlLocaleData::method_get_uiLanguages, 0); - o->defineAccessorProperty(QStringLiteral("firstDayOfWeek"), QQmlLocaleData::method_get_firstDayOfWeek, 0); - o->defineAccessorProperty(QStringLiteral("pmText"), QQmlLocaleData::method_get_pmText, 0); - o->defineAccessorProperty(QStringLiteral("percent"), QQmlLocaleData::method_get_percent, 0); - o->defineAccessorProperty(QStringLiteral("textDirection"), QQmlLocaleData::method_get_textDirection, 0); - o->defineAccessorProperty(QStringLiteral("weekDays"), QQmlLocaleData::method_get_weekDays, 0); - o->defineAccessorProperty(QStringLiteral("negativeSign"), QQmlLocaleData::method_get_negativeSign, 0); - o->defineAccessorProperty(QStringLiteral("groupSeparator"), QQmlLocaleData::method_get_groupSeparator, 0); - o->defineAccessorProperty(QStringLiteral("decimalPoint"), QQmlLocaleData::method_get_decimalPoint, 0); - o->defineAccessorProperty(QStringLiteral("nativeLanguageName"), QQmlLocaleData::method_get_nativeLanguageName, 0); - o->defineAccessorProperty(QStringLiteral("nativeCountryName"), QQmlLocaleData::method_get_nativeCountryName, 0); - o->defineAccessorProperty(QStringLiteral("zeroDigit"), QQmlLocaleData::method_get_zeroDigit, 0); - o->defineAccessorProperty(QStringLiteral("amText"), QQmlLocaleData::method_get_amText, 0); - o->defineAccessorProperty(QStringLiteral("measurementSystem"), QQmlLocaleData::method_get_measurementSystem, 0); - o->defineAccessorProperty(QStringLiteral("exponential"), QQmlLocaleData::method_get_exponential, 0); + o->defineAccessorProperty(QStringLiteral("name"), QQmlLocaleData::method_get_name, nullptr); + o->defineAccessorProperty(QStringLiteral("positiveSign"), QQmlLocaleData::method_get_positiveSign, nullptr); + o->defineAccessorProperty(QStringLiteral("uiLanguages"), QQmlLocaleData::method_get_uiLanguages, nullptr); + o->defineAccessorProperty(QStringLiteral("firstDayOfWeek"), QQmlLocaleData::method_get_firstDayOfWeek, nullptr); + o->defineAccessorProperty(QStringLiteral("pmText"), QQmlLocaleData::method_get_pmText, nullptr); + o->defineAccessorProperty(QStringLiteral("percent"), QQmlLocaleData::method_get_percent, nullptr); + o->defineAccessorProperty(QStringLiteral("textDirection"), QQmlLocaleData::method_get_textDirection, nullptr); + o->defineAccessorProperty(QStringLiteral("weekDays"), QQmlLocaleData::method_get_weekDays, nullptr); + o->defineAccessorProperty(QStringLiteral("negativeSign"), QQmlLocaleData::method_get_negativeSign, nullptr); + o->defineAccessorProperty(QStringLiteral("groupSeparator"), QQmlLocaleData::method_get_groupSeparator, nullptr); + o->defineAccessorProperty(QStringLiteral("decimalPoint"), QQmlLocaleData::method_get_decimalPoint, nullptr); + o->defineAccessorProperty(QStringLiteral("nativeLanguageName"), QQmlLocaleData::method_get_nativeLanguageName, nullptr); + o->defineAccessorProperty(QStringLiteral("nativeCountryName"), QQmlLocaleData::method_get_nativeCountryName, nullptr); + o->defineAccessorProperty(QStringLiteral("zeroDigit"), QQmlLocaleData::method_get_zeroDigit, nullptr); + o->defineAccessorProperty(QStringLiteral("amText"), QQmlLocaleData::method_get_amText, nullptr); + o->defineAccessorProperty(QStringLiteral("measurementSystem"), QQmlLocaleData::method_get_measurementSystem, nullptr); + o->defineAccessorProperty(QStringLiteral("exponential"), QQmlLocaleData::method_get_exponential, nullptr); prototype.set(engine, o); } @@ -837,16 +837,16 @@ void QQmlLocale::registerStringLocaleCompare(QV4::ExecutionEngine *engine) engine->stringPrototype()->defineDefaultProperty(QStringLiteral("localeCompare"), method_localeCompare); } -ReturnedValue QQmlLocale::method_localeCompare(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlLocale::method_localeCompare(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { - if (callData->argc() != 1 || (!callData->args[0].isString() && !callData->args[0].as<StringObject>())) - return QV4::StringPrototype::method_localeCompare(b, &callData->thisObject, callData->args, callData->argc()); + if (argc != 1 || (!argv[0].isString() && !argv[0].as<StringObject>())) + return QV4::StringPrototype::method_localeCompare(b, thisObject, argv, argc); - if (!callData->thisObject.isString() && !callData->thisObject.as<StringObject>()) - return QV4::StringPrototype::method_localeCompare(b, &callData->thisObject, callData->args, callData->argc()); + if (!thisObject->isString() && !thisObject->as<StringObject>()) + return QV4::StringPrototype::method_localeCompare(b, thisObject, argv, argc); - QString thisString = callData->thisObject.toQStringNoThrow(); - QString thatString = callData->args[0].toQStringNoThrow(); + QString thisString = thisObject->toQStringNoThrow(); + QString thatString = argv[0].toQStringNoThrow(); return QV4::Encode(QString::localeAwareCompare(thisString, thatString)); } diff --git a/src/qml/qml/qqmllocale_p.h b/src/qml/qml/qqmllocale_p.h index a81fe07b8e..8341b1f555 100644 --- a/src/qml/qml/qqmllocale_p.h +++ b/src/qml/qml/qqmllocale_p.h @@ -67,13 +67,13 @@ public: static void registerExtension(QV4::ExecutionEngine *engine); private: - static QV4::ReturnedValue method_toLocaleString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_toLocaleTimeString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_toLocaleDateString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_fromLocaleString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_fromLocaleTimeString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_fromLocaleDateString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_timeZoneUpdated(const QV4::BuiltinFunction *, QV4::CallData *callData); + static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_toLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_toLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_fromLocaleTimeString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_fromLocaleDateString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_timeZoneUpdated(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); }; @@ -83,9 +83,9 @@ public: static void registerExtension(QV4::ExecutionEngine *engine); private: - static QV4::ReturnedValue method_toLocaleString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_fromLocaleString(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_toLocaleCurrencyString(const QV4::BuiltinFunction *, QV4::CallData *callData); + static QV4::ReturnedValue method_toLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_fromLocaleString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_toLocaleCurrencyString(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); }; @@ -135,7 +135,7 @@ public: private: QQmlLocale(); - static QV4::ReturnedValue method_localeCompare(const QV4::BuiltinFunction *, QV4::CallData *callData); + static QV4::ReturnedValue method_localeCompare(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); }; namespace QV4 { @@ -158,43 +158,43 @@ struct QQmlLocaleData : public QV4::Object V4_OBJECT2(QQmlLocaleData, Object) V4_NEEDS_DESTROY - static QLocale *getThisLocale(QV4::Scope &scope, QV4::CallData *callData) { - QV4::Object *o = callData->thisObject.as<Object>(); - QQmlLocaleData *thisObject = o ? o->as<QQmlLocaleData>() : 0; - if (!thisObject) { + static QLocale *getThisLocale(QV4::Scope &scope, const QV4::Value *thisObject) { + const QV4::Object *o = thisObject->as<Object>(); + const QQmlLocaleData *data = o ? o->as<QQmlLocaleData>() : nullptr; + if (!data) { scope.engine->throwTypeError(); - return 0; + return nullptr; } - return thisObject->d()->locale; + return data->d()->locale; } - static QV4::ReturnedValue method_currencySymbol(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_dateTimeFormat(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_timeFormat(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_dateFormat(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_monthName(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_standaloneMonthName(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_dayName(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_standaloneDayName(const QV4::BuiltinFunction *, QV4::CallData *callData); - - static QV4::ReturnedValue method_get_firstDayOfWeek(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_measurementSystem(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_textDirection(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_weekDays(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_uiLanguages(const QV4::BuiltinFunction *, QV4::CallData *callData); - - static QV4::ReturnedValue method_get_name(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_nativeLanguageName(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_nativeCountryName(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_decimalPoint(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_groupSeparator(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_percent(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_zeroDigit(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_negativeSign(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_positiveSign(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_exponential(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_amText(const QV4::BuiltinFunction *, QV4::CallData *callData); - static QV4::ReturnedValue method_get_pmText(const QV4::BuiltinFunction *, QV4::CallData *callData); + static QV4::ReturnedValue method_currencySymbol(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_dateTimeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_timeFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_dateFormat(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_monthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_standaloneMonthName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_dayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_standaloneDayName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + + static QV4::ReturnedValue method_get_firstDayOfWeek(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_measurementSystem(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_textDirection(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_weekDays(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_uiLanguages(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + + static QV4::ReturnedValue method_get_name(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_nativeLanguageName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_nativeCountryName(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_decimalPoint(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_groupSeparator(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_percent(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_zeroDigit(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_negativeSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_positiveSign(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_exponential(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_amText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); + static QV4::ReturnedValue method_get_pmText(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc); }; } diff --git a/src/qml/qml/qqmlloggingcategory_p.h b/src/qml/qml/qqmlloggingcategory_p.h index 2b7f2f5b53..544db1fe33 100644 --- a/src/qml/qml/qqmlloggingcategory_p.h +++ b/src/qml/qml/qqmlloggingcategory_p.h @@ -67,7 +67,7 @@ class QQmlLoggingCategory : public QObject, public QQmlParserStatus Q_PROPERTY(QString name READ name WRITE setName) public: - QQmlLoggingCategory(QObject *parent = 0); + QQmlLoggingCategory(QObject *parent = nullptr); virtual ~QQmlLoggingCategory(); QString name() const; diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 5836c85666..7754f0fddc 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -170,7 +170,7 @@ public: ~QQmlTypePrivate(); void init() const; - void initEnums(const QQmlPropertyCache *cache = 0) const; + void initEnums(const QQmlPropertyCache *cache = nullptr) const; void insertEnums(const QMetaObject *metaObject) const; void insertEnumsFromPropertyCache(const QQmlPropertyCache *cache) const; @@ -272,8 +272,10 @@ void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e) QQmlData::ensurePropertyCache(e, o); } else if (!url.isEmpty() && !qobjectApi(e)) { QQmlComponent component(e, url, QQmlComponent::PreferSynchronous); - QObject *o = component.create(); + QObject *o = component.beginCreate(e->rootContext()); setQObjectApi(e, o); + if (o) + component.completeCreate(); } } @@ -313,31 +315,31 @@ QJSValue QQmlType::SingletonInstanceInfo::scriptApi(QQmlEngine *e) const QHash<const QMetaObject *, int> QQmlTypePrivate::attachedPropertyIds; QQmlTypePrivate::QQmlTypePrivate(QQmlType::RegistrationType type) -: refCount(1), regType(type), iid(0), typeId(0), listId(0), revision(0), - containsRevisionedAttributes(false), baseMetaObject(0), +: refCount(1), regType(type), iid(nullptr), typeId(0), listId(0), revision(0), + containsRevisionedAttributes(false), baseMetaObject(nullptr), index(-1), isSetup(false), isEnumSetup(false), haveSuperType(false) { switch (type) { case QQmlType::CppType: extraData.cd = new QQmlCppTypeData; extraData.cd->allocationSize = 0; - extraData.cd->newFunc = 0; + extraData.cd->newFunc = nullptr; extraData.cd->parserStatusCast = -1; - extraData.cd->extFunc = 0; - extraData.cd->extMetaObject = 0; - extraData.cd->customParser = 0; - extraData.cd->attachedPropertiesFunc = 0; - extraData.cd->attachedPropertiesType = 0; + extraData.cd->extFunc = nullptr; + extraData.cd->extMetaObject = nullptr; + extraData.cd->customParser = nullptr; + extraData.cd->attachedPropertiesFunc = nullptr; + extraData.cd->attachedPropertiesType = nullptr; extraData.cd->propertyValueSourceCast = -1; extraData.cd->propertyValueInterceptorCast = -1; break; case QQmlType::SingletonType: case QQmlType::CompositeSingletonType: extraData.sd = new QQmlSingletonTypeData; - extraData.sd->singletonInstanceInfo = 0; + extraData.sd->singletonInstanceInfo = nullptr; break; case QQmlType::InterfaceType: - extraData.cd = 0; + extraData.cd = nullptr; break; case QQmlType::CompositeType: extraData.fd = new QQmlCompositeTypeData; @@ -404,7 +406,7 @@ QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQm d->extraData.sd->singletonInstanceInfo->qobjectCallback = type.qobjectApi; d->extraData.sd->singletonInstanceInfo->typeName = QString::fromUtf8(type.typeName); d->extraData.sd->singletonInstanceInfo->instanceMetaObject - = (type.qobjectApi && type.version >= 1) ? type.instanceMetaObject : 0; + = (type.qobjectApi && type.version >= 1) ? type.instanceMetaObject : nullptr; } QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQmlPrivate::RegisterCompositeSingletonType &type) @@ -476,7 +478,7 @@ QQmlType::QQmlType(QQmlMetaTypeData *data, const QString &elementName, const QQm } QQmlType::QQmlType() - : d(0) + : d(nullptr) { } @@ -584,10 +586,10 @@ QQmlPropertyCache *QQmlType::compositePropertyCache(QQmlEnginePrivate *engine) c // similar logic to resolveCompositeBaseType Q_ASSERT(isComposite()); if (!engine) - return 0; + return nullptr; QQmlRefPointer<QQmlTypeData> td(engine->typeLoader.getType(sourceUrl()), QQmlRefPointer<QQmlTypeData>::Adopt); if (td.isNull() || !td->isComplete()) - return 0; + return nullptr; QV4::CompiledData::CompilationUnit *compilationUnit = td->compilationUnit(); return compilationUnit->rootPropertyCache(); } @@ -737,7 +739,7 @@ void QQmlTypePrivate::init() const // Check for revisioned details { - const QMetaObject *mo = 0; + const QMetaObject *mo = nullptr; if (metaObjects.isEmpty()) mo = baseMetaObject; else @@ -790,7 +792,7 @@ void QQmlTypePrivate::insertEnums(const QMetaObject *metaObject) const for (int ii = 0; ii < metaObject->enumeratorCount(); ++ii) { QMetaEnum e = metaObject->enumerator(ii); const bool isScoped = e.isScoped(); - QStringHash<int> *scoped = isScoped ? new QStringHash<int>() : 0; + QStringHash<int> *scoped = isScoped ? new QStringHash<int>() : nullptr; for (int jj = 0; jj < e.keyCount(); ++jj) { const QString key = QString::fromUtf8(e.key(jj)); @@ -886,7 +888,7 @@ QString QQmlType::qmlTypeName() const QObject *QQmlType::create() const { if (!d || !isCreatable()) - return 0; + return nullptr; d->init(); @@ -919,25 +921,25 @@ void QQmlType::create(QObject **out, void **memory, size_t additionalMemory) con QQmlType::SingletonInstanceInfo *QQmlType::singletonInstanceInfo() const { if (!d) - return 0; + return nullptr; if (d->regType != SingletonType && d->regType != CompositeSingletonType) - return 0; + return nullptr; return d->extraData.sd->singletonInstanceInfo; } QQmlCustomParser *QQmlType::customParser() const { if (!d) - return 0; + return nullptr; if (d->regType != CppType) - return 0; + return nullptr; return d->extraData.cd->customParser; } QQmlType::CreateFunc QQmlType::createFunction() const { if (!d || d->regType != CppType) - return 0; + return nullptr; return d->extraData.cd->newFunc; } @@ -1002,7 +1004,7 @@ int QQmlType::qListTypeId() const const QMetaObject *QQmlType::metaObject() const { if (!d) - return 0; + return nullptr; d->init(); if (d->metaObjects.isEmpty()) @@ -1014,7 +1016,7 @@ const QMetaObject *QQmlType::metaObject() const const QMetaObject *QQmlType::baseMetaObject() const { - return d ? d->baseMetaObject : 0; + return d ? d->baseMetaObject : nullptr; } bool QQmlType::containsRevisionedAttributes() const @@ -1034,7 +1036,7 @@ int QQmlType::metaObjectRevision() const QQmlAttachedPropertiesFunc QQmlType::attachedPropertiesFunction(QQmlEnginePrivate *engine) const { if (!d) - return 0; + return nullptr; if (d->regType == CppType) return d->extraData.cd->attachedPropertiesFunc; @@ -1047,7 +1049,7 @@ QQmlAttachedPropertiesFunc QQmlType::attachedPropertiesFunction(QQmlEnginePrivat const QMetaObject *QQmlType::attachedPropertiesType(QQmlEnginePrivate *engine) const { if (!d) - return 0; + return nullptr; if (d->regType == CppType) return d->extraData.cd->attachedPropertiesType; @@ -1099,7 +1101,7 @@ int QQmlType::propertyValueInterceptorCast() const const char *QQmlType::interfaceIId() const { if (!d || d->regType != InterfaceType) - return 0; + return nullptr; return d->iid; } @@ -1123,7 +1125,7 @@ int QQmlType::enumValue(QQmlEnginePrivate *engine, const QHashedStringRef &name, { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; @@ -1142,7 +1144,7 @@ int QQmlType::enumValue(QQmlEnginePrivate *engine, const QHashedCStringRef &name { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; @@ -1161,7 +1163,7 @@ int QQmlType::enumValue(QQmlEnginePrivate *engine, const QV4::String *name, bool { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; d->initEnums(cache); @@ -1179,7 +1181,7 @@ int QQmlType::scopedEnumIndex(QQmlEnginePrivate *engine, const QV4::String *name { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; d->initEnums(cache); @@ -1197,7 +1199,7 @@ int QQmlType::scopedEnumIndex(QQmlEnginePrivate *engine, const QString &name, bo { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; d->initEnums(cache); @@ -1249,7 +1251,7 @@ int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &scope { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; d->initEnums(cache); @@ -1272,7 +1274,7 @@ int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &scope { Q_ASSERT(ok); if (d) { - const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : 0; + const QQmlPropertyCache *cache = isComposite() ? compositePropertyCache(engine) : nullptr; *ok = true; d->initEnums(cache); @@ -1338,7 +1340,7 @@ QQmlTypeModule::QQmlTypeModule() QQmlTypeModule::~QQmlTypeModule() { - delete d; d = 0; + delete d; d = nullptr; } QString QQmlTypeModule::module() const @@ -1437,7 +1439,7 @@ void QQmlTypeModule::walkCompositeSingletons(const std::function<void(const QQml } QQmlTypeModuleVersion::QQmlTypeModuleVersion() -: m_module(0), m_minor(0) +: m_module(nullptr), m_minor(0) { } @@ -1564,6 +1566,12 @@ QString registrationTypeString(QQmlType::RegistrationType typeType) bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *data, const char *uri, const QString &typeName, int majorVersion = -1) { if (!typeName.isEmpty()) { + if (typeName.at(0).isLower()) { + QString failure(QCoreApplication::translate("qmlRegisterType", "Invalid QML %1 name \"%2\"; type names must begin with an uppercase letter")); + data->typeRegistrationFailures.append(failure.arg(registrationTypeString(typeType)).arg(typeName)); + return false; + } + int typeNameLen = typeName.length(); for (int ii = 0; ii < typeNameLen; ++ii) { if (!(typeName.at(ii).isLetterOrNumber() || typeName.at(ii) == '_')) { @@ -1577,15 +1585,7 @@ bool checkRegistration(QQmlType::RegistrationType typeType, QQmlMetaTypeData *da if (uri && !typeName.isEmpty()) { QString nameSpace = QString::fromUtf8(uri); - if (!data->typeRegistrationNamespace.isEmpty()) { - // We can only install types into the registered namespace - if (nameSpace != data->typeRegistrationNamespace) { - QString failure(QCoreApplication::translate("qmlRegisterType", - "Cannot install %1 '%2' into unregistered namespace '%3'")); - data->typeRegistrationFailures.append(failure.arg(registrationTypeString(typeType)).arg(typeName).arg(nameSpace)); - return false; - } - } else if (data->typeRegistrationNamespace != nameSpace) { + if (data->typeRegistrationNamespace.isEmpty() && !nameSpace.isEmpty()) { // Is the target namespace protected against further registrations? if (data->protectedNamespaces.contains(nameSpace)) { QString failure(QCoreApplication::translate("qmlRegisterType", @@ -1699,7 +1699,7 @@ QQmlType QQmlMetaType::registerCompositeSingletonType(const QQmlPrivate::Registe bool fileImport = false; if (*(type.uri) == '\0') fileImport = true; - if (!checkRegistration(QQmlType::CompositeSingletonType, data, fileImport ? 0 : type.uri, typeName)) + if (!checkRegistration(QQmlType::CompositeSingletonType, data, fileImport ? nullptr : type.uri, typeName)) return QQmlType(); QQmlType dtype(data, typeName, type); @@ -1721,7 +1721,7 @@ QQmlType QQmlMetaType::registerCompositeType(const QQmlPrivate::RegisterComposit bool fileImport = false; if (*(type.uri) == '\0') fileImport = true; - if (!checkRegistration(QQmlType::CompositeType, data, fileImport?0:type.uri, typeName, type.versionMajor)) + if (!checkRegistration(QQmlType::CompositeType, data, fileImport?nullptr:type.uri, typeName, type.versionMajor)) return QQmlType(); QQmlType dtype(data, typeName, type); @@ -1745,13 +1745,13 @@ void QQmlMetaType::registerInternalCompositeType(QV4::CompiledData::CompilationU QtMetaTypePrivate::QMetaTypeFunctionHelper<QObject*>::Construct, sizeof(QObject*), static_cast<QFlags<QMetaType::TypeFlag> >(QtPrivate::QMetaTypeTypeFlags<QObject*>::Flags), - 0); + nullptr); int lst_type = QMetaType::registerNormalizedType(lst, QtMetaTypePrivate::QMetaTypeFunctionHelper<QQmlListProperty<QObject> >::Destruct, QtMetaTypePrivate::QMetaTypeFunctionHelper<QQmlListProperty<QObject> >::Construct, sizeof(QQmlListProperty<QObject>), static_cast<QFlags<QMetaType::TypeFlag> >(QtPrivate::QMetaTypeTypeFlags<QQmlListProperty<QObject> >::Flags), - static_cast<QMetaObject*>(0)); + static_cast<QMetaObject*>(nullptr)); compilationUnit->metaTypeId = ptr_type; compilationUnit->listMetaTypeId = lst_type; @@ -1809,6 +1809,9 @@ int QQmlPrivate::qmlregister(RegistrationType type, void *data) else return -1; + if (!dtype.isValid()) + return -1; + QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *typeData = metaTypeData(); typeData->undeletableTypes.insert(dtype); @@ -1961,7 +1964,7 @@ QObject *QQmlMetaType::toQObject(const QVariant &v, bool *ok) { if (!isQObject(v.userType())) { if (ok) *ok = false; - return 0; + return nullptr; } if (ok) *ok = true; @@ -2011,7 +2014,7 @@ int QQmlMetaType::attachedPropertiesFuncId(QQmlEnginePrivate *engine, const QMet QQmlAttachedPropertiesFunc QQmlMetaType::attachedPropertiesFuncById(QQmlEnginePrivate *engine, int id) { if (id < 0) - return 0; + return nullptr; QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); return data->types.at(id).attachedPropertiesFunction(engine); @@ -2104,7 +2107,7 @@ const char *QQmlMetaType::interfaceIId(int userType) if (type.isInterface() && type.typeId() == userType) return type.interfaceIId(); else - return 0; + return nullptr; } bool QQmlMetaType::isList(int userType) @@ -2397,6 +2400,27 @@ QQmlPropertyCache *QQmlMetaType::propertyCache(const QQmlType &type, int minorVe return data->propertyCache(type, minorVersion); } +void qmlUnregisterType(int typeIndex) +{ + QMutexLocker lock(metaTypeDataLock()); + QQmlMetaTypeData *data = metaTypeData(); + { + const QQmlTypePrivate *d = data->types.value(typeIndex).priv(); + if (d) { + removeQQmlTypePrivate(data->idToType, d); + removeQQmlTypePrivate(data->nameToType, d); + removeQQmlTypePrivate(data->urlToType, d); + removeQQmlTypePrivate(data->urlToNonFileImportType, d); + removeQQmlTypePrivate(data->metaObjectToType, d); + for (QQmlMetaTypeData::TypeModules::Iterator module = data->uriToModule.begin(); module != data->uriToModule.end(); ++module) { + QQmlTypeModulePrivate *modulePrivate = (*module)->priv(); + modulePrivate->remove(d); + } + data->types[typeIndex] = QQmlType(); + } + } +} + void QQmlMetaType::freeUnusedTypesAndCaches() { QMutexLocker lock(metaTypeDataLock()); @@ -2515,16 +2539,16 @@ QList<QQmlType> QQmlMetaType::qmlSingletonTypes() return retn; } -const QQmlPrivate::CachedQmlUnit *QQmlMetaType::findCachedCompilationUnit(const QUrl &uri) +const QV4::CompiledData::Unit *QQmlMetaType::findCachedCompilationUnit(const QUrl &uri) { QMutexLocker lock(metaTypeDataLock()); QQmlMetaTypeData *data = metaTypeData(); for (const auto lookup : qAsConst(data->lookupCachedQmlUnit)) { if (const QQmlPrivate::CachedQmlUnit *unit = lookup(uri)) - return unit; + return unit->qmlData; } - return 0; + return nullptr; } /*! diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 85ee4d7b97..07bef526ba 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -75,6 +75,8 @@ class QQmlCompiledData; namespace QV4 { struct String; } +void Q_QML_PRIVATE_EXPORT qmlUnregisterType(int type); + class Q_QML_PRIVATE_EXPORT QQmlMetaType { public: @@ -107,7 +109,7 @@ public: static QMetaMethod defaultMethod(QObject *); static bool isQObject(int); - static QObject *toQObject(const QVariant &, bool *ok = 0); + static QObject *toQObject(const QVariant &, bool *ok = nullptr); static int listType(int); static int attachedPropertiesFuncId(QQmlEnginePrivate *engine, const QMetaObject *); @@ -131,7 +133,7 @@ public: static QList<QQmlPrivate::AutoParentFunction> parentFunctions(); - static const QQmlPrivate::CachedQmlUnit *findCachedCompilationUnit(const QUrl &uri); + static const QV4::CompiledData::Unit *findCachedCompilationUnit(const QUrl &uri); static bool namespaceContainsRegistrations(const QString &, int majorVersion); @@ -161,7 +163,7 @@ public: return d == other.d; } - bool isValid() const { return d != 0; } + bool isValid() const { return d != nullptr; } const QQmlTypePrivate *key() const { return d; } QByteArray typeName() const; @@ -216,7 +218,7 @@ public: { public: SingletonInstanceInfo() - : scriptCallback(0), qobjectCallback(0), instanceMetaObject(0) {} + : scriptCallback(nullptr), qobjectCallback(nullptr), instanceMetaObject(nullptr) {} QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *); QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *); diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp index e068ad174a..ac247ae0ad 100644 --- a/src/qml/qml/qqmlnotifier.cpp +++ b/src/qml/qml/qqmlnotifier.cpp @@ -51,7 +51,7 @@ void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *, void **); void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *, void **); static Callback QQmlNotifier_callbacks[] = { - 0, + nullptr, QQmlBoundSignal_callback, QQmlJavaScriptExpressionGuard_callback, QQmlVMEMetaObjectEndpoint_callback @@ -59,9 +59,9 @@ static Callback QQmlNotifier_callbacks[] = { namespace { struct NotifyListTraversalData { - NotifyListTraversalData(QQmlNotifierEndpoint *ep = 0) + NotifyListTraversalData(QQmlNotifierEndpoint *ep = nullptr) : originalSenderPtr(0) - , disconnectWatch(0) + , disconnectWatch(nullptr) , endpoint(ep) {} diff --git a/src/qml/qml/qqmlnotifier_p.h b/src/qml/qml/qqmlnotifier_p.h index a99b13f155..d77e314de5 100644 --- a/src/qml/qml/qqmlnotifier_p.h +++ b/src/qml/qml/qqmlnotifier_p.h @@ -73,7 +73,7 @@ private: friend class QQmlThreadNotifierProxyObject; static void emitNotify(QQmlNotifierEndpoint *, void **a); - QQmlNotifierEndpoint *endpoints; + QQmlNotifierEndpoint *endpoints = nullptr; }; class QQmlEngine; @@ -129,7 +129,6 @@ private: }; QQmlNotifier::QQmlNotifier() -: endpoints(0) { } @@ -142,22 +141,22 @@ QQmlNotifier::~QQmlNotifier() if (n->isNotifying()) *((qintptr *)(n->senderPtr & ~0x1)) = 0; - n->next = 0; - n->prev = 0; + n->next = nullptr; + n->prev = nullptr; n->senderPtr = 0; n->sourceSignal = -1; } - endpoints = 0; + endpoints = nullptr; } void QQmlNotifier::notify() { - void *args[] = { 0 }; + void *args[] = { nullptr }; if (endpoints) emitNotify(endpoints, args); } QQmlNotifierEndpoint::QQmlNotifierEndpoint(Callback callback) -: next(0), prev(0), senderPtr(0), callback(callback), needsConnectNotify(false), sourceSignal(-1) +: next(nullptr), prev(nullptr), senderPtr(0), callback(callback), needsConnectNotify(false), sourceSignal(-1) { } @@ -168,7 +167,7 @@ QQmlNotifierEndpoint::~QQmlNotifierEndpoint() bool QQmlNotifierEndpoint::isConnected() const { - return prev != 0; + return prev != nullptr; } /*! \internal @@ -212,8 +211,8 @@ void QQmlNotifierEndpoint::disconnect() } if (isNotifying()) *((qintptr *)(senderPtr & ~0x1)) = 0; - next = 0; - prev = 0; + next = nullptr; + prev = nullptr; senderPtr = 0; sourceSignal = -1; } diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index d009536767..36e56a01f8 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -82,13 +82,13 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QV4::Compil { init(parentContext); - sharedState->componentAttached = 0; + sharedState->componentAttached = nullptr; sharedState->allCreatedBindings.allocate(compilationUnit->totalBindingsCount); sharedState->allParserStatusCallbacks.allocate(compilationUnit->totalParserStatusCount); sharedState->allCreatedObjects.allocate(compilationUnit->totalObjectCount); - sharedState->allJavaScriptObjects = 0; + sharedState->allJavaScriptObjects = nullptr; sharedState->creationContext = creationContext; - sharedState->rootContext = 0; + sharedState->rootContext = nullptr; if (auto profiler = QQmlEnginePrivate::get(engine)->profiler) { Q_QML_PROFILE_IF_ENABLED(QQmlProfilerDefinitions::ProfileCreating, profiler, @@ -105,7 +105,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QV4::Compil , propertyCaches(&compilationUnit->propertyCaches) , sharedState(inheritedSharedState) , topLevelCreator(false) - , incubator(0) + , incubator(nullptr) { init(parentContext); } @@ -114,23 +114,23 @@ void QQmlObjectCreator::init(QQmlContextData *providedParentContext) { parentContext = providedParentContext; engine = parentContext->engine; - v4 = QV8Engine::getV4(engine); + v4 = engine->handle(); if (compilationUnit && !compilationUnit->engine) compilationUnit->linkToEngine(v4); qmlUnit = compilationUnit->data; - context = 0; - _qobject = 0; - _scopeObject = 0; - _bindingTarget = 0; - _valueTypeProperty = 0; - _compiledObject = 0; + context = nullptr; + _qobject = nullptr; + _scopeObject = nullptr; + _bindingTarget = nullptr; + _valueTypeProperty = nullptr; + _compiledObject = nullptr; _compiledObjectIndex = -1; - _ddata = 0; - _propertyCache = 0; - _vmeMetaObject = 0; - _qmlContext = 0; + _ddata = nullptr; + _propertyCache = nullptr; + _vmeMetaObject = nullptr; + _qmlContext = nullptr; } QQmlObjectCreator::~QQmlObjectCreator() @@ -142,7 +142,7 @@ QQmlObjectCreator::~QQmlObjectCreator() for (int i = 0; i < sharedState->allParserStatusCallbacks.count(); ++i) { QQmlParserStatus *ps = sharedState->allParserStatusCallbacks.at(i); if (ps) - ps->d = 0; + ps->d = nullptr; } while (sharedState->componentAttached) { QQmlComponentAttached *a = sharedState->componentAttached; @@ -203,19 +203,16 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI if (instance) { QQmlData *ddata = QQmlData::get(instance); Q_ASSERT(ddata); - if (ddata->compilationUnit) - ddata->compilationUnit->release(); ddata->compilationUnit = compilationUnit; - ddata->compilationUnit->addref(); } if (topLevelCreator) - sharedState->allJavaScriptObjects = 0; + sharedState->allJavaScriptObjects = nullptr; phase = CreatingObjectsPhase2; if (interrupt && interrupt->shouldInterrupt()) - return 0; + return nullptr; phase = ObjectsCreated; @@ -233,6 +230,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI return instance; } +// ### unify or keep in sync with populateDeferredBinding() bool QQmlObjectCreator::populateDeferredProperties(QObject *instance, QQmlData::DeferredData *deferredData) { QQmlData *declarativeData = QQmlData::get(instance); @@ -283,6 +281,80 @@ bool QQmlObjectCreator::populateDeferredProperties(QObject *instance, QQmlData:: qSwap(_qmlContext, qmlContext); qSwap(_scopeObject, scopeObject); + deferredData->bindings.clear(); + phase = ObjectsCreated; + + return errors.isEmpty(); +} + +// ### unify or keep in sync with populateDeferredProperties() +bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty, QQmlData::DeferredData *deferredData, const QV4::CompiledData::Binding *binding) +{ + Q_ASSERT(binding->flags & QV4::CompiledData::Binding::IsDeferredBinding); + + QObject *instance = qmlProperty.object(); + QQmlData *declarativeData = QQmlData::get(instance); + context = deferredData->context; + sharedState->rootContext = context; + + QObject *bindingTarget = instance; + + QQmlRefPointer<QQmlPropertyCache> cache = declarativeData->propertyCache; + QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance); + + QObject *scopeObject = instance; + qSwap(_scopeObject, scopeObject); + + QV4::Scope valueScope(v4); + + Q_ASSERT(topLevelCreator); + if (!sharedState->allJavaScriptObjects) + sharedState->allJavaScriptObjects = valueScope.alloc(compilationUnit->totalObjectCount); + + QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc(1)); + + qSwap(_qmlContext, qmlContext); + + qSwap(_propertyCache, cache); + qSwap(_qobject, instance); + + int objectIndex = deferredData->deferredIdx; + qSwap(_compiledObjectIndex, objectIndex); + + const QV4::CompiledData::Object *obj = qmlUnit->objectAt(_compiledObjectIndex); + qSwap(_compiledObject, obj); + + qSwap(_ddata, declarativeData); + qSwap(_bindingTarget, bindingTarget); + qSwap(_vmeMetaObject, vmeMetaObject); + + QQmlListProperty<void> savedList; + qSwap(_currentList, savedList); + + const QQmlPropertyData &property = QQmlPropertyPrivate::get(qmlProperty)->core; + + if (property.isQList()) { + void *argv[1] = { (void*)&_currentList }; + QMetaObject::metacall(_qobject, QMetaObject::ReadProperty, property.coreIndex(), argv); + } else if (_currentList.object) { + _currentList = QQmlListProperty<void>(); + } + + setPropertyBinding(&property, binding); + + qSwap(_currentList, savedList); + + qSwap(_vmeMetaObject, vmeMetaObject); + qSwap(_bindingTarget, bindingTarget); + qSwap(_ddata, declarativeData); + qSwap(_compiledObject, obj); + qSwap(_compiledObjectIndex, objectIndex); + qSwap(_qobject, instance); + qSwap(_propertyCache, cache); + + qSwap(_qmlContext, qmlContext); + qSwap(_scopeObject, scopeObject); + phase = ObjectsCreated; return errors.isEmpty(); @@ -370,7 +442,7 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QString string = binding->valueAsString(qmlUnit); // Encoded dir-separators defeat QUrl processing - decode them first string.replace(QLatin1String("%2f"), QLatin1String("/"), Qt::CaseInsensitive); - QUrl value = string.isEmpty() ? QUrl() : compilationUnit->url().resolved(QUrl(string)); + QUrl value = string.isEmpty() ? QUrl() : compilationUnit->finalUrl().resolved(QUrl(string)); // Apply URL interceptor if (engine->urlInterceptor()) value = engine->urlInterceptor()->intercept(value, QQmlAbstractUrlInterceptor::UrlString); @@ -568,7 +640,8 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const } else if (property->propType() == qMetaTypeId<QList<QUrl> >()) { Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_String); QString urlString = binding->valueAsString(qmlUnit); - QUrl u = urlString.isEmpty() ? QUrl() : compilationUnit->url().resolved(QUrl(urlString)); + QUrl u = urlString.isEmpty() ? QUrl() + : compilationUnit->finalUrl().resolved(QUrl(urlString)); QList<QUrl> value; value.append(u); property->writeProperty(_qobject, &value, propertyWriteFlags); @@ -723,7 +796,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con } const int id = attachedType.attachedPropertiesId(QQmlEnginePrivate::get(engine)); QObject *qmlObject = qmlAttachedPropertiesObjectById(id, _qobject); - if (!populateInstance(binding->value.objectIndex, qmlObject, qmlObject, /*value type property*/0)) + if (!populateInstance(binding->value.objectIndex, qmlObject, qmlObject, /*value type property*/nullptr)) return false; return true; } @@ -741,12 +814,12 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con QQmlPropertyData::WriteFlags propertyWriteFlags = QQmlPropertyData::BypassInterceptor | QQmlPropertyData::RemoveBindingOnAliasWrite; int propertyWriteStatus = -1; - void *argv[] = { &ss, 0, &propertyWriteStatus, &propertyWriteFlags }; + void *argv[] = { &ss, nullptr, &propertyWriteStatus, &propertyWriteFlags }; QMetaObject::metacall(_qobject, QMetaObject::WriteProperty, property->coreIndex(), argv); return true; } - QObject *createdSubObject = 0; + QObject *createdSubObject = nullptr; if (binding->type == QV4::CompiledData::Binding::Type_Object) { createdSubObject = createInstance(binding->value.objectIndex, _bindingTarget); if (!createdSubObject) @@ -760,9 +833,9 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con const QV4::CompiledData::Object *obj = qmlUnit->objectAt(binding->value.objectIndex); if (stringAt(obj->inheritedTypeNameIndex).isEmpty()) { - QObject *groupObject = 0; - QQmlValueType *valueType = 0; - const QQmlPropertyData *valueTypeProperty = 0; + QObject *groupObject = nullptr; + QQmlValueType *valueType = nullptr; + const QQmlPropertyData *valueTypeProperty = nullptr; QObject *bindingTarget = _bindingTarget; if (QQmlValueTypeFactory::isValueType(property->propType())) { @@ -935,7 +1008,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con QQmlPropertyData::WriteFlags propertyWriteFlags = QQmlPropertyData::BypassInterceptor | QQmlPropertyData::RemoveBindingOnAliasWrite; int propertyWriteStatus = -1; - void *argv[] = { 0, 0, &propertyWriteStatus, &propertyWriteFlags }; + void *argv[] = { nullptr, nullptr, &propertyWriteStatus, &propertyWriteFlags }; if (const char *iid = QQmlMetaType::interfaceIId(property->propType())) { void *ptr = createdSubObject->qt_metacast(iid); @@ -949,7 +1022,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con } else if (property->propType() == QMetaType::QVariant) { if (property->isVarProperty()) { QV4::Scope scope(v4); - QV4::ScopedValue wrappedObject(scope, QV4::QObjectWrapper::wrap(QV8Engine::getV4(engine), createdSubObject)); + QV4::ScopedValue wrappedObject(scope, QV4::QObjectWrapper::wrap(engine->handle(), createdSubObject)); _vmeMetaObject->setVMEProperty(property->coreIndex(), wrappedObject); } else { QVariant value = QVariant::fromValue(createdSubObject); @@ -961,7 +1034,7 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *property, con void *itemToAdd = createdSubObject; - const char *iid = 0; + const char *iid = nullptr; int listItemType = QQmlEnginePrivate::get(engine)->listType(property->propType()); if (listItemType != -1) iid = QQmlMetaType::interfaceIId(listItemType); @@ -1028,12 +1101,9 @@ void QQmlObjectCreator::registerObjectWithContextById(const QV4::CompiledData::O context->setIdProperty(object->id, instance); } -QV4::QmlContext *QQmlObjectCreator::currentQmlContext() +void QQmlObjectCreator::createQmlContext() { - if (!_qmlContext->isManaged()) - _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); - - return _qmlContext; + _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); } QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isContextObject) @@ -1044,10 +1114,10 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine)); bool isComponent = false; - QObject *instance = 0; - QQmlData *ddata = 0; - QQmlCustomParser *customParser = 0; - QQmlParserStatus *parserStatus = 0; + QObject *instance = nullptr; + QQmlData *ddata = nullptr; + QQmlCustomParser *customParser = nullptr; + QQmlParserStatus *parserStatus = nullptr; bool installPropertyCache = true; if (obj->flags & QV4::CompiledData::Object::IsComponent) { @@ -1067,11 +1137,11 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo Q_QML_OC_PROFILE(sharedState->profiler, profiler.update( compilationUnit, obj, type.qmlTypeName(), context->url())); - void *ddataMemory = 0; + void *ddataMemory = nullptr; type.create(&instance, &ddataMemory, sizeof(QQmlData)); if (!instance) { recordError(obj->location, tr("Unable to create object of type %1").arg(stringAt(obj->inheritedTypeNameIndex))); - return 0; + return nullptr; } { @@ -1103,14 +1173,14 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo if (typeRef->compilationUnit->data->isSingleton()) { recordError(obj->location, tr("Composite Singleton Type %1 is not creatable").arg(stringAt(obj->inheritedTypeNameIndex))); - return 0; + return nullptr; } QQmlObjectCreator subCreator(context, typeRef->compilationUnit, sharedState.data()); instance = subCreator.create(); if (!instance) { errors += subCreator.errors; - return 0; + return nullptr; } } if (instance->isWidgetType()) { @@ -1174,8 +1244,8 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo } customParser->applyBindings(instance, compilationUnit, bindings); - customParser->engine = 0; - customParser->imports = (QQmlTypeNameCache*)0; + customParser->engine = nullptr; + customParser->imports = (QQmlTypeNameCache*)nullptr; } if (isComponent) { @@ -1204,12 +1274,12 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo qSwap(_qmlContext, qmlContext); - bool result = populateInstance(index, instance, /*binding target*/instance, /*value type property*/0); + bool result = populateInstance(index, instance, /*binding target*/instance, /*value type property*/nullptr); qSwap(_qmlContext, qmlContext); qSwap(_scopeObject, scopeObject); - return result ? instance : 0; + return result ? instance : nullptr; } QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interrupt) @@ -1233,7 +1303,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru QQmlPropertyData::DontRemoveBinding); if (watcher.hasRecursed() || interrupt.shouldInterrupt()) - return 0; + return nullptr; } if (QQmlVME::componentCompleteEnabled()) { // the qml designer does the component complete later @@ -1242,12 +1312,12 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru QQmlParserStatus *status = sharedState->allParserStatusCallbacks.pop(); if (status && status->d) { - status->d = 0; + status->d = nullptr; status->componentComplete(); } if (watcher.hasRecursed() || interrupt.shouldInterrupt()) - return 0; + return nullptr; } } @@ -1255,11 +1325,11 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru QQmlEnginePrivate::FinalizeCallback callback = sharedState->finalizeCallbacks.at(ii); QObject *obj = callback.first; if (obj) { - void *args[] = { 0 }; + void *args[] = { nullptr }; QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, callback.second, args); } if (watcher.hasRecursed()) - return 0; + return nullptr; } sharedState->finalizeCallbacks.clear(); @@ -1274,7 +1344,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru emit a->completed(); if (watcher.hasRecursed() || interrupt.shouldInterrupt()) - return 0; + return nullptr; } phase = Done; @@ -1282,21 +1352,6 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru return sharedState->rootContext; } -void QQmlObjectCreator::cancel(QObject *object) -{ - int last = sharedState->allCreatedObjects.count() - 1; - int i = last; - while (i >= 0) { - if (sharedState->allCreatedObjects.at(i) == object) { - if (i < last) - qSwap(sharedState->allCreatedObjects[i], sharedState->allCreatedObjects[last]); - sharedState->allCreatedObjects.pop(); - break; - } - --i; - } -} - void QQmlObjectCreator::clear() { if (phase == Done || phase == Finalizing || phase == Startup) @@ -1331,7 +1386,7 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject * QQmlRefPointer<QQmlPropertyCache> cache = propertyCaches->at(_compiledObjectIndex); - QQmlVMEMetaObject *vmeMetaObject = 0; + QQmlVMEMetaObject *vmeMetaObject = nullptr; if (propertyCaches->needsVMEMetaObject(_compiledObjectIndex)) { Q_ASSERT(!cache.isNull()); // install on _object @@ -1350,14 +1405,8 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject * qSwap(_propertyCache, cache); qSwap(_vmeMetaObject, vmeMetaObject); - if (_compiledObject->flags & QV4::CompiledData::Object::HasDeferredBindings) { - QQmlData::DeferredData *deferData = new QQmlData::DeferredData; - deferData->deferredIdx = _compiledObjectIndex; - deferData->compilationUnit = compilationUnit; - deferData->compilationUnit->addref(); - deferData->context = context; - _ddata->deferredData.append(deferData); - } + if (_compiledObject->flags & QV4::CompiledData::Object::HasDeferredBindings) + _ddata->deferData(_compiledObjectIndex, compilationUnit, context); if (_compiledObject->nFunctions > 0) setupFunctions(); diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index aa0165ec06..399a5f6d4a 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -81,17 +81,17 @@ struct QQmlObjectCreatorSharedState : public QSharedData QRecursionNode recursionNode; }; -class QQmlObjectCreator +class Q_QML_PRIVATE_EXPORT QQmlObjectCreator { Q_DECLARE_TR_FUNCTIONS(QQmlObjectCreator) public: - QQmlObjectCreator(QQmlContextData *parentContext, QV4::CompiledData::CompilationUnit *compilationUnit, QQmlContextData *creationContext, QQmlIncubatorPrivate *incubator = 0); + QQmlObjectCreator(QQmlContextData *parentContext, QV4::CompiledData::CompilationUnit *compilationUnit, QQmlContextData *creationContext, QQmlIncubatorPrivate *incubator = nullptr); ~QQmlObjectCreator(); - QObject *create(int subComponentIndex = -1, QObject *parent = 0, QQmlInstantiationInterrupt *interrupt = 0); + QObject *create(int subComponentIndex = -1, QObject *parent = nullptr, QQmlInstantiationInterrupt *interrupt = nullptr); bool populateDeferredProperties(QObject *instance, QQmlData::DeferredData *deferredData); + bool populateDeferredBinding(const QQmlProperty &qmlProperty, QQmlData::DeferredData *deferredData, const QV4::CompiledData::Binding *binding); QQmlContextData *finalize(QQmlInstantiationInterrupt &interrupt); - void cancel(QObject *object); void clear(); QQmlComponentAttached **componentAttachment() const { return &sharedState->componentAttached; } @@ -108,7 +108,7 @@ private: void init(QQmlContextData *parentContext); - QObject *createInstance(int index, QObject *parent = 0, bool isContextObject = false); + QObject *createInstance(int index, QObject *parent = nullptr, bool isContextObject = false); bool populateInstance(int index, QObject *instance, QObject *bindingTarget, const QQmlPropertyData *valueTypeProperty); @@ -123,7 +123,8 @@ private: void registerObjectWithContextById(const QV4::CompiledData::Object *object, QObject *instance) const; - QV4::QmlContext *currentQmlContext(); + inline QV4::QmlContext *currentQmlContext(); + Q_NEVER_INLINE void createQmlContext(); enum Phase { Startup, @@ -136,7 +137,7 @@ private: QQmlEngine *engine; QV4::ExecutionEngine *v4; - QV4::CompiledData::CompilationUnit *compilationUnit; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; const QV4::CompiledData::Unit *qmlUnit; QQmlGuardedContextData parentContext; QQmlContextData *context; @@ -173,6 +174,14 @@ private: QRecursionWatcher<QQmlObjectCreatorSharedState, &QQmlObjectCreatorSharedState::recursionNode> watcher; }; +QV4::QmlContext *QQmlObjectCreator::currentQmlContext() +{ + if (!_qmlContext->isManaged()) + _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); + + return _qmlContext; +} + QT_END_NAMESPACE #endif // QQMLOBJECTCREATOR_P_H diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp index fc85030b3d..1b44bbdda3 100644 --- a/src/qml/qml/qqmlopenmetaobject.cpp +++ b/src/qml/qml/qqmlopenmetaobject.cpp @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE class QQmlOpenMetaObjectTypePrivate { public: - QQmlOpenMetaObjectTypePrivate() : mem(0), cache(0), engine(0) {} + QQmlOpenMetaObjectTypePrivate() : mem(nullptr), cache(nullptr), engine(nullptr) {} void init(const QMetaObject *metaObj); @@ -83,7 +83,7 @@ QQmlOpenMetaObjectType::~QQmlOpenMetaObjectType() void QQmlOpenMetaObjectType::clear() { - d->engine = 0; + d->engine = nullptr; } int QQmlOpenMetaObjectType::propertyOffset() const @@ -182,7 +182,7 @@ class QQmlOpenMetaObjectPrivate { public: QQmlOpenMetaObjectPrivate(QQmlOpenMetaObject *_q) - : q(_q), parent(0), type(0), cacheProperties(false) {} + : q(_q), parent(nullptr), type(nullptr), cacheProperties(false) {} inline QPair<QVariant, bool> &getDataRef(int idx) { while (data.count() <= idx) @@ -220,7 +220,7 @@ QQmlOpenMetaObject::QQmlOpenMetaObject(QObject *obj, const QMetaObject *base, bo d->autoCreate = automatic; d->object = obj; - d->type = new QQmlOpenMetaObjectType(base ? base : obj->metaObject(), 0); + d->type = new QQmlOpenMetaObjectType(base ? base : obj->metaObject(), nullptr); d->type->d->referers.insert(this); QObjectPrivate *op = QObjectPrivate::get(obj); @@ -264,7 +264,7 @@ void QQmlOpenMetaObject::emitPropertyNotification(const QByteArray &propertyName QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(propertyName); if (iter == d->type->d->names.constEnd()) return; - activate(d->object, *iter + d->type->d->signalOffset, 0); + activate(d->object, *iter + d->type->d->signalOffset, nullptr); } int QQmlOpenMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void **a) @@ -284,7 +284,7 @@ int QQmlOpenMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void * prop.first = propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0])); prop.second = true; propertyWritten(propId); - activate(o, d->type->d->signalOffset + propId, 0); + activate(o, d->type->d->signalOffset + propId, nullptr); } } return -1; @@ -311,7 +311,7 @@ void QQmlOpenMetaObject::setValue(int id, const QVariant &value) QPair<QVariant, bool> &prop = d->getDataRef(id); prop.first = propertyWriteValue(id, value); prop.second = true; - activate(d->object, id + d->type->d->signalOffset, 0); + activate(d->object, id + d->type->d->signalOffset, nullptr); } QVariant QQmlOpenMetaObject::value(const QByteArray &name) const @@ -353,7 +353,7 @@ bool QQmlOpenMetaObject::setValue(const QByteArray &name, const QVariant &val) return false; dataVal = val; - activate(d->object, id + d->type->d->signalOffset, 0); + activate(d->object, id + d->type->d->signalOffset, nullptr); return true; } @@ -382,7 +382,7 @@ void QQmlOpenMetaObject::setCached(bool c) } else { if (d->type->d->cache) d->type->d->cache->release(); - qmldata->propertyCache = 0; + qmldata->propertyCache = nullptr; } } @@ -395,7 +395,7 @@ int QQmlOpenMetaObject::createProperty(const char *name, const char *) if (QQmlData *ddata = QQmlData::get(d->object, /*create*/false)) { if (ddata->propertyCache) { ddata->propertyCache->release(); - ddata->propertyCache = 0; + ddata->propertyCache = nullptr; } } diff --git a/src/qml/qml/qqmlopenmetaobject_p.h b/src/qml/qml/qqmlopenmetaobject_p.h index 4bb92489a5..4905190b75 100644 --- a/src/qml/qml/qqmlopenmetaobject_p.h +++ b/src/qml/qml/qqmlopenmetaobject_p.h @@ -69,7 +69,7 @@ class Q_QML_PRIVATE_EXPORT QQmlOpenMetaObjectType : public QQmlRefCount, public { public: QQmlOpenMetaObjectType(const QMetaObject *base, QQmlEngine *engine); - ~QQmlOpenMetaObjectType(); + ~QQmlOpenMetaObjectType() override; void createProperties(const QVector<QByteArray> &names); int createProperty(const QByteArray &name); @@ -95,9 +95,9 @@ class QQmlOpenMetaObjectPrivate; class Q_QML_PRIVATE_EXPORT QQmlOpenMetaObject : public QAbstractDynamicMetaObject { public: - QQmlOpenMetaObject(QObject *, const QMetaObject * = 0, bool = true); + QQmlOpenMetaObject(QObject *, const QMetaObject * = nullptr, bool = true); QQmlOpenMetaObject(QObject *, QQmlOpenMetaObjectType *, bool = true); - ~QQmlOpenMetaObject(); + ~QQmlOpenMetaObject() override; QVariant value(const QByteArray &) const; bool setValue(const QByteArray &, const QVariant &); diff --git a/src/qml/qml/qqmlparserstatus.cpp b/src/qml/qml/qqmlparserstatus.cpp index ad07cac7ef..1082c318cb 100644 --- a/src/qml/qml/qqmlparserstatus.cpp +++ b/src/qml/qml/qqmlparserstatus.cpp @@ -87,7 +87,7 @@ QT_BEGIN_NAMESPACE /*! \internal */ QQmlParserStatus::QQmlParserStatus() -: d(0) +: d(nullptr) { } @@ -95,7 +95,7 @@ QQmlParserStatus::QQmlParserStatus() QQmlParserStatus::~QQmlParserStatus() { if(d) - (*d) = 0; + (*d) = nullptr; } /*! diff --git a/src/qml/qml/qqmlplatform_p.h b/src/qml/qml/qqmlplatform_p.h index 6246ca7105..af33dffca3 100644 --- a/src/qml/qml/qqmlplatform_p.h +++ b/src/qml/qml/qqmlplatform_p.h @@ -64,7 +64,7 @@ class Q_QML_PRIVATE_EXPORT QQmlPlatform : public QObject Q_PROPERTY(QString pluginName READ pluginName CONSTANT) public: - explicit QQmlPlatform(QObject *parent = 0); + explicit QQmlPlatform(QObject *parent = nullptr); virtual ~QQmlPlatform(); static QString os(); diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h index eeb5b4c302..fabdcacc36 100644 --- a/src/qml/qml/qqmlprivate.h +++ b/src/qml/qml/qqmlprivate.h @@ -69,7 +69,6 @@ namespace CompiledData { struct Unit; struct CompilationUnit; } -typedef CompiledData::CompilationUnit *(*CompilationUnitFactoryFunction)(); } namespace QmlIR { struct Document; @@ -99,7 +98,7 @@ namespace QQmlPrivate class QQmlElement : public T { public: - virtual ~QQmlElement() { + ~QQmlElement() override { QQmlPrivate::qdeclarativeelement_destructor(this); } }; @@ -168,8 +167,8 @@ namespace QQmlPrivate class AttachedPropertySelector { public: - static inline QQmlAttachedPropertiesFunc func() { return 0; } - static inline const QMetaObject *metaObject() { return 0; } + static inline QQmlAttachedPropertiesFunc func() { return nullptr; } + static inline const QMetaObject *metaObject() { return nullptr; } }; template<typename T> class AttachedPropertySelector<T, 1> @@ -284,8 +283,8 @@ namespace QQmlPrivate struct CachedQmlUnit { const QV4::CompiledData::Unit *qmlData; - QV4::CompilationUnitFactoryFunction createCompilationUnit; - QmlIR::IRLoaderFunction loadIR; + void *unused1; + void *unused2; }; typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url); diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 9a138dcf80..ebf296b29d 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -119,7 +119,7 @@ The \l {Qt Quick 1} version of this class was named QDeclarativeProperty. Create an invalid QQmlProperty. */ QQmlProperty::QQmlProperty() -: d(0) +: d(nullptr) { } @@ -128,7 +128,7 @@ QQmlProperty::~QQmlProperty() { if (d) d->release(); - d = 0; + d = nullptr; } /*! @@ -150,8 +150,8 @@ QQmlProperty::QQmlProperty(QObject *obj) QQmlProperty::QQmlProperty(QObject *obj, QQmlContext *ctxt) : d(new QQmlPropertyPrivate) { - d->context = ctxt?QQmlContextData::get(ctxt):0; - d->engine = ctxt?ctxt->engine():0; + d->context = ctxt?QQmlContextData::get(ctxt):nullptr; + d->engine = ctxt?ctxt->engine():nullptr; d->initDefault(obj); } @@ -164,7 +164,7 @@ QQmlProperty::QQmlProperty(QObject *obj, QQmlContext *ctxt) QQmlProperty::QQmlProperty(QObject *obj, QQmlEngine *engine) : d(new QQmlPropertyPrivate) { - d->context = 0; + d->context = nullptr; d->engine = engine; d->initDefault(obj); } @@ -190,7 +190,7 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name) : d(new QQmlPropertyPrivate) { d->initProperty(obj, name); - if (!isValid()) d->object = 0; + if (!isValid()) d->object = nullptr; } /*! @@ -203,10 +203,10 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name) QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt) : d(new QQmlPropertyPrivate) { - d->context = ctxt?QQmlContextData::get(ctxt):0; - d->engine = ctxt?ctxt->engine():0; + d->context = ctxt?QQmlContextData::get(ctxt):nullptr; + d->engine = ctxt?ctxt->engine():nullptr; d->initProperty(obj, name); - if (!isValid()) { d->object = 0; d->context = 0; d->engine = 0; } + if (!isValid()) { d->object = nullptr; d->context = nullptr; d->engine = nullptr; } } /*! @@ -217,14 +217,30 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt) QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine) : d(new QQmlPropertyPrivate) { - d->context = 0; + d->context = nullptr; d->engine = engine; d->initProperty(obj, name); - if (!isValid()) { d->object = 0; d->context = 0; d->engine = 0; } + if (!isValid()) { d->object = nullptr; d->context = nullptr; d->engine = nullptr; } +} + +QQmlProperty QQmlPropertyPrivate::create(QObject *target, const QString &propertyName, QQmlContextData *context) +{ + QQmlProperty result; + auto d = new QQmlPropertyPrivate; + result.d = d; + d->context = context; + d->engine = context ? context->engine : nullptr; + d->initProperty(target, propertyName); + if (!result.isValid()) { + d->object = nullptr; + d->context = nullptr; + d->engine = nullptr; + } + return result; } QQmlPropertyPrivate::QQmlPropertyPrivate() -: context(0), engine(0), object(0), isNameCached(false) +: context(nullptr), engine(nullptr), object(nullptr), isNameCached(false) { } @@ -232,98 +248,104 @@ QQmlContextData *QQmlPropertyPrivate::effectiveContext() const { if (context) return context; else if (engine) return QQmlContextData::get(engine->rootContext()); - else return 0; + else return nullptr; } void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) { if (!obj) return; - QQmlTypeNameCache *typeNameCache = context?context->imports:0; - - const auto path = name.splitRef(QLatin1Char('.')); - if (path.isEmpty()) return; + QQmlTypeNameCache *typeNameCache = context?context->imports:nullptr; QObject *currentObject = obj; - - // Everything up to the last property must be an "object type" property - for (int ii = 0; ii < path.count() - 1; ++ii) { - const QStringRef &pathName = path.at(ii); - - if (typeNameCache) { - QQmlTypeNameCache::Result r = typeNameCache->query(pathName); - if (r.isValid()) { - if (r.type.isValid()) { - QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - } else if (r.importNamespace) { - if ((ii + 1) == path.count()) return; // No type following the namespace - - ++ii; r = typeNameCache->query(path.at(ii), r.importNamespace); - if (!r.type.isValid()) return; // Invalid type in namespace - - QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - - } else if (r.scriptIndex != -1) { - return; // Not a type - } else { - Q_ASSERT(!"Unreachable"); + QVector<QStringRef> path; + QStringRef terminal(&name); + + if (name.contains(QLatin1Char('.'))) { + path = name.splitRef(QLatin1Char('.')); + if (path.isEmpty()) return; + + // Everything up to the last property must be an "object type" property + for (int ii = 0; ii < path.count() - 1; ++ii) { + const QStringRef &pathName = path.at(ii); + + // Types must begin with an uppercase letter (see checkRegistration() + // in qqmlmetatype.cpp for the enforcement of this). + if (typeNameCache && !pathName.isEmpty() && pathName.at(0).isUpper()) { + QQmlTypeNameCache::Result r = typeNameCache->query(pathName); + if (r.isValid()) { + if (r.type.isValid()) { + QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + } else if (r.importNamespace) { + if ((ii + 1) == path.count()) return; // No type following the namespace + + ++ii; r = typeNameCache->query(path.at(ii), r.importNamespace); + if (!r.type.isValid()) return; // Invalid type in namespace + + QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + + } else if (r.scriptIndex != -1) { + return; // Not a type + } else { + Q_ASSERT(!"Unreachable"); + } + continue; } - continue; + } - } + QQmlPropertyData local; + QQmlPropertyData *property = + QQmlPropertyCache::property(engine, currentObject, pathName, context, local); - QQmlPropertyData local; - QQmlPropertyData *property = - QQmlPropertyCache::property(engine, currentObject, pathName, context, local); + if (!property) return; // Not a property + if (property->isFunction()) + return; // Not an object property - if (!property) return; // Not a property - if (property->isFunction()) - return; // Not an object property + if (ii == (path.count() - 2) && QQmlValueTypeFactory::isValueType(property->propType())) { + // We're now at a value type property + const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(property->propType()); + if (!valueTypeMetaObject) return; // Not a value type - if (ii == (path.count() - 2) && QQmlValueTypeFactory::isValueType(property->propType())) { - // We're now at a value type property - const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(property->propType()); - if (!valueTypeMetaObject) return; // Not a value type + int idx = valueTypeMetaObject->indexOfProperty(path.last().toUtf8().constData()); + if (idx == -1) return; // Value type property does not exist - int idx = valueTypeMetaObject->indexOfProperty(path.last().toUtf8().constData()); - if (idx == -1) return; // Value type property does not exist + QMetaProperty vtProp = valueTypeMetaObject->property(idx); - QMetaProperty vtProp = valueTypeMetaObject->property(idx); + Q_ASSERT(vtProp.userType() <= 0x0000FFFF); + Q_ASSERT(idx <= 0x0000FFFF); - Q_ASSERT(vtProp.userType() <= 0x0000FFFF); - Q_ASSERT(idx <= 0x0000FFFF); + object = currentObject; + core = *property; + valueTypeData.setFlags(QQmlPropertyData::flagsForProperty(vtProp)); + valueTypeData.setPropType(vtProp.userType()); + valueTypeData.setCoreIndex(idx); - object = currentObject; - core = *property; - valueTypeData.setFlags(QQmlPropertyData::flagsForProperty(vtProp)); - valueTypeData.setPropType(vtProp.userType()); - valueTypeData.setCoreIndex(idx); + return; + } else { + if (!property->isQObject()) + return; // Not an object property - return; - } else { - if (!property->isQObject()) - return; // Not an object property + property->readProperty(currentObject, ¤tObject); + if (!currentObject) return; // No value - property->readProperty(currentObject, ¤tObject); - if (!currentObject) return; // No value + } } + terminal = path.last(); } - const QStringRef &terminal = path.last(); - if (terminal.count() >= 3 && terminal.at(0) == QLatin1Char('o') && terminal.at(1) == QLatin1Char('n') && @@ -467,7 +489,7 @@ QQmlPropertyPrivate::propertyTypeCategory() const const char *QQmlProperty::propertyTypeName() const { if (!d) - return 0; + return nullptr; if (d->isValueType()) { const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(d->core.propType()); Q_ASSERT(valueTypeMetaObject); @@ -475,7 +497,7 @@ const char *QQmlProperty::propertyTypeName() const } else if (d->object && type() & Property && d->core.isValid()) { return d->object->metaObject()->property(d->core.coreIndex()).typeName(); } else { - return 0; + return nullptr; } } @@ -559,7 +581,7 @@ bool QQmlProperty::isSignalProperty() const */ QObject *QQmlProperty::object() const { - return d ? d->object : 0; + return d ? d->object : nullptr; } /*! @@ -697,7 +719,7 @@ QQmlAbstractBinding * QQmlPropertyPrivate::binding(const QQmlProperty &that) { if (!that.d || !that.isProperty() || !that.d->object) - return 0; + return nullptr; QQmlPropertyIndex thatIndex(that.d->core.coreIndex(), that.d->valueTypeData.coreIndex()); return binding(that.d->object, thatIndex); @@ -759,7 +781,7 @@ static void removeOldBinding(QObject *object, QQmlPropertyIndex index, QQmlPrope return; if (!(flags & QQmlPropertyPrivate::DontEnable)) - oldBinding->setEnabled(false, 0); + oldBinding->setEnabled(false, nullptr); oldBinding->removeFromObject(); } @@ -793,13 +815,13 @@ QQmlPropertyPrivate::binding(QObject *object, QQmlPropertyIndex index) QQmlData *data = QQmlData::get(object); if (!data) - return 0; + return nullptr; const int coreIndex = index.coreIndex(); const int valueTypeIndex = index.valueTypeIndex(); if (coreIndex < 0 || !data->hasBindingBit(coreIndex)) - return 0; + return nullptr; QQmlAbstractBinding *binding = data->bindings; while (binding && (binding->targetPropertyIndex().coreIndex() != coreIndex || @@ -825,11 +847,11 @@ void QQmlPropertyPrivate::findAliasTarget(QObject *object, QQmlPropertyIndex bin int valueTypeIndex = bindingIndex.valueTypeIndex(); QQmlPropertyData *propertyData = - data->propertyCache?data->propertyCache->property(coreIndex):0; + data->propertyCache?data->propertyCache->property(coreIndex):nullptr; if (propertyData && propertyData->isAlias()) { QQmlVMEMetaObject *vme = QQmlVMEMetaObject::getForProperty(object, coreIndex); - QObject *aObject = 0; int aCoreIndex = -1; int aValueTypeIndex = -1; + QObject *aObject = nullptr; int aCoreIndex = -1; int aValueTypeIndex = -1; if (vme->aliasTarget(coreIndex, &aObject, &aCoreIndex, &aValueTypeIndex)) { // This will either be a value type sub-reference or an alias to a value-type sub-reference not both Q_ASSERT(valueTypeIndex == -1 || aValueTypeIndex == -1); @@ -884,11 +906,11 @@ QQmlBoundSignalExpression * QQmlPropertyPrivate::signalExpression(const QQmlProperty &that) { if (!(that.type() & QQmlProperty::SignalProperty)) - return 0; + return nullptr; QQmlData *data = QQmlData::get(that.d->object); if (!data) - return 0; + return nullptr; QQmlBoundSignal *signalHandler = data->signalHandlers; @@ -898,7 +920,7 @@ QQmlPropertyPrivate::signalExpression(const QQmlProperty &that) if (signalHandler) return signalHandler->expression(); - return 0; + return nullptr; } /*! @@ -925,7 +947,7 @@ void QQmlPropertyPrivate::takeSignalExpression(const QQmlProperty &that, return; } - QQmlData *data = QQmlData::get(that.d->object, 0 != expr); + QQmlData *data = QQmlData::get(that.d->object, nullptr != expr); if (!data) return; @@ -1032,7 +1054,7 @@ QVariant QQmlPropertyPrivate::readValueProperty() } else if (core.isQObject()) { - QObject *rv = 0; + QObject *rv = nullptr; core.readProperty(object, &rv); return QVariant::fromValue(rv); @@ -1043,11 +1065,11 @@ QVariant QQmlPropertyPrivate::readValueProperty() QVariant value; int status = -1; - void *args[] = { 0, &value, &status }; + void *args[] = { nullptr, &value, &status }; if (core.propType() == QMetaType::QVariant) { args[0] = &value; } else { - value = QVariant(core.propType(), (void*)0); + value = QVariant(core.propType(), (void*)nullptr); args[0] = value.data(); } core.readPropertyWithArgs(object, args); @@ -1406,7 +1428,7 @@ QQmlMetaObject QQmlPropertyPrivate::rawMetaObjectForType(QQmlEnginePrivate *engi */ bool QQmlProperty::write(const QVariant &value) const { - return QQmlPropertyPrivate::write(*this, value, 0); + return QQmlPropertyPrivate::write(*this, value, nullptr); } /*! @@ -1475,7 +1497,7 @@ bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &v bool QQmlProperty::reset() const { if (isResettable()) { - void *args[] = { 0 }; + void *args[] = { nullptr }; QMetaObject::metacall(d->object, QMetaObject::ResetProperty, d->core.coreIndex(), args); return true; } else { diff --git a/src/qml/qml/qqmlproperty_p.h b/src/qml/qml/qqmlproperty_p.h index 53062a2f13..544eab4c7f 100644 --- a/src/qml/qml/qqmlproperty_p.h +++ b/src/qml/qml/qqmlproperty_p.h @@ -104,9 +104,9 @@ public: static bool writeValueProperty(QObject *, const QQmlPropertyData &, const QQmlPropertyData &valueTypeData, const QVariant &, QQmlContextData *, - QQmlPropertyData::WriteFlags flags = 0); + QQmlPropertyData::WriteFlags flags = nullptr); static bool write(QObject *, const QQmlPropertyData &, const QVariant &, - QQmlContextData *, QQmlPropertyData::WriteFlags flags = 0); + QQmlContextData *, QQmlPropertyData::WriteFlags flags = nullptr); static void findAliasTarget(QObject *, QQmlPropertyIndex, QObject **, QQmlPropertyIndex *); enum BindingFlag { @@ -140,10 +140,12 @@ public: static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &); static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, - int type = 0, int *types = 0); + int type = 0, int *types = nullptr); static void flushSignal(const QObject *sender, int signal_index); static QVariant resolvedUrlSequence(const QVariant &value, QQmlContextData *context); + static QQmlProperty create(QObject *target, const QString &propertyName, QQmlContextData *context); + }; Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags) diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 7178dffa8b..88eda9c020 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -243,9 +243,9 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m) Creates a new empty QQmlPropertyCache. */ QQmlPropertyCache::QQmlPropertyCache() - : _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), + : _parent(nullptr), propertyIndexCacheStart(0), methodIndexCacheStart(0), signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), - _metaObject(0), argumentsCache(0), _jsFactoryMethodIndex(-1) + _metaObject(nullptr), argumentsCache(nullptr), _jsFactoryMethodIndex(-1) { } @@ -277,8 +277,8 @@ QQmlPropertyCache::~QQmlPropertyCache() if (_parent) _parent->release(); if (_ownMetaObject) free(const_cast<QMetaObject *>(_metaObject)); - _metaObject = 0; - _parent = 0; + _metaObject = nullptr; + _parent = nullptr; } QQmlPropertyCache *QQmlPropertyCache::copy(int reserve) @@ -310,7 +310,7 @@ QQmlPropertyCache *QQmlPropertyCache::copyAndReserve(int propertyCount, int meth rv->methodIndexCache.reserve(methodCount); rv->signalHandlerIndexCache.reserve(signalCount); rv->enumCache.reserve(enumCount); - rv->_metaObject = 0; + rv->_metaObject = nullptr; return rv; } @@ -321,13 +321,14 @@ QQmlPropertyCache *QQmlPropertyCache::copyAndReserve(int propertyCount, int meth This is different from QMetaMethod::methodIndex(). */ void QQmlPropertyCache::appendProperty(const QString &name, QQmlPropertyData::Flags flags, - int coreIndex, int propType, int notifyIndex) + int coreIndex, int propType, int minorVersion, int notifyIndex) { QQmlPropertyData data; data.setPropType(propType); data.setCoreIndex(coreIndex); data.setNotifyIndex(notifyIndex); data.setFlags(flags); + data.setTypeMinorVersion(minorVersion); QQmlPropertyData *old = findNamedProperty(name); if (old) @@ -336,7 +337,7 @@ void QQmlPropertyCache::appendProperty(const QString &name, QQmlPropertyData::Fl int index = propertyIndexCache.count(); propertyIndexCache.append(data); - setNamedProperty(name, index + propertyOffset(), propertyIndexCache.data() + index, (old != 0)); + setNamedProperty(name, index + propertyOffset(), propertyIndexCache.data() + index, (old != nullptr)); } void QQmlPropertyCache::appendSignal(const QString &name, QQmlPropertyData::Flags flags, @@ -373,8 +374,8 @@ void QQmlPropertyCache::appendSignal(const QString &name, QQmlPropertyData::Flag QString handlerName = QLatin1String("on") + name; handlerName[2] = handlerName.at(2).toUpper(); - setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0)); - setNamedProperty(handlerName, signalHandlerIndex + signalOffset(), signalHandlerIndexCache.data() + signalHandlerIndex, (old != 0)); + setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != nullptr)); + setNamedProperty(handlerName, signalHandlerIndex + signalOffset(), signalHandlerIndexCache.data() + signalHandlerIndex, (old != nullptr)); } void QQmlPropertyCache::appendMethod(const QString &name, QQmlPropertyData::Flags flags, @@ -401,7 +402,7 @@ void QQmlPropertyCache::appendMethod(const QString &name, QQmlPropertyData::Flag int methodIndex = methodIndexCache.count(); methodIndexCache.append(data); - setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != 0)); + setNamedProperty(name, methodIndex + methodOffset(), methodIndexCache.data() + methodIndex, (old != nullptr)); } void QQmlPropertyCache::appendEnum(const QString &name, const QVector<QQmlEnumValue> &values) @@ -429,7 +430,7 @@ const QMetaObject *QQmlPropertyCache::createMetaObject() QQmlPropertyData *QQmlPropertyCache::defaultProperty() const { - return property(defaultPropertyName(), 0, 0); + return property(defaultPropertyName(), nullptr, nullptr); } void QQmlPropertyCache::setParent(QQmlPropertyCache *newParent) @@ -542,7 +543,7 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, } QQmlPropertyData *data = &methodIndexCache[ii - methodIndexCacheStart]; - QQmlPropertyData *sigdata = 0; + QQmlPropertyData *sigdata = nullptr; if (m.methodType() == QMetaMethod::Signal) data->setFlags(signalFlags); @@ -561,24 +562,24 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, sigdata->_flags.isSignalHandler = true; } - QQmlPropertyData *old = 0; + QQmlPropertyData *old = nullptr; if (utf8) { QHashedString methodName(QString::fromUtf8(rawName, cptr - rawName)); if (StringCache::mapped_type *it = stringCache.value(methodName)) old = it->second; - setNamedProperty(methodName, ii, data, (old != 0)); + setNamedProperty(methodName, ii, data, (old != nullptr)); if (data->isSignal()) { QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % methodName.midRef(1)); - setNamedProperty(on, ii, sigdata, (old != 0)); + setNamedProperty(on, ii, sigdata, (old != nullptr)); ++signalHandlerIndex; } } else { QHashedCStringRef methodName(rawName, cptr - rawName); if (StringCache::mapped_type *it = stringCache.value(methodName)) old = it->second; - setNamedProperty(methodName, ii, data, (old != 0)); + setNamedProperty(methodName, ii, data, (old != nullptr)); if (data->isSignal()) { int length = methodName.length(); @@ -592,7 +593,7 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, str[length + 2] = '\0'; QHashedString on(QString::fromLatin1(str.data())); - setNamedProperty(on, ii, data, (old != 0)); + setNamedProperty(on, ii, data, (old != nullptr)); ++signalHandlerIndex; } } @@ -635,18 +636,18 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX); data->setMetaObjectOffset(allowedRevisionCache.count() - 1); - QQmlPropertyData *old = 0; + QQmlPropertyData *old = nullptr; if (utf8) { QHashedString propName(QString::fromUtf8(str, cptr - str)); if (StringCache::mapped_type *it = stringCache.value(propName)) old = it->second; - setNamedProperty(propName, ii, data, (old != 0)); + setNamedProperty(propName, ii, data, (old != nullptr)); } else { QHashedCStringRef propName(str, cptr - str); if (StringCache::mapped_type *it = stringCache.value(propName)) old = it->second; - setNamedProperty(propName, ii, data, (old != 0)); + setNamedProperty(propName, ii, data, (old != nullptr)); } bool isGadget = true; @@ -749,7 +750,7 @@ void QQmlPropertyCache::invalidate(const QMetaObject *metaObject) signalHandlerIndexCache.clear(); _hasPropertyOverrides = false; - argumentsCache = 0; + argumentsCache = nullptr; int pc = metaObject->propertyCount(); int mc = metaObject->methodCount(); @@ -772,8 +773,8 @@ void QQmlPropertyCache::invalidate(const QMetaObject *metaObject) QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, QObject *object, QQmlContextData *context) const { - QQmlData *data = (object ? QQmlData::get(object) : 0); - const QQmlVMEMetaObject *vmemo = 0; + QQmlData *data = (object ? QQmlData::get(object) : nullptr); + const QQmlVMEMetaObject *vmemo = nullptr; if (data && data->hasVMEMetaObject) { QObjectPrivate *op = QObjectPrivate::get(object); vmemo = static_cast<const QQmlVMEMetaObject *>(op->metaObject); @@ -848,7 +849,7 @@ QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, return ensureResolved(result); } - return 0; + return nullptr; } QString QQmlPropertyData::name(QObject *object) const @@ -918,9 +919,9 @@ QQmlPropertyCacheMethodArguments *QQmlPropertyCache::createArgumentsObject(int a A *args = static_cast<A *>(malloc(sizeof(A) + (argc) * sizeof(int))); args->arguments[0] = argc; args->argumentsValid = false; - args->signalParameterStringForJS = 0; + args->signalParameterStringForJS = nullptr; args->parameterError = false; - args->names = argc ? new QList<QByteArray>(names) : 0; + args->names = argc ? new QList<QByteArray>(names) : nullptr; args->next = argumentsCache; argumentsCache = args; return args; @@ -1026,10 +1027,10 @@ static QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject, c } /* If the "cmo" variable didn't change, set it to 0 to * avoid running into an infinite loop */ - if (!changed) cmo = 0; + if (!changed) cmo = nullptr; } } else { - cmo = 0; + cmo = nullptr; } } } @@ -1056,7 +1057,7 @@ QQmlPropertyData * qQmlPropertyCacheProperty(QJSEngine *engine, QObject *obj, T name, QQmlContextData *context, QQmlPropertyData &local) { - QQmlPropertyCache *cache = 0; + QQmlPropertyCache *cache = nullptr; QQmlData *ddata = QQmlData::get(obj, false); @@ -1072,7 +1073,7 @@ qQmlPropertyCacheProperty(QJSEngine *engine, QObject *obj, T name, } } - QQmlPropertyData *rv = 0; + QQmlPropertyData *rv = nullptr; if (cache) { rv = cache->property(name, obj, context); @@ -1213,7 +1214,7 @@ void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder) // '+=' reserves extra capacity. Follow-up appending will be probably free. signature += methods.at(ii).first.toUtf8() + '('; - QQmlPropertyCacheMethodArguments *arguments = 0; + QQmlPropertyCacheMethodArguments *arguments = nullptr; if (data->hasArguments()) { arguments = (QQmlPropertyCacheMethodArguments *)data->arguments(); Q_ASSERT(arguments->argumentsValid); @@ -1251,7 +1252,7 @@ void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder) } if (!_defaultPropertyName.isEmpty()) { - QQmlPropertyData *dp = property(_defaultPropertyName, 0, 0); + QQmlPropertyData *dp = property(_defaultPropertyName, nullptr, nullptr); if (dp && dp->coreIndex() >= propertyIndexCacheStart) { Q_ASSERT(!dp->isFunction()); builder.addClassInfo("DefaultProperty", _defaultPropertyName.toUtf8()); @@ -1576,7 +1577,7 @@ void QQmlMetaObject::resolveGadgetMethodOrPropertyIndex(QMetaObject::Call type, QQmlPropertyCache *QQmlMetaObject::propertyCache(QQmlEnginePrivate *e) const { - if (_m.isNull()) return 0; + if (_m.isNull()) return nullptr; if (_m.isT1()) return _m.asT1(); else return e->cache(_m.asT2()); } @@ -1587,7 +1588,7 @@ int QQmlMetaObject::methodReturnType(const QQmlPropertyData &data, QByteArray *u int type = data.propType(); - const char *propTypeName = 0; + const char *propTypeName = nullptr; if (type == QMetaType::UnknownType) { // Find the return type name from the method info @@ -1675,7 +1676,7 @@ int *QQmlMetaObject::methodParameterTypes(int index, ArgTypeStorage *argStorage, } if (type == QMetaType::UnknownType) { if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii); - return 0; + return nullptr; } args->arguments[ii + 1] = type; } @@ -1714,7 +1715,7 @@ int *QQmlMetaObject::methodParameterTypes(const QMetaMethod &m, ArgTypeStorage * } if (type == QMetaType::UnknownType) { if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii); - return 0; + return nullptr; } argStorage->operator[](ii + 1) = type; } @@ -1726,7 +1727,7 @@ void QQmlObjectOrGadget::metacall(QMetaObject::Call type, int index, void **argv { if (ptr.isNull()) { const QMetaObject *metaObject = _m.asT2(); - metaObject->d.static_metacall(0, type, index, argv); + metaObject->d.static_metacall(nullptr, type, index, argv); } else if (ptr.isT1()) { QMetaObject::metacall(ptr.asT1(), type, index, argv); diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 6f4879baa2..5553fe6b80 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -245,12 +245,36 @@ public: _coreIndex = qint16(idx); } - int revision() const { return _revision; } - void setRevision(int rev) + quint8 revision() const { return _revision; } + void setRevision(quint8 rev) { - Q_ASSERT(rev >= std::numeric_limits<qint16>::min()); - Q_ASSERT(rev <= std::numeric_limits<qint16>::max()); - _revision = qint16(rev); + Q_ASSERT(rev <= std::numeric_limits<quint8>::max()); + _revision = quint8(rev); + } + + /* If a property is a C++ type, then we store the minor + * version of this type. + * This is required to resolve property or signal revisions + * if this property is used as a grouped property. + * + * Test.qml + * property TextEdit someTextEdit: TextEdit {} + * + * Test { + * someTextEdit.preeditText: "test" //revision 7 + * someTextEdit.onEditingFinished: console.log("test") //revision 6 + * } + * + * To determine if these properties with revisions are available we need + * the minor version of TextEdit as imported in Test.qml. + * + */ + + quint8 typeMinorVersion() const { return _typeMinorVersion; } + void setTypeMinorVersion(quint8 rev) + { + Q_ASSERT(rev <= std::numeric_limits<quint8>::max()); + _typeMinorVersion = quint8(rev); } QQmlPropertyCacheMethodArguments *arguments() const { return _arguments; } @@ -284,7 +308,8 @@ private: qint16 _notifyIndex; qint16 _overrideIndex; - qint16 _revision; + quint8 _revision; + quint8 _typeMinorVersion; qint16 _metaObjectOffset; QQmlPropertyCacheMethodArguments *_arguments; @@ -325,7 +350,7 @@ public: inline void readProperty(QObject *target, void *property) const { - void *args[] = { property, 0 }; + void *args[] = { property, nullptr }; readPropertyWithArgs(target, args); } @@ -342,7 +367,7 @@ public: bool writeProperty(QObject *target, void *value, WriteFlags flags) const { int status = -1; - void *argv[] = { value, 0, &status, &flags }; + void *argv[] = { value, nullptr, &status, &flags }; if (flags.testFlag(BypassInterceptor) && hasStaticMetaCallFunction()) staticMetaCallFunction()(target, QMetaObject::WriteProperty, relativePropertyIndex(), argv); else if (flags.testFlag(BypassInterceptor) && isDirect()) @@ -378,10 +403,10 @@ private: struct QQmlEnumValue { - QQmlEnumValue() : value(-1) {} + QQmlEnumValue() {} QQmlEnumValue(const QString &n, int v) : namedValue(n), value(v) {} QString namedValue; - int value; + int value = -1; }; struct QQmlEnumData @@ -396,7 +421,7 @@ class Q_QML_PRIVATE_EXPORT QQmlPropertyCache : public QQmlRefCount public: QQmlPropertyCache(); QQmlPropertyCache(const QMetaObject *); - virtual ~QQmlPropertyCache(); + ~QQmlPropertyCache() override; void update(const QMetaObject *); void invalidate(const QMetaObject *); @@ -417,9 +442,9 @@ public: QQmlPropertyCache *copyAndReserve(int propertyCount, int methodCount, int signalCount, int enumCount); void appendProperty(const QString &, QQmlPropertyRawData::Flags flags, int coreIndex, - int propType, int notifyIndex); + int propType, int revision, int notifyIndex); void appendSignal(const QString &, QQmlPropertyRawData::Flags, int coreIndex, - const int *types = 0, const QList<QByteArray> &names = QList<QByteArray>()); + const int *types = nullptr, const QList<QByteArray> &names = QList<QByteArray>()); void appendMethod(const QString &, QQmlPropertyData::Flags flags, int coreIndex, const QList<QByteArray> &names = QList<QByteArray>()); void appendEnum(const QString &, const QVector<QQmlEnumValue> &); @@ -467,7 +492,7 @@ public: static int originalClone(QObject *, int index); QList<QByteArray> signalParameterNames(int index) const; - static QString signalParameterStringForJS(QV4::ExecutionEngine *engine, const QList<QByteArray> ¶meterNameList, QString *errorString = 0); + static QString signalParameterStringForJS(QV4::ExecutionEngine *engine, const QList<QByteArray> ¶meterNameList, QString *errorString = nullptr); const char *className() const; @@ -741,7 +766,7 @@ inline const QMetaObject *QQmlPropertyCache::metaObject() const // QML inline const QMetaObject *QQmlPropertyCache::firstCppMetaObject() const { - while (_parent && (_metaObject == 0 || _ownMetaObject)) + while (_parent && (_metaObject == nullptr || _ownMetaObject)) return _parent->firstCppMetaObject(); return _metaObject; } @@ -749,7 +774,7 @@ inline const QMetaObject *QQmlPropertyCache::firstCppMetaObject() const inline QQmlPropertyData *QQmlPropertyCache::property(int index) const { if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count())) - return 0; + return nullptr; if (index < propertyIndexCacheStart) return _parent->property(index); @@ -761,7 +786,7 @@ inline QQmlPropertyData *QQmlPropertyCache::property(int index) const inline QQmlPropertyData *QQmlPropertyCache::method(int index) const { if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count())) - return 0; + return nullptr; if (index < methodIndexCacheStart) return _parent->method(index); @@ -777,7 +802,7 @@ inline QQmlPropertyData *QQmlPropertyCache::method(int index) const inline QQmlPropertyData *QQmlPropertyCache::signal(int index) const { if (index < 0 || index >= (signalHandlerIndexCacheStart + signalHandlerIndexCache.count())) - return 0; + return nullptr; if (index < signalHandlerIndexCacheStart) return _parent->signal(index); @@ -790,7 +815,7 @@ inline QQmlPropertyData *QQmlPropertyCache::signal(int index) const inline QQmlEnumData *QQmlPropertyCache::qmlEnum(int index) const { if (index < 0 || index >= enumCache.count()) - return 0; + return nullptr; return const_cast<QQmlEnumData *>(&enumCache.at(index)); } @@ -821,7 +846,7 @@ QQmlPropertyData * QQmlPropertyCache::overrideData(QQmlPropertyData *data) const { if (!data->hasOverride()) - return 0; + return nullptr; if (data->overrideIndexIsProperty()) return property(data->overrideIndex()); @@ -923,7 +948,7 @@ bool QQmlMetaObject::isNull() const const char *QQmlMetaObject::className() const { if (_m.isNull()) { - return 0; + return nullptr; } else if (_m.isT1()) { return _m.asT1()->className(); } else { @@ -949,7 +974,7 @@ bool QQmlMetaObject::hasMetaObject() const const QMetaObject *QQmlMetaObject::metaObject() const { - if (_m.isNull()) return 0; + if (_m.isNull()) return nullptr; if (_m.isT1()) return _m.asT1()->createMetaObject(); else return _m.asT2(); } diff --git a/src/qml/qml/qqmlpropertyvalueinterceptor.cpp b/src/qml/qml/qqmlpropertyvalueinterceptor.cpp index 52c003ab59..603245f29d 100644 --- a/src/qml/qml/qqmlpropertyvalueinterceptor.cpp +++ b/src/qml/qml/qqmlpropertyvalueinterceptor.cpp @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE /*! Constructs a QQmlPropertyValueInterceptor. */ -QQmlPropertyValueInterceptor::QQmlPropertyValueInterceptor() : m_next(0) +QQmlPropertyValueInterceptor::QQmlPropertyValueInterceptor() : m_next(nullptr) { } diff --git a/src/qml/qml/qqmlproxymetaobject.cpp b/src/qml/qml/qqmlproxymetaobject.cpp index 27e3c13ff8..e1500f70fb 100644 --- a/src/qml/qml/qqmlproxymetaobject.cpp +++ b/src/qml/qml/qqmlproxymetaobject.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE QQmlProxyMetaObject::QQmlProxyMetaObject(QObject *obj, QList<ProxyData> *mList) -: metaObjects(mList), proxies(0), parent(0), object(obj) +: metaObjects(mList), proxies(nullptr), parent(nullptr), object(obj) { *static_cast<QMetaObject *>(this) = *metaObjects->constFirst().metaObject; @@ -58,11 +58,11 @@ QQmlProxyMetaObject::~QQmlProxyMetaObject() { if (parent) delete parent; - parent = 0; + parent = nullptr; if (proxies) delete [] proxies; - proxies = 0; + proxies = nullptr; } int QQmlProxyMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void **a) diff --git a/src/qml/qml/qqmlscriptstring_p.h b/src/qml/qml/qqmlscriptstring_p.h index 2dfb817186..fd8ccd5d53 100644 --- a/src/qml/qml/qqmlscriptstring_p.h +++ b/src/qml/qml/qqmlscriptstring_p.h @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE class Q_AUTOTEST_EXPORT QQmlScriptStringPrivate : public QSharedData { public: - QQmlScriptStringPrivate() : context(0), scope(0), bindingId(-1), lineNumber(0), columnNumber(0), + QQmlScriptStringPrivate() : context(nullptr), scope(nullptr), bindingId(-1), lineNumber(0), columnNumber(0), numberValue(0), isStringLiteral(false), isNumberLiteral(false) {} //for testing diff --git a/src/qml/qml/qqmlstringconverters_p.h b/src/qml/qml/qqmlstringconverters_p.h index af344e3344..215f0c0aaf 100644 --- a/src/qml/qml/qqmlstringconverters_p.h +++ b/src/qml/qml/qqmlstringconverters_p.h @@ -67,19 +67,19 @@ class QByteArray; namespace QQmlStringConverters { Q_QML_PRIVATE_EXPORT QVariant variantFromString(const QString &); - Q_QML_PRIVATE_EXPORT QVariant variantFromString(const QString &, int preferredType, bool *ok = 0); + Q_QML_PRIVATE_EXPORT QVariant variantFromString(const QString &, int preferredType, bool *ok = nullptr); - Q_QML_PRIVATE_EXPORT QVariant colorFromString(const QString &, bool *ok = 0); - Q_QML_PRIVATE_EXPORT unsigned rgbaFromString(const QString &, bool *ok = 0); + Q_QML_PRIVATE_EXPORT QVariant colorFromString(const QString &, bool *ok = nullptr); + Q_QML_PRIVATE_EXPORT unsigned rgbaFromString(const QString &, bool *ok = nullptr); #if QT_CONFIG(datestring) - Q_QML_PRIVATE_EXPORT QDate dateFromString(const QString &, bool *ok = 0); - Q_QML_PRIVATE_EXPORT QTime timeFromString(const QString &, bool *ok = 0); - Q_QML_PRIVATE_EXPORT QDateTime dateTimeFromString(const QString &, bool *ok = 0); + Q_QML_PRIVATE_EXPORT QDate dateFromString(const QString &, bool *ok = nullptr); + Q_QML_PRIVATE_EXPORT QTime timeFromString(const QString &, bool *ok = nullptr); + Q_QML_PRIVATE_EXPORT QDateTime dateTimeFromString(const QString &, bool *ok = nullptr); #endif - Q_QML_PRIVATE_EXPORT QPointF pointFFromString(const QString &, bool *ok = 0); - Q_QML_PRIVATE_EXPORT QSizeF sizeFFromString(const QString &, bool *ok = 0); - Q_QML_PRIVATE_EXPORT QRectF rectFFromString(const QString &, bool *ok = 0); + Q_QML_PRIVATE_EXPORT QPointF pointFFromString(const QString &, bool *ok = nullptr); + Q_QML_PRIVATE_EXPORT QSizeF sizeFFromString(const QString &, bool *ok = nullptr); + Q_QML_PRIVATE_EXPORT QRectF rectFFromString(const QString &, bool *ok = nullptr); Q_QML_PRIVATE_EXPORT bool createFromString(int, const QString &, void *, size_t); } diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 9285328892..5212b49670 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -156,8 +156,8 @@ public: void loadAsync(QQmlDataBlob *b); void loadWithStaticData(QQmlDataBlob *b, const QByteArray &); void loadWithStaticDataAsync(QQmlDataBlob *b, const QByteArray &); - void loadWithCachedUnit(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit); - void loadWithCachedUnitAsync(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit); + void loadWithCachedUnit(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit); + void loadWithCachedUnitAsync(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit); void callCompleted(QQmlDataBlob *b); void callDownloadProgressChanged(QQmlDataBlob *b, qreal p); void initializeEngine(QQmlExtensionInterface *, const char *); @@ -168,7 +168,7 @@ protected: private: void loadThread(QQmlDataBlob *b); void loadWithStaticDataThread(QQmlDataBlob *b, const QByteArray &); - void loadWithCachedUnitThread(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit); + void loadWithCachedUnitThread(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit); void callCompletedMain(QQmlDataBlob *b); void callDownloadProgressChangedMain(QQmlDataBlob *b, qreal p); void initializeEngineMain(QQmlExtensionInterface *iface, const char *uri); @@ -317,7 +317,8 @@ Returns true if the status is WaitingForDependencies. */ bool QQmlDataBlob::isWaiting() const { - return status() == WaitingForDependencies; + return status() == WaitingForDependencies || + status() == ResolvingDependencies; } /*! @@ -356,8 +357,10 @@ qreal QQmlDataBlob::progress() const } /*! -Returns the blob url passed to the constructor. If a network redirect -happens while fetching the data, this url remains the same. +Returns the physical url of the data. Initially this is the same as +finalUrl(), but if a network redirect happens while fetching the data, this url +is updated to reflect the new location. Also, if a URL interceptor is set, it +will work on this URL and leave finalUrl() alone. \sa finalUrl() */ @@ -366,16 +369,25 @@ QUrl QQmlDataBlob::url() const return m_url; } +QString QQmlDataBlob::urlString() const +{ + if (m_urlString.isEmpty()) + m_urlString = m_url.toString(); + + return m_urlString; +} + /*! -Returns the final url of the data. Initially this is the same as -url(), but if a network redirect happens while fetching the data, this url -is updated to reflect the new location. +Returns the logical URL to be used for resolving further URLs referred to in +the code. -May only be called from the load thread, or after the blob isCompleteOrError(). +This is the blob url passed to the constructor. If a network redirect +happens while fetching the data, this url remains the same. + +\sa url() */ QUrl QQmlDataBlob::finalUrl() const { - Q_ASSERT(isCompleteOrError() || (m_typeLoader && m_typeLoader->m_thread->isThisThread())); return m_finalUrl; } @@ -384,7 +396,6 @@ Returns the finalUrl() as a string. */ QString QQmlDataBlob::finalUrlString() const { - Q_ASSERT(isCompleteOrError() || (m_typeLoader && m_typeLoader->m_thread->isThisThread())); if (m_finalUrlString.isEmpty()) m_finalUrlString = m_finalUrl.toString(); @@ -433,7 +444,7 @@ void QQmlDataBlob::setError(const QList<QQmlError> &errors) m_data.setStatus(Error); if (dumpErrors()) { - qWarning().nospace() << "Errors for " << m_finalUrl.toString(); + qWarning().nospace() << "Errors for " << urlString(); for (int ii = 0; ii < errors.count(); ++ii) qWarning().nospace() << " " << qPrintable(errors.at(ii).toString()); } @@ -472,7 +483,7 @@ void QQmlDataBlob::setError(const QString &description) { QQmlError e; e.setDescription(description); - e.setUrl(finalUrl()); + e.setUrl(url()); setError(e); } @@ -538,9 +549,9 @@ void QQmlDataBlob::networkError(QNetworkReply::NetworkError networkError) Q_UNUSED(networkError); QQmlError error; - error.setUrl(m_finalUrl); + error.setUrl(m_url); - const char *errorString = 0; + const char *errorString = nullptr; switch (networkError) { default: errorString = "Network error"; @@ -610,6 +621,7 @@ The default implementation does nothing. */ void QQmlDataBlob::allDependenciesDone() { + m_data.setStatus(QQmlDataBlob::ResolvingDependencies); } /*! @@ -654,7 +666,7 @@ void QQmlDataBlob::tryDone() addref(); #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob::done() %s", qPrintable(url().toString())); + qWarning("QQmlDataBlob::done() %s", qPrintable(urlString())); #endif done(); @@ -780,7 +792,7 @@ void QQmlDataBlob::ThreadData::setProgress(quint8 v) QQmlTypeLoaderThread::QQmlTypeLoaderThread(QQmlTypeLoader *loader) : m_loader(loader) #if QT_CONFIG(qml_network) -, m_networkAccessManager(0), m_networkReplyProxy(0) +, m_networkAccessManager(nullptr), m_networkReplyProxy(nullptr) #endif // qml_network { // Do that after initializing all the members. @@ -792,7 +804,7 @@ QNetworkAccessManager *QQmlTypeLoaderThread::networkAccessManager() const { Q_ASSERT(isThisThread()); if (!m_networkAccessManager) { - m_networkAccessManager = QQmlEnginePrivate::get(m_loader->engine())->createNetworkAccessManager(0); + m_networkAccessManager = QQmlEnginePrivate::get(m_loader->engine())->createNetworkAccessManager(nullptr); m_networkReplyProxy = new QQmlTypeLoaderNetworkReplyProxy(m_loader); } @@ -831,13 +843,13 @@ void QQmlTypeLoaderThread::loadWithStaticDataAsync(QQmlDataBlob *b, const QByteA postMethodToThread(&This::loadWithStaticDataThread, b, d); } -void QQmlTypeLoaderThread::loadWithCachedUnit(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeLoaderThread::loadWithCachedUnit(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit) { b->addref(); callMethodInThread(&This::loadWithCachedUnitThread, b, unit); } -void QQmlTypeLoaderThread::loadWithCachedUnitAsync(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeLoaderThread::loadWithCachedUnitAsync(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit) { b->addref(); postMethodToThread(&This::loadWithCachedUnitThread, b, unit); @@ -865,9 +877,9 @@ void QQmlTypeLoaderThread::shutdownThread() { #if QT_CONFIG(qml_network) delete m_networkAccessManager; - m_networkAccessManager = 0; + m_networkAccessManager = nullptr; delete m_networkReplyProxy; - m_networkReplyProxy = 0; + m_networkReplyProxy = nullptr; #endif // qml_network } @@ -883,7 +895,7 @@ void QQmlTypeLoaderThread::loadWithStaticDataThread(QQmlDataBlob *b, const QByte b->release(); } -void QQmlTypeLoaderThread::loadWithCachedUnitThread(QQmlDataBlob *b, const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeLoaderThread::loadWithCachedUnitThread(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit) { m_loader->loadWithCachedUnitThread(b, unit); b->release(); @@ -893,7 +905,7 @@ void QQmlTypeLoaderThread::callCompletedMain(QQmlDataBlob *b) { QML_MEMORY_SCOPE_URL(b->url()); #ifdef DATABLOB_DEBUG - qWarning("QQmlTypeLoaderThread: %s completed() callback", qPrintable(b->url().toString())); + qWarning("QQmlTypeLoaderThread: %s completed() callback", qPrintable(b->urlString())); #endif b->completed(); b->release(); @@ -903,7 +915,7 @@ void QQmlTypeLoaderThread::callDownloadProgressChangedMain(QQmlDataBlob *b, qrea { #ifdef DATABLOB_DEBUG qWarning("QQmlTypeLoaderThread: %s downloadProgressChanged(%f) callback", - qPrintable(b->url().toString()), p); + qPrintable(b->urlString()), p); #endif b->downloadProgressChanged(p); b->release(); @@ -951,7 +963,7 @@ void QQmlTypeLoader::invalidate() if (m_thread) { shutdownThread(); delete m_thread; - m_thread = 0; + m_thread = nullptr; } #if QT_CONFIG(qml_network) @@ -1021,8 +1033,8 @@ struct StaticLoader { }; struct CachedLoader { - const QQmlPrivate::CachedQmlUnit *unit; - CachedLoader(const QQmlPrivate::CachedQmlUnit *unit) : unit(unit) {} + const QV4::CompiledData::Unit *unit; + CachedLoader(const QV4::CompiledData::Unit *unit) : unit(unit) {} void loadThread(QQmlTypeLoader *loader, QQmlDataBlob *blob) const { @@ -1042,7 +1054,7 @@ template<typename Loader> void QQmlTypeLoader::doLoad(const Loader &loader, QQmlDataBlob *blob, Mode mode) { #ifdef DATABLOB_DEBUG - qWarning("QQmlTypeLoader::doLoad(%s): %s thread", qPrintable(blob->m_url.toString()), + qWarning("QQmlTypeLoader::doLoad(%s): %s thread", qPrintable(blob->urlString()), m_thread->isThisThread()?"Compile":"Engine"); #endif #ifdef Q_OS_HTML5 @@ -1095,7 +1107,7 @@ void QQmlTypeLoader::loadWithStaticData(QQmlDataBlob *blob, const QByteArray &da doLoad(StaticLoader(data), blob, mode); } -void QQmlTypeLoader::loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode) +void QQmlTypeLoader::loadWithCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit, Mode mode) { doLoad(CachedLoader(unit), blob, mode); } @@ -1107,7 +1119,7 @@ void QQmlTypeLoader::loadWithStaticDataThread(QQmlDataBlob *blob, const QByteArr setData(blob, data); } -void QQmlTypeLoader::loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeLoader::loadWithCachedUnitThread(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit) { ASSERT_LOADTHREAD(); @@ -1165,7 +1177,7 @@ void QQmlTypeLoader::loadThread(QQmlDataBlob *blob) } #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob: requested %s", qPrintable(blob->url().toString())); + qWarning("QQmlDataBlob: requested %s", qPrintable(blob->urlString())); #endif // DATABLOB_DEBUG #endif // qml_network } @@ -1191,14 +1203,15 @@ void QQmlTypeLoader::networkReplyFinished(QNetworkReply *reply) QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (redirect.isValid()) { QUrl url = reply->url().resolved(redirect.toUrl()); - blob->m_finalUrl = url; + blob->m_url = url; + blob->m_urlString.clear(); QNetworkReply *reply = m_thread->networkAccessManager()->get(QNetworkRequest(url)); QObject *nrp = m_thread->networkReplyProxy(); QObject::connect(reply, SIGNAL(finished()), nrp, SLOT(finished())); m_networkReplies.insert(reply, blob); #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob: redirected to %s", qPrintable(blob->m_finalUrl.toString())); + qWarning("QQmlDataBlob: redirected to %s", qPrintable(blob->urlString())); #endif return; } @@ -1294,7 +1307,7 @@ void QQmlTypeLoader::setData(QQmlDataBlob *blob, const QQmlDataBlob::SourceCodeD blob->tryDone(); } -void QQmlTypeLoader::setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeLoader::setCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit) { QML_MEMORY_SCOPE_URL(blob->url()); QQmlCompilingProfiler prof(profiler(), blob); @@ -1354,7 +1367,7 @@ bool QQmlTypeLoader::Blob::fetchQmldir(const QUrl &url, const QV4::CompiledData: bool QQmlTypeLoader::Blob::updateQmldir(QQmlQmldirData *data, const QV4::CompiledData::Import *import, QList<QQmlError> *errors) { - QString qmldirIdentifier = data->url().toString(); + QString qmldirIdentifier = data->urlString(); QString qmldirUrl = qmldirIdentifier.left(qmldirIdentifier.lastIndexOf(QLatin1Char('/')) + 1); typeLoader()->setQmldirContent(qmldirIdentifier, data->content()); @@ -1442,8 +1455,13 @@ bool QQmlTypeLoader::Blob::addImport(const QV4::CompiledData::Import *import, QL // We haven't yet resolved this import m_unresolvedImports.insert(import, 0); - // Query any network import paths for this library - QStringList remotePathList = importDatabase->importPathList(QQmlImportDatabase::Remote); + QQmlAbstractUrlInterceptor *interceptor = typeLoader()->engine()->urlInterceptor(); + + // Query any network import paths for this library. + // Interceptor might redirect local paths. + QStringList remotePathList = importDatabase->importPathList( + interceptor ? QQmlImportDatabase::LocalOrRemote + : QQmlImportDatabase::Remote); if (!remotePathList.isEmpty()) { // Add this library and request the possible locations for it if (!m_importCache.addLibraryImport(importDatabase, importUri, importQualifier, import->majorVersion, @@ -1454,8 +1472,18 @@ bool QQmlTypeLoader::Blob::addImport(const QV4::CompiledData::Import *import, QL int priority = 0; const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(importUri, remotePathList, import->majorVersion, import->minorVersion); for (const QString &qmldirPath : qmlDirPaths) { - if (!fetchQmldir(QUrl(qmldirPath), import, ++priority, errors)) + if (interceptor) { + QUrl url = interceptor->intercept( + QQmlImports::urlFromLocalFileOrQrcOrUrl(qmldirPath), + QQmlAbstractUrlInterceptor::QmldirFile); + if (!QQmlFile::isLocalFile(url) + && !fetchQmldir(url, import, ++priority, errors)) { + return false; + } + } else if (!fetchQmldir(QUrl(qmldirPath), import, ++priority, errors)) { return false; + } + } } } @@ -1514,7 +1542,7 @@ void QQmlTypeLoader::Blob::dependencyComplete(QQmlDataBlob *blob) bool QQmlTypeLoader::Blob::isDebugging() const { - return QV8Engine::getV4(typeLoader()->engine())->debugger() != 0; + return typeLoader()->engine()->handle()->debugger() != nullptr; } bool QQmlTypeLoader::Blob::qmldirDataAvailable(QQmlQmldirData *data, QList<QQmlError> *errors) @@ -1522,7 +1550,7 @@ bool QQmlTypeLoader::Blob::qmldirDataAvailable(QQmlQmldirData *data, QList<QQmlE bool resolve = true; const QV4::CompiledData::Import *import = data->import(this); - data->setImport(this, 0); + data->setImport(this, nullptr); int priority = data->priority(this); data->setPriority(this, 0); @@ -1656,7 +1684,7 @@ QQmlTypeData *QQmlTypeLoader::getType(const QUrl &url, Mode mode) typeData = new QQmlTypeData(url, this); // TODO: if (compiledData == 0), is it safe to omit this insertion? m_typeCache.insert(url, typeData); - if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(typeData->url())) { + if (const QV4::CompiledData::Unit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(typeData->url())) { QQmlTypeLoader::loadWithCachedUnit(typeData, cachedUnit, mode); } else { QQmlTypeLoader::load(typeData, mode); @@ -1717,7 +1745,7 @@ QQmlScriptBlob *QQmlTypeLoader::getScript(const QUrl &url) scriptBlob = new QQmlScriptBlob(url, this); m_scriptCache.insert(url, scriptBlob); - if (const QQmlPrivate::CachedQmlUnit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(scriptBlob->url())) { + if (const QV4::CompiledData::Unit *cachedUnit = QQmlMetaType::findCachedCompilationUnit(scriptBlob->url())) { QQmlTypeLoader::loadWithCachedUnit(scriptBlob, cachedUnit); } else { QQmlTypeLoader::load(scriptBlob); @@ -1805,7 +1833,7 @@ QString QQmlTypeLoader::absoluteFilePath(const QString &path) if (!m_importDirCache.contains(dirPath)) { bool exists = QDir(dirPath).exists(); - QCache<QString, bool> *entry = exists ? new QCache<QString, bool> : 0; + QCache<QString, bool> *entry = exists ? new QCache<QString, bool> : nullptr; m_importDirCache.insert(dirPath, entry); } QCache<QString, bool> *fileSet = m_importDirCache.object(dirPath); @@ -1868,12 +1896,12 @@ bool QQmlTypeLoader::directoryExists(const QString &path) if (!m_importDirCache.contains(dirPath)) { bool exists = QDir(dirPath).exists(); - QCache<QString, bool> *files = exists ? new QCache<QString, bool> : 0; + QCache<QString, bool> *files = exists ? new QCache<QString, bool> : nullptr; m_importDirCache.insert(dirPath, files); } QCache<QString, bool> *fileSet = m_importDirCache.object(dirPath); - return fileSet != 0; + return fileSet != nullptr; } @@ -1886,19 +1914,22 @@ It can also be a remote path for a remote directory import, but it will have bee */ const QQmlTypeLoaderQmldirContent *QQmlTypeLoader::qmldirContent(const QString &filePathIn) { - QUrl url(filePathIn); //May already contain http scheme - if (url.scheme() == QLatin1String("http") || url.scheme() == QLatin1String("https")) - return *(m_importQmlDirCache.value(filePathIn)); //Can't load the remote here, but should be cached - else - url = QUrl::fromLocalFile(filePathIn); - if (engine() && engine()->urlInterceptor()) - url = engine()->urlInterceptor()->intercept(url, QQmlAbstractUrlInterceptor::QmldirFile); - Q_ASSERT(url.scheme() == QLatin1String("file")); QString filePath; - if (url.scheme() == QLatin1String("file")) - filePath = url.toLocalFile(); - else - filePath = url.path(); + + // Try to guess if filePathIn is already a URL. This is necessarily fragile, because + // - paths can contain ':', which might make them appear as URLs with schemes. + // - windows drive letters appear as schemes (thus "< 2" below). + // - a "file:" URL is equivalent to the respective file, but will be treated differently. + // Yet, this heuristic is the best we can do until we pass more structured information here, + // for example a QUrl also for local files. + QUrl url(filePathIn); + if (url.scheme().length() < 2) { + filePath = filePathIn; + } else { + filePath = QQmlFile::urlToLocalFileOrQrc(url); + if (filePath.isEmpty()) // Can't load the remote here, but should be cached + return *(m_importQmlDirCache.value(filePathIn)); + } QQmlTypeLoaderQmldirContent *qmldir; QQmlTypeLoaderQmldirContent **val = m_importQmlDirCache.value(filePath); @@ -2092,7 +2123,7 @@ bool QQmlTypeData::tryLoadFromDiskCache() if (isDebugging()) return false; - QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(typeLoader()->engine()); + QV4::ExecutionEngine *v4 = typeLoader()->engine()->handle(); if (!v4) return false; @@ -2100,7 +2131,7 @@ bool QQmlTypeData::tryLoadFromDiskCache() { QString error; if (!unit->loadFromDisk(url(), m_backupSourceCode.sourceTimeStamp(), &error)) { - qCDebug(DBG_DISK_CACHE) << "Error loading" << url().toString() << "from disk cache:" << error; + qCDebug(DBG_DISK_CACHE) << "Error loading" << urlString() << "from disk cache:" << error; return false; } } @@ -2171,8 +2202,12 @@ void QQmlTypeData::createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeName QQmlEnginePrivate * const engine = QQmlEnginePrivate::get(typeLoader()->engine()); + QQmlPendingGroupPropertyBindings pendingGroupPropertyBindings; + { - QQmlPropertyCacheCreator<QV4::CompiledData::CompilationUnit> propertyCacheCreator(&m_compiledData->propertyCaches, engine, m_compiledData, &m_importCache); + QQmlPropertyCacheCreator<QV4::CompiledData::CompilationUnit> propertyCacheCreator(&m_compiledData->propertyCaches, + &pendingGroupPropertyBindings, + engine, m_compiledData, &m_importCache); QQmlCompileError error = propertyCacheCreator.buildMetaObjects(); if (error.isSet()) { setError(error); @@ -2182,6 +2217,8 @@ void QQmlTypeData::createTypeAndPropertyCaches(const QQmlRefPointer<QQmlTypeName QQmlPropertyCacheAliasCreator<QV4::CompiledData::CompilationUnit> aliasCreator(&m_compiledData->propertyCaches, m_compiledData); aliasCreator.appendAliasPropertiesToMetaObjects(); + + pendingGroupPropertyBindings.resolveMissingPropertyCaches(engine, &m_compiledData->propertyCaches); } static bool addTypeReferenceChecksumsToHash(const QList<QQmlTypeData::TypeReference> &typeRefs, QCryptographicHash *hash, QQmlEngine *engine) @@ -2220,10 +2257,10 @@ void QQmlTypeData::done() if (script.script->isError()) { QList<QQmlError> errors = script.script->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(script.location.line); error.setColumn(script.location.column); - error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->url().toString())); + error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->urlString())); errors.prepend(error); setError(errors); return; @@ -2240,7 +2277,7 @@ void QQmlTypeData::done() QList<QQmlError> errors = type.typeData->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(type.location.line); error.setColumn(type.location.column); error.setDescription(QQmlTypeLoader::tr("Type %1 unavailable").arg(typeName)); @@ -2259,7 +2296,7 @@ void QQmlTypeData::done() QList<QQmlError> errors = type.typeData->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(type.location.line); error.setColumn(type.location.column); error.setDescription(QQmlTypeLoader::tr("Type %1 unavailable").arg(typeName)); @@ -2289,7 +2326,7 @@ void QQmlTypeData::done() // verify if any dependencies changed if we're using a cache if (m_document.isNull() && !m_compiledData->verifyChecksum(dependencyHasher)) { - qCDebug(DBG_DISK_CACHE) << "Checksum mismatch for cached version of" << m_compiledData->url().toString(); + qCDebug(DBG_DISK_CACHE) << "Checksum mismatch for cached version of" << m_compiledData->fileName(); if (!loadFromSource()) return; m_backupSourceCode = SourceCodeData(); @@ -2420,10 +2457,14 @@ void QQmlTypeData::dataReceived(const SourceCodeData &data) continueLoadFromIR(); } -void QQmlTypeData::initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) +void QQmlTypeData::initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) { m_document.reset(new QmlIR::Document(isDebugging())); - unit->loadIR(m_document.data(), unit); + QmlIR::IRLoader loader(unit, m_document.data()); + loader.load(); + m_document->jsModule.fileName = urlString(); + m_document->jsModule.finalUrl = finalUrlString(); + m_document->javaScriptCompilationUnit.adopt(new QV4::CompiledData::CompilationUnit(unit)); continueLoadFromIR(); } @@ -2432,7 +2473,7 @@ bool QQmlTypeData::loadFromSource() m_document.reset(new QmlIR::Document(isDebugging())); m_document->jsModule.sourceTimeStamp = m_backupSourceCode.sourceTimeStamp(); QQmlEngine *qmlEngine = typeLoader()->engine(); - QmlIR::IRBuilder compiler(QV8Engine::get(qmlEngine)->illegalNames()); + QmlIR::IRBuilder compiler(qmlEngine->handle()->v8Engine->illegalNames()); QString sourceError; const QString source = m_backupSourceCode.readAll(&sourceError); @@ -2446,7 +2487,7 @@ bool QQmlTypeData::loadFromSource() errors.reserve(compiler.errors.count()); for (const QQmlJS::DiagnosticMessage &msg : qAsConst(compiler.errors)) { QQmlError e; - e.setUrl(finalUrl()); + e.setUrl(url()); e.setLine(msg.loc.startLine); e.setColumn(msg.loc.startColumn); e.setDescription(msg.message); @@ -2463,7 +2504,8 @@ void QQmlTypeData::restoreIR(QQmlRefPointer<QV4::CompiledData::CompilationUnit> m_document.reset(new QmlIR::Document(isDebugging())); QmlIR::IRLoader loader(unit->data, m_document.data()); loader.load(); - m_document->jsModule.fileName = finalUrlString(); + m_document->jsModule.fileName = urlString(); + m_document->jsModule.finalUrl = finalUrlString(); m_document->javaScriptCompilationUnit = unit; continueLoadFromIR(); } @@ -2515,6 +2557,8 @@ void QQmlTypeData::continueLoadFromIR() void QQmlTypeData::allDependenciesDone() { + QQmlTypeLoader::Blob::allDependenciesDone(); + if (!m_typesResolved) { // Check that all imports were resolved QList<QQmlError> errors; @@ -2584,7 +2628,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCach // ignore error, keep using the in-memory compilation unit. } } else { - qCDebug(DBG_DISK_CACHE) << "Error saving cached version of" << m_compiledData->url().toString() << "to disk:" << errorString; + qCDebug(DBG_DISK_CACHE) << "Error saving cached version of" << m_compiledData->fileName() << "to disk:" << errorString; } } } @@ -2634,6 +2678,10 @@ void QQmlTypeData::resolveTypes() if (ref.type.isCompositeSingleton()) { ref.typeData = typeLoader()->getType(ref.type.sourceUrl()); + if (ref.typeData->status() == QQmlDataBlob::ResolvingDependencies) { + // TODO: give an error message? If so, we should record and show the path of the cycle. + continue; + } addDependency(ref.typeData); ref.prefix = csRef.prefix; @@ -2737,7 +2785,7 @@ bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int & TypeReference &ref, int lineNumber, int columnNumber, bool reportErrors, QQmlType::RegistrationType registrationType) { - QQmlImportNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = nullptr; QList<QQmlError> errors; bool typeFound = m_importCache.resolveType(typeName, &ref.type, &majorVersion, &minorVersion, @@ -2797,9 +2845,9 @@ void QQmlTypeData::scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData: } QQmlScriptData::QQmlScriptData() - : typeNameCache(0) + : typeNameCache(nullptr) , m_loaded(false) - , m_program(0) + , m_program(nullptr) { } @@ -2814,11 +2862,9 @@ void QQmlScriptData::initialize(QQmlEngine *engine) Q_ASSERT(engine); Q_ASSERT(!hasEngine()); - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); - QV8Engine *v8engine = ep->v8engine(); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(v8engine); + QV4::ExecutionEngine *v4 = engine->handle(); - m_program = new QV4::Script(v4, 0, m_precompiledScript); + m_program = new QV4::Script(v4, nullptr, m_precompiledScript); addToEngine(engine); @@ -2832,14 +2878,14 @@ QV4::ReturnedValue QQmlScriptData::scriptValueForContext(QQmlContextData *parent Q_ASSERT(parentCtxt && parentCtxt->engine); QQmlEnginePrivate *ep = QQmlEnginePrivate::get(parentCtxt->engine); - QV4::ExecutionEngine *v4 = QV8Engine::getV4(parentCtxt->engine); + QV4::ExecutionEngine *v4 = parentCtxt->engine->handle(); QV4::Scope scope(v4); bool shared = m_precompiledScript->data->flags & QV4::CompiledData::Unit::IsSharedLibrary; QQmlContextData *effectiveCtxt = parentCtxt; if (shared) - effectiveCtxt = 0; + effectiveCtxt = nullptr; // Create the script context if required QQmlContextDataRef ctxt(new QQmlContextData); @@ -2887,10 +2933,11 @@ QV4::ReturnedValue QQmlScriptData::scriptValueForContext(QQmlContextData *parent return QV4::Encode::undefined(); } - QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxt, 0)); + QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxt, nullptr)); m_program->qmlContext.set(scope.engine, qmlContext); m_program->run(); + m_program->qmlContext.clear(); if (scope.engine->hasException) { QQmlError error = scope.engine->catchExceptionAsQmlError(); if (error.isValid()) @@ -2910,7 +2957,7 @@ void QQmlScriptData::clear() { if (typeNameCache) { typeNameCache->release(); - typeNameCache = 0; + typeNameCache = nullptr; } for (int ii = 0; ii < scripts.count(); ++ii) @@ -2922,7 +2969,7 @@ void QQmlScriptData::clear() } QQmlScriptBlob::QQmlScriptBlob(const QUrl &url, QQmlTypeLoader *loader) -: QQmlTypeLoader::Blob(url, JavaScriptFile, loader), m_scriptData(0) +: QQmlTypeLoader::Blob(url, JavaScriptFile, loader), m_scriptData(nullptr) { } @@ -2930,7 +2977,7 @@ QQmlScriptBlob::~QQmlScriptBlob() { if (m_scriptData) { m_scriptData->release(); - m_scriptData = 0; + m_scriptData = nullptr; } } @@ -2948,7 +2995,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) initializeFromCompilationUnit(unit); return; } else { - qCDebug(DBG_DISK_CACHE()) << "Error loading" << url().toString() << "from disk cache:" << error; + qCDebug(DBG_DISK_CACHE()) << "Error loading" << urlString() << "from disk cache:" << error; } } @@ -2966,7 +3013,9 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) QmlIR::ScriptDirectivesCollector collector(&irUnit.jsParserEngine, &irUnit.jsGenerator); QList<QQmlError> errors; - QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Script::precompile(&irUnit.jsModule, &irUnit.jsGenerator, finalUrl(), source, &errors, &collector); + QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Script::precompile( + &irUnit.jsModule, &irUnit.jsGenerator, urlString(), finalUrlString(), + source, &errors, &collector); // No need to addref on unit, it's initial refcount is 1 source.clear(); if (!errors.isEmpty()) { @@ -2987,19 +3036,21 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) // The js unit owns the data and will free the qml unit. unit->data = unitData; - if (!disableDiskCache() || forceDiskCache()) { + if ((!disableDiskCache() || forceDiskCache()) && !isDebugging()) { QString errorString; if (!unit->saveToDisk(url(), &errorString)) { - qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->url().toString() << "to disk:" << errorString; + qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->fileName() << "to disk:" << errorString; } } initializeFromCompilationUnit(unit); } -void QQmlScriptBlob::initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) +void QQmlScriptBlob::initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) { - initializeFromCompilationUnit(unit->createCompilationUnit()); + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; + compilationUnit.adopt(new QV4::CompiledData::CompilationUnit(unit)); + initializeFromCompilationUnit(compilationUnit); } void QQmlScriptBlob::done() @@ -3014,10 +3065,10 @@ void QQmlScriptBlob::done() if (script.script->isError()) { QList<QQmlError> errors = script.script->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(script.location.line); error.setColumn(script.location.column); - error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->url().toString())); + error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->urlString())); errors.prepend(error); setError(errors); return; @@ -3061,7 +3112,7 @@ void QQmlScriptBlob::scriptImported(QQmlScriptBlob *blob, const QV4::CompiledDat m_scripts << ref; } -void QQmlScriptBlob::initializeFromCompilationUnit(QV4::CompiledData::CompilationUnit *unit) +void QQmlScriptBlob::initializeFromCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit) { Q_ASSERT(!m_scriptData); m_scriptData = new QQmlScriptData(); @@ -3105,7 +3156,7 @@ const QV4::CompiledData::Import *QQmlQmldirData::import(QQmlTypeLoader::Blob *bl QHash<QQmlTypeLoader::Blob *, const QV4::CompiledData::Import *>::const_iterator it = m_imports.find(blob); if (it == m_imports.end()) - return 0; + return nullptr; return *it; } @@ -3137,7 +3188,7 @@ void QQmlQmldirData::dataReceived(const SourceCodeData &data) } } -void QQmlQmldirData::initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *) +void QQmlQmldirData::initializeFromCachedUnit(const QV4::CompiledData::Unit *) { Q_UNIMPLEMENTED(); } diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 7218858726..e1a7ac7f06 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -98,6 +98,7 @@ public: Null, // Prior to QQmlTypeLoader::load() Loading, // Prior to data being received and dataReceived() being called WaitingForDependencies, // While there are outstanding addDependency()s + ResolvingDependencies, // While resolving outstanding dependencies, to detect cycles Complete, // Finished Error // Error }; @@ -109,7 +110,7 @@ public: }; QQmlDataBlob(const QUrl &, Type, QQmlTypeLoader* manager); - virtual ~QQmlDataBlob(); + ~QQmlDataBlob() override; void startLoading(); @@ -128,6 +129,7 @@ public: qreal progress() const; QUrl url() const; + QString urlString() const; QUrl finalUrl() const; QString finalUrlString() const; @@ -156,7 +158,7 @@ protected: // Callbacks made in load thread virtual void dataReceived(const SourceCodeData &) = 0; - virtual void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit*) = 0; + virtual void initializeFromCachedUnit(const QV4::CompiledData::Unit*) = 0; virtual void done(); #if QT_CONFIG(qml_network) virtual void networkError(QNetworkReply::NetworkError); @@ -206,6 +208,7 @@ private: QUrl m_url; QUrl m_finalUrl; + mutable QString m_urlString; mutable QString m_finalUrlString; // List of QQmlDataBlob's that are waiting for me to complete. @@ -265,7 +268,7 @@ public: { public: Blob(const QUrl &url, QQmlDataBlob::Type type, QQmlTypeLoader *loader); - ~Blob(); + ~Blob() override; const QQmlImports &imports() const { return m_importCache; } @@ -321,7 +324,7 @@ public: void load(QQmlDataBlob *, Mode = PreferSynchronous); void loadWithStaticData(QQmlDataBlob *, const QByteArray &, Mode = PreferSynchronous); - void loadWithCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode = PreferSynchronous); + void loadWithCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit, Mode mode = PreferSynchronous); QQmlEngine *engine() const; void initializeEngine(QQmlExtensionInterface *, const char *); @@ -347,7 +350,7 @@ private: void loadThread(QQmlDataBlob *); void loadWithStaticDataThread(QQmlDataBlob *, const QByteArray &); - void loadWithCachedUnitThread(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit); + void loadWithCachedUnitThread(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit); #if QT_CONFIG(qml_network) void networkReplyFinished(QNetworkReply *); void networkReplyProgress(QNetworkReply *, qint64, qint64); @@ -358,7 +361,7 @@ private: void setData(QQmlDataBlob *, const QByteArray &); void setData(QQmlDataBlob *, const QString &fileName); void setData(QQmlDataBlob *, const QQmlDataBlob::SourceCodeData &); - void setCachedUnit(QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit); + void setCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit); template<typename T> struct TypedCallback @@ -414,7 +417,7 @@ class Q_AUTOTEST_EXPORT QQmlTypeData : public QQmlTypeLoader::Blob public: struct TypeReference { - TypeReference() : majorVersion(0), minorVersion(0), typeData(0), needsCreation(true) {} + TypeReference() : majorVersion(0), minorVersion(0), typeData(nullptr), needsCreation(true) {} QV4::CompiledData::Location location; QQmlType type; @@ -428,7 +431,7 @@ public: struct ScriptReference { - ScriptReference() : script(0) {} + ScriptReference() : script(nullptr) {} QV4::CompiledData::Location location; QString qualifier; @@ -441,7 +444,7 @@ private: QQmlTypeData(const QUrl &, QQmlTypeLoader *); public: - ~QQmlTypeData(); + ~QQmlTypeData() override; const QList<ScriptReference> &resolvedScripts() const; @@ -460,7 +463,7 @@ protected: void done() override; void completed() override; void dataReceived(const SourceCodeData &) override; - void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override; + void initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) override; void allDependenciesDone() override; void downloadProgressChanged(qreal) override; @@ -526,7 +529,7 @@ private: QQmlScriptData(); public: - ~QQmlScriptData(); + ~QQmlScriptData() override; QUrl url; QString urlString; @@ -557,11 +560,11 @@ private: QQmlScriptBlob(const QUrl &, QQmlTypeLoader *); public: - ~QQmlScriptBlob(); + ~QQmlScriptBlob() override; struct ScriptReference { - ScriptReference() : script(0) {} + ScriptReference() : script(nullptr) {} QV4::CompiledData::Location location; QString qualifier; @@ -573,14 +576,14 @@ public: protected: void dataReceived(const SourceCodeData &) override; - void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit *unit) override; + void initializeFromCachedUnit(const QV4::CompiledData::Unit *unit) override; void done() override; QString stringAt(int index) const override; private: void scriptImported(QQmlScriptBlob *blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override; - void initializeFromCompilationUnit(QV4::CompiledData::CompilationUnit *unit); + void initializeFromCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit); QList<ScriptReference> m_scripts; QQmlScriptData *m_scriptData; @@ -604,7 +607,7 @@ public: protected: void dataReceived(const SourceCodeData &) override; - void initializeFromCachedUnit(const QQmlPrivate::CachedQmlUnit*) override; + void initializeFromCachedUnit(const QV4::CompiledData::Unit *) override; private: QString m_content; diff --git a/src/qml/qml/qqmltypenamecache.cpp b/src/qml/qml/qqmltypenamecache.cpp index 32b0fa16c4..8f1a61e6ad 100644 --- a/src/qml/qml/qqmltypenamecache.cpp +++ b/src/qml/qml/qqmltypenamecache.cpp @@ -56,7 +56,7 @@ void QQmlTypeNameCache::add(const QHashedString &name, const QUrl &url, const QH { if (nameSpace.length() != 0) { QQmlImportRef *i = m_namedImports.value(nameSpace); - Q_ASSERT(i != 0); + Q_ASSERT(i != nullptr); i->compositeSingletons.insert(name, url); return; } @@ -75,7 +75,7 @@ void QQmlTypeNameCache::add(const QHashedString &name, int importedScriptIndex, if (nameSpace.length() != 0) { QQmlImportRef *i = m_namedImports.value(nameSpace); - Q_ASSERT(i != 0); + Q_ASSERT(i != nullptr); m_namespacedImports[i].insert(name, import); return; } @@ -98,10 +98,10 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name) if (!result.isValid()) { // Look up anonymous types from the imports of this document - QQmlImportNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = nullptr; QList<QQmlError> errors; QQmlType t; - bool typeFound = m_imports.resolveType(name, &t, 0, 0, &typeNamespace, &errors); + bool typeFound = m_imports.resolveType(name, &t, nullptr, nullptr, &typeNamespace, &errors); if (typeFound) { return Result(t); } @@ -126,10 +126,10 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name, // ### it would be nice if QQmlImports allowed us to resolve a namespace // first, and then types on it. QString qualifiedTypeName = importNamespace->m_qualifier + QLatin1Char('.') + name.toString(); - QQmlImportNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = nullptr; QList<QQmlError> errors; QQmlType t; - bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors); + bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, nullptr, nullptr, &typeNamespace, &errors); if (typeFound) { return Result(t); } @@ -151,10 +151,10 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, QQml if (!result.isValid()) { // Look up anonymous types from the imports of this document QString typeName = name->toQStringNoThrow(); - QQmlImportNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = nullptr; QList<QQmlError> errors; QQmlType t; - bool typeFound = m_imports.resolveType(typeName, &t, 0, 0, &typeNamespace, &errors, + bool typeFound = m_imports.resolveType(typeName, &t, nullptr, nullptr, &typeNamespace, &errors, QQmlType::AnyRegistrationType, recursionRestriction); if (typeFound) { return Result(t); @@ -186,10 +186,10 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, cons // ### it would be nice if QQmlImports allowed us to resolve a namespace // first, and then types on it. QString qualifiedTypeName = importNamespace->m_qualifier + QLatin1Char('.') + name->toQStringNoThrow(); - QQmlImportNamespace *typeNamespace = 0; + QQmlImportNamespace *typeNamespace = nullptr; QList<QQmlError> errors; QQmlType t; - bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, 0, 0, &typeNamespace, &errors); + bool typeFound = m_imports.resolveType(qualifiedTypeName, &t, nullptr, nullptr, &typeNamespace, &errors); if (typeFound) { return Result(t); } diff --git a/src/qml/qml/qqmltypenamecache_p.h b/src/qml/qml/qqmltypenamecache_p.h index 8ac25c4fbe..28b5e7f0ad 100644 --- a/src/qml/qml/qqmltypenamecache_p.h +++ b/src/qml/qml/qqmltypenamecache_p.h @@ -85,7 +85,7 @@ class Q_QML_PRIVATE_EXPORT QQmlTypeNameCache : public QQmlRefCount { public: QQmlTypeNameCache(const QQmlImports &imports); - virtual ~QQmlTypeNameCache(); + ~QQmlTypeNameCache() override; inline bool isEmpty() const; @@ -162,7 +162,7 @@ private: }; QQmlTypeNameCache::Result::Result() -: importNamespace(0), scriptIndex(-1) +: importNamespace(nullptr), scriptIndex(-1) { } @@ -172,12 +172,12 @@ QQmlTypeNameCache::Result::Result(const QQmlImportRef *importNamespace) } QQmlTypeNameCache::Result::Result(const QQmlType &type) -: type(type), importNamespace(0), scriptIndex(-1) +: type(type), importNamespace(nullptr), scriptIndex(-1) { } QQmlTypeNameCache::Result::Result(int scriptIndex) -: importNamespace(0), scriptIndex(scriptIndex) +: importNamespace(nullptr), scriptIndex(scriptIndex) { } diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 404bc0612e..6dbf6ad8c1 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -85,7 +85,7 @@ bool QQmlTypeWrapper::isSingleton() const QObject* QQmlTypeWrapper::singletonObject() const { if (!isSingleton()) - return 0; + return nullptr; QQmlEngine *e = engine()->qmlEngine(); QQmlType::SingletonInstanceInfo *siinfo = d()->type().singletonInstanceInfo(); @@ -134,11 +134,11 @@ ReturnedValue QQmlTypeWrapper::create(QV4::ExecutionEngine *engine, QObject *o, } static int enumForSingleton(QV4::ExecutionEngine *v4, String *name, QObject *qobjectSingleton, - const QQmlType &type) + const QQmlType &type, bool *ok) { - bool ok; - int value = type.enumValue(QQmlEnginePrivate::get(v4->qmlEngine()), name, &ok); - if (ok) + Q_ASSERT(ok != nullptr); + int value = type.enumValue(QQmlEnginePrivate::get(v4->qmlEngine()), name, ok); + if (*ok) return value; // ### Optimize @@ -146,10 +146,11 @@ static int enumForSingleton(QV4::ExecutionEngine *v4, String *name, QObject *qob const QMetaObject *metaObject = qobjectSingleton->metaObject(); for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) { QMetaEnum e = metaObject->enumerator(ii); - value = e.keyToValue(enumName.constData(), &ok); - if (ok) + value = e.keyToValue(enumName.constData(), ok); + if (*ok) return value; } + *ok = false; return -1; } @@ -192,8 +193,9 @@ ReturnedValue QQmlTypeWrapper::get(const Managed *m, String *name, bool *hasProp // check for enum value const bool includeEnums = w->d()->mode == Heap::QQmlTypeWrapper::IncludeEnums; if (includeEnums && name->startsWithUpper()) { - const int value = enumForSingleton(v4, name, qobjectSingleton, type); - if (value != -1) + bool ok = false; + const int value = enumForSingleton(v4, name, qobjectSingleton, type, &ok); + if (ok) return QV4::Primitive::fromInt32(value).asReturnedValue(); } @@ -205,8 +207,8 @@ ReturnedValue QQmlTypeWrapper::get(const Managed *m, String *name, bool *hasProp // Warn when attempting to access a lowercased enum value, singleton case if (!ok && includeEnums && !name->startsWithUpper()) { - const int value = enumForSingleton(v4, name, qobjectSingleton, type); - if (value != -1) + enumForSingleton(v4, name, qobjectSingleton, type, &ok); + if (ok) return throwLowercaseEnumError(v4, name, type); } diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp index 520f512b1a..270414a676 100644 --- a/src/qml/qml/qqmlvaluetype.cpp +++ b/src/qml/qml/qqmlvaluetype.cpp @@ -68,7 +68,7 @@ struct QQmlValueTypeFactoryImpl QQmlValueTypeFactoryImpl::QQmlValueTypeFactoryImpl() { for (unsigned int ii = 0; ii < QVariant::UserType; ++ii) - valueTypes[ii] = 0; + valueTypes[ii] = nullptr; // See types wrapped in qqmlmodelindexvaluetype_p.h qRegisterMetaType<QItemSelectionRange>(); @@ -83,7 +83,7 @@ QQmlValueTypeFactoryImpl::~QQmlValueTypeFactoryImpl() bool QQmlValueTypeFactoryImpl::isValueType(int idx) { if (idx >= (int)QVariant::UserType) { - return (valueType(idx) != 0); + return (valueType(idx) != nullptr); } else if (idx >= 0 && idx != QVariant::StringList && idx != QMetaType::QObjectStar @@ -130,7 +130,7 @@ const QMetaObject *QQmlValueTypeFactoryImpl::metaObjectForMetaType(int t) QMetaType metaType(t); if (metaType.flags() & QMetaType::IsGadget) return metaType.metaObject(); - return 0; + return nullptr; } QQmlValueType *QQmlValueTypeFactoryImpl::valueType(int idx) @@ -141,7 +141,7 @@ QQmlValueType *QQmlValueTypeFactoryImpl::valueType(int idx) QHash<int, QQmlValueType *>::iterator it = userTypes.find(idx); if (it == userTypes.end()) { - QQmlValueType *vt = 0; + QQmlValueType *vt = nullptr; if (const QMetaObject *mo = metaObjectForMetaType(idx)) vt = new QQmlValueType(idx, mo); it = userTypes.insert(idx, vt); @@ -209,14 +209,14 @@ QQmlValueType::~QQmlValueType() { QObjectPrivate *op = QObjectPrivate::get(this); Q_ASSERT(op->metaObject == this); - op->metaObject = 0; + op->metaObject = nullptr; ::free(const_cast<QMetaObject *>(_metaObject)); metaType.destroy(gadgetPtr); } void QQmlValueType::read(QObject *obj, int idx) { - void *a[] = { gadgetPtr, 0 }; + void *a[] = { gadgetPtr, nullptr }; QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a); } @@ -224,7 +224,7 @@ void QQmlValueType::write(QObject *obj, int idx, QQmlPropertyData::WriteFlags fl { Q_ASSERT(gadgetPtr); int status = -1; - void *a[] = { gadgetPtr, 0, &status, &flags }; + void *a[] = { gadgetPtr, nullptr, &status, &flags }; QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a); } diff --git a/src/qml/qml/qqmlvaluetype_p.h b/src/qml/qml/qqmlvaluetype_p.h index 0502a5d665..4ea71e8955 100644 --- a/src/qml/qml/qqmlvaluetype_p.h +++ b/src/qml/qml/qqmlvaluetype_p.h @@ -67,7 +67,7 @@ class Q_QML_PRIVATE_EXPORT QQmlValueType : public QObject, public QAbstractDynam { public: QQmlValueType(int userType, const QMetaObject *metaObject); - ~QQmlValueType(); + ~QQmlValueType() override; void read(QObject *, int); void write(QObject *, int, QQmlPropertyData::WriteFlags flags); QVariant value(); @@ -272,19 +272,19 @@ int qmlRegisterValueTypeEnums(const char *uri, int versionMajor, int versionMino QQmlPrivate::RegisterType type = { 0, - qRegisterNormalizedMetaType<T *>(pointerName.constData()), 0, 0, 0, + qRegisterNormalizedMetaType<T *>(pointerName.constData()), 0, 0, nullptr, QString(), uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject, - 0, 0, + nullptr, nullptr, 0, 0, 0, - 0, 0, + nullptr, nullptr, - 0, + nullptr, 0 }; diff --git a/src/qml/qml/qqmlvaluetypeproxybinding.cpp b/src/qml/qml/qqmlvaluetypeproxybinding.cpp index 7a3e4b2df4..d5cff26444 100644 --- a/src/qml/qml/qqmlvaluetypeproxybinding.cpp +++ b/src/qml/qml/qqmlvaluetypeproxybinding.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE QQmlValueTypeProxyBinding::QQmlValueTypeProxyBinding(QObject *o, QQmlPropertyIndex index) : QQmlAbstractBinding(), - m_bindings(0) + m_bindings(nullptr) { m_target = o; m_targetIndex = index; @@ -93,7 +93,7 @@ Removes a collection of bindings, corresponding to the set bits in \a mask. void QQmlValueTypeProxyBinding::removeBindings(quint32 mask) { QQmlAbstractBinding *binding = m_bindings.data(); - QQmlAbstractBinding *lastBinding = 0; + QQmlAbstractBinding *lastBinding = nullptr; while (binding) { const int valueTypeIndex = binding->targetPropertyIndex().valueTypeIndex(); @@ -102,7 +102,7 @@ void QQmlValueTypeProxyBinding::removeBindings(quint32 mask) remove->setAddedToObject(false); binding = remove->nextBinding(); - if (lastBinding == 0) + if (lastBinding == nullptr) m_bindings = remove->nextBinding(); else lastBinding->setNextBinding(remove->nextBinding()); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index 90ca08537c..a28115d192 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -98,6 +98,8 @@ void Heap::QQmlValueTypeWrapper::destroy() valueType->metaType.destruct(gadgetPtr); ::operator delete(gadgetPtr); } + if (_propertyCache) + _propertyCache->release(); Object::destroy(); } @@ -129,7 +131,7 @@ bool QQmlValueTypeReference::readReferenceValue() const // variant-containing-value-type reference QVariant variantReferenceValue; - void *a[] = { &variantReferenceValue, 0 }; + void *a[] = { &variantReferenceValue, nullptr }; QMetaObject::metacall(d()->object, QMetaObject::ReadProperty, d()->property, a); int variantReferenceType = variantReferenceValue.userType(); @@ -139,14 +141,14 @@ bool QQmlValueTypeReference::readReferenceValue() const // We need to modify this reference to the updated value type, if // possible, or return false if it is not a value type. if (QQmlValueTypeFactory::isValueType(variantReferenceType)) { - QQmlPropertyCache *cache = 0; + QQmlPropertyCache *cache = nullptr; if (const QMetaObject *mo = QQmlValueTypeFactory::metaObjectForMetaType(variantReferenceType)) cache = QJSEnginePrivate::get(engine())->cache(mo); if (d()->gadgetPtr) { d()->valueType->metaType.destruct(d()->gadgetPtr); ::operator delete(d()->gadgetPtr); } - d()->gadgetPtr =0; + d()->gadgetPtr =nullptr; d()->setPropertyCache(cache); d()->valueType = QQmlValueTypeFactory::valueType(variantReferenceType); if (!cache) @@ -159,10 +161,10 @@ bool QQmlValueTypeReference::readReferenceValue() const } else { if (!d()->gadgetPtr) { d()->gadgetPtr = ::operator new(d()->valueType->metaType.sizeOf()); - d()->valueType->metaType.construct(d()->gadgetPtr, 0); + d()->valueType->metaType.construct(d()->gadgetPtr, nullptr); } // value-type reference - void *args[] = { d()->gadgetPtr, 0 }; + void *args[] = { d()->gadgetPtr, nullptr }; QMetaObject::metacall(d()->object, QMetaObject::ReadProperty, d()->property, args); } return true; @@ -189,7 +191,7 @@ ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, QObject *obj r->d()->property = property; r->d()->setPropertyCache(QJSEnginePrivate::get(engine)->cache(metaObject)); r->d()->valueType = QQmlValueTypeFactory::valueType(typeId); - r->d()->gadgetPtr = 0; + r->d()->gadgetPtr = nullptr; return r->asReturnedValue(); } @@ -201,7 +203,7 @@ ReturnedValue QQmlValueTypeWrapper::create(ExecutionEngine *engine, const QVaria Scoped<QQmlValueTypeWrapper> r(scope, engine->memoryManager->allocObject<QQmlValueTypeWrapper>()); r->d()->setPropertyCache(QJSEnginePrivate::get(engine)->cache(metaObject)); r->d()->valueType = QQmlValueTypeFactory::valueType(typeId); - r->d()->gadgetPtr = 0; + r->d()->gadgetPtr = nullptr; r->d()->setValue(value); return r->asReturnedValue(); } @@ -244,13 +246,13 @@ PropertyAttributes QQmlValueTypeWrapper::query(const Managed *m, String *name) Q_ASSERT(m->as<const QQmlValueTypeWrapper>()); const QQmlValueTypeWrapper *r = static_cast<const QQmlValueTypeWrapper *>(m); - QQmlPropertyData *result = r->d()->propertyCache()->property(name, 0, 0); + QQmlPropertyData *result = r->d()->propertyCache()->property(name, nullptr, nullptr); return result ? Attr_Data : Attr_Invalid; } void QQmlValueTypeWrapper::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes) { - name->setM(0); + name->setM(nullptr); *index = UINT_MAX; QQmlValueTypeWrapper *that = static_cast<QQmlValueTypeWrapper*>(m); @@ -297,7 +299,7 @@ bool QQmlValueTypeWrapper::write(QObject *target, int propertyIndex) const if (!d()->gadgetPtr) { Q_ALLOCA_ASSIGN(void, gadget, d()->valueType->metaType.sizeOf()); d()->gadgetPtr = gadget; - d()->valueType->metaType.construct(d()->gadgetPtr, 0); + d()->valueType->metaType.construct(d()->gadgetPtr, nullptr); destructGadgetOnExit = true; } if (!ref->readReferenceValue()) @@ -306,27 +308,26 @@ bool QQmlValueTypeWrapper::write(QObject *target, int propertyIndex) const int flags = 0; int status = -1; - void *a[] = { d()->gadgetPtr, 0, &status, &flags }; + void *a[] = { d()->gadgetPtr, nullptr, &status, &flags }; QMetaObject::metacall(target, QMetaObject::WriteProperty, propertyIndex, a); if (destructGadgetOnExit) { d()->valueType->metaType.destruct(d()->gadgetPtr); - d()->gadgetPtr = 0; + d()->gadgetPtr = nullptr; } return true; } -ReturnedValue QQmlValueTypeWrapper::method_toString(const BuiltinFunction *b, CallData *callData) +ReturnedValue QQmlValueTypeWrapper::method_toString(const FunctionObject *b, const Value *thisObject, const Value *, int) { - Scope scope(b); - Object *o = callData->thisObject.as<Object>(); + const Object *o = thisObject->as<Object>(); if (!o) - THROW_TYPE_ERROR(); - QQmlValueTypeWrapper *w = o->as<QQmlValueTypeWrapper>(); + return b->engine()->throwTypeError(); + const QQmlValueTypeWrapper *w = o->as<QQmlValueTypeWrapper>(); if (!w) - THROW_TYPE_ERROR(); + return b->engine()->throwTypeError(); - if (QQmlValueTypeReference *ref = w->as<QQmlValueTypeReference>()) + if (const QQmlValueTypeReference *ref = w->as<QQmlValueTypeReference>()) if (!ref->readReferenceValue()) RETURN_UNDEFINED(); @@ -351,7 +352,7 @@ ReturnedValue QQmlValueTypeWrapper::method_toString(const BuiltinFunction *b, Ca } result += QLatin1Char(')'); } - return Encode(scope.engine->newString(result)); + return Encode(b->engine()->newString(result)); } ReturnedValue QQmlValueTypeWrapper::get(const Managed *m, String *name, bool *hasProperty) @@ -366,7 +367,7 @@ ReturnedValue QQmlValueTypeWrapper::get(const Managed *m, String *name, bool *ha return Primitive::undefinedValue().asReturnedValue(); } - QQmlPropertyData *result = r->d()->propertyCache()->property(name, 0, 0); + QQmlPropertyData *result = r->d()->propertyCache()->property(name, nullptr, nullptr); if (!result) return Object::get(m, name, hasProperty); @@ -435,7 +436,7 @@ bool QQmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) } const QMetaObject *metaObject = r->d()->propertyCache()->metaObject(); - const QQmlPropertyData *pd = r->d()->propertyCache()->property(name, 0, 0); + const QQmlPropertyData *pd = r->d()->propertyCache()->property(name, nullptr, nullptr); if (!pd) return false; @@ -504,13 +505,13 @@ bool QQmlValueTypeWrapper::put(Managed *m, String *name, const Value &value) int flags = 0; int status = -1; - void *a[] = { &variantReferenceValue, 0, &status, &flags }; + void *a[] = { &variantReferenceValue, nullptr, &status, &flags }; QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); } else { int flags = 0; int status = -1; - void *a[] = { r->d()->gadgetPtr, 0, &status, &flags }; + void *a[] = { r->d()->gadgetPtr, nullptr, &status, &flags }; QMetaObject::metacall(reference->d()->object, QMetaObject::WriteProperty, reference->d()->property, a); } } diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h index da03af6dbc..f99d207d68 100644 --- a/src/qml/qml/qqmlvaluetypewrapper_p.h +++ b/src/qml/qml/qqmlvaluetypewrapper_p.h @@ -112,7 +112,7 @@ public: static PropertyAttributes query(const Managed *, String *name); static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); - static ReturnedValue method_toString(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_toString(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); static void initProto(ExecutionEngine *v4); }; diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index c60f4edc80..018769948d 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -96,7 +96,7 @@ bool QQmlVME::componentCompleteEnabled() } QQmlVMEGuard::QQmlVMEGuard() -: m_objectCount(0), m_objects(0), m_contextCount(0), m_contexts(0) +: m_objectCount(0), m_objects(nullptr), m_contextCount(0), m_contexts(nullptr) { } @@ -120,27 +120,15 @@ void QQmlVMEGuard::guard(QQmlObjectCreator *creator) m_contexts[0] = creator->parentContextData(); } -void QQmlVMEGuard::unguard(QObject *object) -{ - for (int ii = 0; ii < m_objectCount; ++ii) { - if (m_objects[ii] == object) { - if (ii < m_objectCount - 1) - ::memmove((void *) m_objects[ii], (void *) m_objects[ii + 1], sizeof(QPointer<QObject> *)); - delete m_objects[--m_objectCount]; - break; - } - } -} - void QQmlVMEGuard::clear() { delete [] m_objects; delete [] m_contexts; m_objectCount = 0; - m_objects = 0; + m_objects = nullptr; m_contextCount = 0; - m_contexts = 0; + m_contexts = nullptr; } bool QQmlVMEGuard::isOK() const diff --git a/src/qml/qml/qqmlvme_p.h b/src/qml/qml/qqmlvme_p.h index 9585b5b6df..9a94ac6258 100644 --- a/src/qml/qml/qqmlvme_p.h +++ b/src/qml/qml/qqmlvme_p.h @@ -83,7 +83,7 @@ namespace QQmlVMETypes { struct State { enum Flag { Deferred = 0x00000001 }; - State() : flags(0), context(0), instructionStream(0) {} + State() : flags(0), context(nullptr), instructionStream(nullptr) {} quint32 flags; QQmlContextData *context; const char *instructionStream; @@ -131,7 +131,6 @@ public: ~QQmlVMEGuard(); void guard(QQmlObjectCreator *); - void unguard(QObject *); void clear(); bool isOK() const; @@ -144,7 +143,7 @@ private: }; QQmlInstantiationInterrupt::QQmlInstantiationInterrupt() - : mode(None), nsecs(0), runWhile(0) + : mode(None), nsecs(0), runWhile(nullptr) { } @@ -154,7 +153,7 @@ QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(volatile bool *runWhile, } QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(int nsecs) - : mode(Time), nsecs(nsecs), runWhile(0) + : mode(Time), nsecs(nsecs), runWhile(nullptr) { } diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 281d64ac79..c1d3980b58 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -64,7 +64,7 @@ static void list_append(QQmlListProperty<QObject> *prop, QObject *o) { QList<QObject *> *list = static_cast<QList<QObject *> *>(prop->data); list->append(o); - static_cast<QQmlVMEMetaObject *>(prop->dummy1)->activate(prop->object, reinterpret_cast<quintptr>(prop->dummy2), 0); + static_cast<QQmlVMEMetaObject *>(prop->dummy1)->activate(prop->object, reinterpret_cast<quintptr>(prop->dummy2), nullptr); } static int list_count(QQmlListProperty<QObject> *prop) @@ -83,11 +83,11 @@ static void list_clear(QQmlListProperty<QObject> *prop) { QList<QObject *> *list = static_cast<QList<QObject *> *>(prop->data); list->clear(); - static_cast<QQmlVMEMetaObject *>(prop->dummy1)->activate(prop->object, reinterpret_cast<quintptr>(prop->dummy2), 0); + static_cast<QQmlVMEMetaObject *>(prop->dummy1)->activate(prop->object, reinterpret_cast<quintptr>(prop->dummy2), nullptr); } QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr() - : QQmlGuard<QObject>(0), m_target(0), m_index(-1) + : QQmlGuard<QObject>(nullptr), m_target(nullptr), m_index(-1) { } @@ -111,7 +111,7 @@ void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *) } } - m_target->activate(m_target->object, m_target->methodOffset() + m_index, 0); + m_target->activate(m_target->object, m_target->methodOffset() + m_index, nullptr); } } @@ -150,7 +150,7 @@ void QQmlVMEMetaObjectEndpoint::tryConnect() if (metaObject.flag()) { // This is actually notify int sigIdx = metaObject->methodOffset() + aliasId + metaObject->compiledObject->nProperties; - metaObject->activate(metaObject->object, sigIdx, 0); + metaObject->activate(metaObject->object, sigIdx, nullptr); } else { const QV4::CompiledData::Alias *aliasData = &metaObject->compiledObject->aliasTable()[aliasId]; if (!aliasData->isObjectAlias()) { @@ -179,7 +179,7 @@ void QQmlVMEMetaObjectEndpoint::tryConnect() QQmlInterceptorMetaObject::QQmlInterceptorMetaObject(QObject *obj, QQmlPropertyCache *cache) : object(obj), cache(cache), - interceptors(0), + interceptors(nullptr), hasAssignedMetaObjectData(false) { QObjectPrivate *op = QObjectPrivate::get(obj); @@ -320,7 +320,7 @@ QQmlVMEMetaObject::QQmlVMEMetaObject(QV4::ExecutionEngine *engine, : QQmlInterceptorMetaObject(obj, cache), engine(engine), ctxt(QQmlData::get(obj, true)->outerContext), - aliasEndpoints(0), compilationUnit(qmlCompilationUnit), compiledObject(0) + aliasEndpoints(nullptr), compilationUnit(qmlCompilationUnit), compiledObject(nullptr) { Q_ASSERT(engine); QQmlData::get(obj)->hasVMEMetaObject = true; @@ -358,7 +358,7 @@ QV4::MemberData *QQmlVMEMetaObject::propertyAndMethodStorageAsMemberData() const // such as the varProperties array) will have been cleaned up, but the // QObject ptr will not yet have been deleted (eg, waiting on deleteLater). // In this situation, return 0. - return 0; + return nullptr; } return static_cast<QV4::MemberData*>(propertyAndMethodStorage.asManaged()); @@ -575,13 +575,13 @@ QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id) const { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); if (!md) - return 0; + return nullptr; QV4::Scope scope(engine); QV4::ScopedValue sv(scope, *(md->data() + id)); const QV4::QObjectWrapper *wrapper = sv->as<QV4::QObjectWrapper>(); if (!wrapper) - return 0; + return nullptr; return wrapper->object(); } @@ -589,7 +589,7 @@ QList<QObject *> *QQmlVMEMetaObject::readPropertyAsList(int id) const { QV4::MemberData *md = propertyAndMethodStorageAsMemberData(); if (!md) - return 0; + return nullptr; QV4::Scope scope(engine); QV4::Scoped<QV4::VariantObject> v(scope, *(md->data() + id)); @@ -643,7 +643,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * if (t == QV4::CompiledData::Property::Var) { // the context can be null if accessing var properties from cpp after re-parenting an item. - QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine); + QQmlEnginePrivate *ep = (ctxt == nullptr || ctxt->engine == nullptr) ? nullptr : QQmlEnginePrivate::get(ctxt->engine); if (ep) { if (c == QMetaObject::ReadProperty) { *reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id); @@ -836,7 +836,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * } if (c == QMetaObject::WriteProperty && needActivate) { - activate(object, methodOffset() + id, 0); + activate(object, methodOffset() + id, nullptr); } return -1; @@ -848,7 +848,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * const QV4::CompiledData::Alias *aliasData = &compiledObject->aliasTable()[id]; if ((aliasData->flags & QV4::CompiledData::Alias::AliasPointsToPointerObject) && c == QMetaObject::ReadProperty) - *reinterpret_cast<void **>(a[0]) = 0; + *reinterpret_cast<void **>(a[0]) = nullptr; if (!ctxt) return -1; @@ -899,7 +899,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * int rv = QMetaObject::metacall(valueType, c, valueTypePropertyIndex, a); if (c == QMetaObject::WriteProperty) - valueType->write(target, coreIndex, 0x00); + valueType->write(target, coreIndex, nullptr); return rv; @@ -926,12 +926,14 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * id -= plainSignals; if (id < methodCount) { - if (!ctxt->engine) + QQmlEngine *engine = ctxt->engine; + if (!engine) return -1; // We can't run the method - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine); + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine); + QV4::ExecutionEngine *v4 = engine->handle(); ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. - QV4::Scope scope(ep->v4engine()); + QV4::Scope scope(v4); QV4::ScopedFunctionObject function(scope, method(id)); @@ -951,7 +953,7 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * const unsigned int parameterCount = function->formalParameterCount(); QV4::JSCallData jsCallData(scope, parameterCount); - *jsCallData->thisObject = ep->v8engine()->global(); + *jsCallData->thisObject = v4->global(); for (uint ii = 0; ii < parameterCount; ++ii) jsCallData->args[ii] = scope.engine->fromVariant(*(QVariant *)a[ii + 1]); @@ -1035,7 +1037,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) if (oldVariant) oldVariant->removeVmePropertyReference(); - QObject *valueObject = 0; + QObject *valueObject = nullptr; QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id); // And, if the new value is a scarce resource, we need to ensure that it does not get @@ -1058,7 +1060,7 @@ void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value) // Write the value and emit change signal as appropriate. md->set(engine, id, value); - activate(object, methodOffset() + id, 0); + activate(object, methodOffset() + id, nullptr); } void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) @@ -1086,7 +1088,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) QVariant currentValue = readPropertyAsVariant(id); md->set(engine, id, newv); if ((currentValue.userType() != value.userType() || currentValue != value)) - activate(object, methodOffset() + id, 0); + activate(object, methodOffset() + id, nullptr); } else { bool needActivate = false; if (value.userType() == QMetaType::QObjectStar) { @@ -1109,7 +1111,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) } if (needActivate) - activate(object, methodOffset() + id, 0); + activate(object, methodOffset() + id, nullptr); } } @@ -1185,7 +1187,7 @@ bool QQmlVMEMetaObject::aliasTarget(int index, QObject **target, int *coreIndex, { Q_ASSERT(compiledObject && (index >= propOffset() + int(compiledObject->nProperties))); - *target = 0; + *target = nullptr; *coreIndex = -1; *valueTypeIndex = -1; @@ -1287,7 +1289,7 @@ QQmlVMEVariantQObjectPtr *QQmlVMEMetaObject::getQObjectGuardForProperty(int inde } } - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index 27e638ceb4..0c82686d47 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -81,7 +81,7 @@ class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject> { public: inline QQmlVMEVariantQObjectPtr(); - inline ~QQmlVMEVariantQObjectPtr(); + inline ~QQmlVMEVariantQObjectPtr() override; inline void objectDestroyed(QObject *) override; inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index); @@ -95,7 +95,7 @@ class Q_QML_PRIVATE_EXPORT QQmlInterceptorMetaObject : public QAbstractDynamicMe { public: QQmlInterceptorMetaObject(QObject *obj, QQmlPropertyCache *cache); - ~QQmlInterceptorMetaObject(); + ~QQmlInterceptorMetaObject() override; void registerInterceptor(QQmlPropertyIndex index, QQmlPropertyValueInterceptor *interceptor); @@ -112,7 +112,7 @@ public: if (it->m_propertyIndex == propertyIndex) return true; } - if (auto parentInterceptor = ((parent.isT1() && parent.flag()) ? static_cast<QQmlInterceptorMetaObject *>(parent.asT1()) : 0)) + if (auto parentInterceptor = ((parent.isT1() && parent.flag()) ? static_cast<QQmlInterceptorMetaObject *>(parent.asT1()) : nullptr)) return parentInterceptor->intercepts(propertyIndex); return false; } @@ -139,7 +139,7 @@ inline QQmlInterceptorMetaObject *QQmlInterceptorMetaObject::get(QObject *obj) } } - return 0; + return nullptr; } class QQmlVMEMetaObjectEndpoint; @@ -147,7 +147,7 @@ class Q_QML_PRIVATE_EXPORT QQmlVMEMetaObject : public QQmlInterceptorMetaObject { public: QQmlVMEMetaObject(QV4::ExecutionEngine *engine, QObject *obj, QQmlPropertyCache *cache, QV4::CompiledData::CompilationUnit *qmlCompilationUnit, int qmlObjectId); - ~QQmlVMEMetaObject(); + ~QQmlVMEMetaObject() override; bool aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const; QV4::ReturnedValue vmeMethod(int index) const; @@ -241,7 +241,7 @@ QQmlVMEMetaObject *QQmlVMEMetaObject::get(QObject *obj) } } - return 0; + return nullptr; } int QQmlVMEMetaObject::propOffset() const @@ -269,7 +269,7 @@ QQmlVMEMetaObject *QQmlVMEMetaObject::parentVMEMetaObject() const if (parent.isT1() && parent.flag()) return static_cast<QQmlVMEMetaObject *>(parent.asT1()); - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 08842e714c..5673acec89 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -116,7 +116,7 @@ class DocumentImpl; class NodeImpl { public: - NodeImpl() : type(Element), document(0), parent(0) {} + NodeImpl() : type(Element), document(nullptr), parent(nullptr) {} virtual ~NodeImpl() { qDeleteAll(children); qDeleteAll(attributes); @@ -157,7 +157,7 @@ public: class DocumentImpl : public QQmlRefCount, public NodeImpl { public: - DocumentImpl() : root(0) { type = Document; } + DocumentImpl() : root(nullptr) { type = Document; } virtual ~DocumentImpl() { delete root; } @@ -276,25 +276,25 @@ public: static void initClass(ExecutionEngine *engine); // JS API - static ReturnedValue method_get_nodeName(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_nodeValue(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_nodeType(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_namespaceUri(const BuiltinFunction *b, QV4::CallData *callData); - - static ReturnedValue method_get_parentNode(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_childNodes(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_firstChild(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_lastChild(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_previousSibling(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_nextSibling(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_attributes(const BuiltinFunction *b, QV4::CallData *callData); - - //static ReturnedValue ownerDocument(const BuiltinFunction *b, QV4::CallData *callData); - //static ReturnedValue namespaceURI(const BuiltinFunction *b, QV4::CallData *callData); - //static ReturnedValue prefix(const BuiltinFunction *b, QV4::CallData *callData); - //static ReturnedValue localName(const BuiltinFunction *b, QV4::CallData *callData); - //static ReturnedValue baseURI(const BuiltinFunction *b, QV4::CallData *callData); - //static ReturnedValue textContent(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_get_nodeName(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_nodeValue(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_nodeType(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_namespaceUri(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_get_parentNode(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_childNodes(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_firstChild(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_lastChild(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_previousSibling(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_nextSibling(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_attributes(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + + //static ReturnedValue ownerDocument(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + //static ReturnedValue namespaceURI(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + //static ReturnedValue prefix(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + //static ReturnedValue localName(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + //static ReturnedValue baseURI(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + //static ReturnedValue textContent(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); static ReturnedValue getProto(ExecutionEngine *v4); @@ -306,18 +306,18 @@ void Heap::NodePrototype::init() Scope scope(internalClass->engine); ScopedObject o(scope, this); - o->defineAccessorProperty(QStringLiteral("nodeName"), QV4::NodePrototype::method_get_nodeName, 0); - o->defineAccessorProperty(QStringLiteral("nodeValue"), QV4::NodePrototype::method_get_nodeValue, 0); - o->defineAccessorProperty(QStringLiteral("nodeType"), QV4::NodePrototype::method_get_nodeType, 0); - o->defineAccessorProperty(QStringLiteral("namespaceUri"), QV4::NodePrototype::method_get_namespaceUri, 0); + o->defineAccessorProperty(QStringLiteral("nodeName"), QV4::NodePrototype::method_get_nodeName, nullptr); + o->defineAccessorProperty(QStringLiteral("nodeValue"), QV4::NodePrototype::method_get_nodeValue, nullptr); + o->defineAccessorProperty(QStringLiteral("nodeType"), QV4::NodePrototype::method_get_nodeType, nullptr); + o->defineAccessorProperty(QStringLiteral("namespaceUri"), QV4::NodePrototype::method_get_namespaceUri, nullptr); - o->defineAccessorProperty(QStringLiteral("parentNode"), QV4::NodePrototype::method_get_parentNode, 0); - o->defineAccessorProperty(QStringLiteral("childNodes"), QV4::NodePrototype::method_get_childNodes, 0); - o->defineAccessorProperty(QStringLiteral("firstChild"), QV4::NodePrototype::method_get_firstChild, 0); - o->defineAccessorProperty(QStringLiteral("lastChild"), QV4::NodePrototype::method_get_lastChild, 0); - o->defineAccessorProperty(QStringLiteral("previousSibling"), QV4::NodePrototype::method_get_previousSibling, 0); - o->defineAccessorProperty(QStringLiteral("nextSibling"), QV4::NodePrototype::method_get_nextSibling, 0); - o->defineAccessorProperty(QStringLiteral("attributes"), QV4::NodePrototype::method_get_attributes, 0); + o->defineAccessorProperty(QStringLiteral("parentNode"), QV4::NodePrototype::method_get_parentNode, nullptr); + o->defineAccessorProperty(QStringLiteral("childNodes"), QV4::NodePrototype::method_get_childNodes, nullptr); + o->defineAccessorProperty(QStringLiteral("firstChild"), QV4::NodePrototype::method_get_firstChild, nullptr); + o->defineAccessorProperty(QStringLiteral("lastChild"), QV4::NodePrototype::method_get_lastChild, nullptr); + o->defineAccessorProperty(QStringLiteral("previousSibling"), QV4::NodePrototype::method_get_previousSibling, nullptr); + o->defineAccessorProperty(QStringLiteral("nextSibling"), QV4::NodePrototype::method_get_nextSibling, nullptr); + o->defineAccessorProperty(QStringLiteral("attributes"), QV4::NodePrototype::method_get_attributes, nullptr); } @@ -355,10 +355,10 @@ class Attr : public Node { public: // JS API - static ReturnedValue method_name(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_name(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // static void specified(CallContext *); - static ReturnedValue method_value(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_ownerElement(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_value(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_ownerElement(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // static void schemaTypeInfo(CallContext *); // static void isId(CallContext *c); @@ -370,7 +370,7 @@ class CharacterData : public Node { public: // JS API - static ReturnedValue method_length(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_length(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // C++ API static ReturnedValue prototype(ExecutionEngine *v4); @@ -380,8 +380,8 @@ class Text : public CharacterData { public: // JS API - static ReturnedValue method_isElementContentWhitespace(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_wholeText(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_isElementContentWhitespace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_wholeText(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // C++ API static ReturnedValue prototype(ExecutionEngine *); @@ -398,10 +398,10 @@ class Document : public Node { public: // JS API - static ReturnedValue method_xmlVersion(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_xmlEncoding(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_xmlStandalone(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_documentElement(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_xmlVersion(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_xmlEncoding(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_xmlStandalone(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_documentElement(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // C++ API static ReturnedValue prototype(ExecutionEngine *); @@ -420,10 +420,10 @@ void NodeImpl::release() document->release(); } -ReturnedValue NodePrototype::method_get_nodeName(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_nodeName(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -445,10 +445,10 @@ ReturnedValue NodePrototype::method_get_nodeName(const BuiltinFunction *b, QV4:: return Encode(scope.engine->newString(name)); } -ReturnedValue NodePrototype::method_get_nodeValue(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_nodeValue(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -464,30 +464,30 @@ ReturnedValue NodePrototype::method_get_nodeValue(const BuiltinFunction *b, QV4: return Encode(scope.engine->newString(r->d()->d->data)); } -ReturnedValue NodePrototype::method_get_nodeType(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_nodeType(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); return Encode(r->d()->d->type); } -ReturnedValue NodePrototype::method_get_namespaceUri(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_namespaceUri(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); return Encode(scope.engine->newString(r->d()->d->namespaceUri)); } -ReturnedValue NodePrototype::method_get_parentNode(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_parentNode(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -497,20 +497,20 @@ ReturnedValue NodePrototype::method_get_parentNode(const BuiltinFunction *b, QV4 return Encode::null(); } -ReturnedValue NodePrototype::method_get_childNodes(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_childNodes(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); return NodeList::create(scope.engine, r->d()->d); } -ReturnedValue NodePrototype::method_get_firstChild(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_firstChild(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -520,10 +520,10 @@ ReturnedValue NodePrototype::method_get_firstChild(const BuiltinFunction *b, QV4 return Node::create(scope.engine, r->d()->d->children.constFirst()); } -ReturnedValue NodePrototype::method_get_lastChild(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_lastChild(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -533,10 +533,10 @@ ReturnedValue NodePrototype::method_get_lastChild(const BuiltinFunction *b, QV4: return Node::create(scope.engine, r->d()->d->children.constLast()); } -ReturnedValue NodePrototype::method_get_previousSibling(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_previousSibling(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -555,10 +555,10 @@ ReturnedValue NodePrototype::method_get_previousSibling(const BuiltinFunction *b return Encode::null(); } -ReturnedValue NodePrototype::method_get_nextSibling(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_nextSibling(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -577,10 +577,10 @@ ReturnedValue NodePrototype::method_get_nextSibling(const BuiltinFunction *b, QV return Encode::null(); } -ReturnedValue NodePrototype::method_get_attributes(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue NodePrototype::method_get_attributes(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) THROW_TYPE_ERROR(); @@ -644,7 +644,7 @@ ReturnedValue Element::prototype(ExecutionEngine *engine) ScopedObject p(scope, engine->newObject()); ScopedObject pp(scope); p->setPrototype((pp = NodePrototype::getProto(engine))); - p->defineAccessorProperty(QStringLiteral("tagName"), NodePrototype::method_get_nodeName, 0); + p->defineAccessorProperty(QStringLiteral("tagName"), NodePrototype::method_get_nodeName, nullptr); d->elementPrototype.set(engine, p); engine->v8Engine->freezeObject(p); } @@ -659,49 +659,49 @@ ReturnedValue Attr::prototype(ExecutionEngine *engine) ScopedObject p(scope, engine->newObject()); ScopedObject pp(scope); p->setPrototype((pp = NodePrototype::getProto(engine))); - p->defineAccessorProperty(QStringLiteral("name"), method_name, 0); - p->defineAccessorProperty(QStringLiteral("value"), method_value, 0); - p->defineAccessorProperty(QStringLiteral("ownerElement"), method_ownerElement, 0); + p->defineAccessorProperty(QStringLiteral("name"), method_name, nullptr); + p->defineAccessorProperty(QStringLiteral("value"), method_value, nullptr); + p->defineAccessorProperty(QStringLiteral("ownerElement"), method_ownerElement, nullptr); d->attrPrototype.set(engine, p); engine->v8Engine->freezeObject(p); } return d->attrPrototype.value(); } -ReturnedValue Attr::method_name(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Attr::method_name(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); return Encode(scope.engine->newString(r->d()->d->name)); } -ReturnedValue Attr::method_value(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Attr::method_value(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); return Encode(scope.engine->newString(r->d()->d->data)); } -ReturnedValue Attr::method_ownerElement(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Attr::method_ownerElement(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); return Node::create(scope.engine, r->d()->d->parent); } -ReturnedValue CharacterData::method_length(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue CharacterData::method_length(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); @@ -716,28 +716,28 @@ ReturnedValue CharacterData::prototype(ExecutionEngine *v4) ScopedObject p(scope, v4->newObject()); ScopedObject pp(scope); p->setPrototype((pp = NodePrototype::getProto(v4))); - p->defineAccessorProperty(QStringLiteral("data"), NodePrototype::method_get_nodeValue, 0); - p->defineAccessorProperty(QStringLiteral("length"), method_length, 0); + p->defineAccessorProperty(QStringLiteral("data"), NodePrototype::method_get_nodeValue, nullptr); + p->defineAccessorProperty(QStringLiteral("length"), method_length, nullptr); d->characterDataPrototype.set(v4, p); v4->v8Engine->freezeObject(p); } return d->characterDataPrototype.value(); } -ReturnedValue Text::method_isElementContentWhitespace(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Text::method_isElementContentWhitespace(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); return Encode(QStringRef(&r->d()->d->data).trimmed().isEmpty()); } -ReturnedValue Text::method_wholeText(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Text::method_wholeText(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r) RETURN_UNDEFINED(); @@ -752,8 +752,8 @@ ReturnedValue Text::prototype(ExecutionEngine *v4) ScopedObject p(scope, v4->newObject()); ScopedObject pp(scope); p->setPrototype((pp = CharacterData::prototype(v4))); - p->defineAccessorProperty(QStringLiteral("isElementContentWhitespace"), method_isElementContentWhitespace, 0); - p->defineAccessorProperty(QStringLiteral("wholeText"), method_wholeText, 0); + p->defineAccessorProperty(QStringLiteral("isElementContentWhitespace"), method_isElementContentWhitespace, nullptr); + p->defineAccessorProperty(QStringLiteral("wholeText"), method_wholeText, nullptr); d->textPrototype.set(v4, p); v4->v8Engine->freezeObject(p); } @@ -783,10 +783,10 @@ ReturnedValue Document::prototype(ExecutionEngine *v4) ScopedObject p(scope, v4->newObject()); ScopedObject pp(scope); p->setPrototype((pp = NodePrototype::getProto(v4))); - p->defineAccessorProperty(QStringLiteral("xmlVersion"), method_xmlVersion, 0); - p->defineAccessorProperty(QStringLiteral("xmlEncoding"), method_xmlEncoding, 0); - p->defineAccessorProperty(QStringLiteral("xmlStandalone"), method_xmlStandalone, 0); - p->defineAccessorProperty(QStringLiteral("documentElement"), method_documentElement, 0); + p->defineAccessorProperty(QStringLiteral("xmlVersion"), method_xmlVersion, nullptr); + p->defineAccessorProperty(QStringLiteral("xmlEncoding"), method_xmlEncoding, nullptr); + p->defineAccessorProperty(QStringLiteral("xmlStandalone"), method_xmlStandalone, nullptr); + p->defineAccessorProperty(QStringLiteral("documentElement"), method_documentElement, nullptr); d->documentPrototype.set(v4, p); v4->v8Engine->freezeObject(p); } @@ -797,7 +797,7 @@ ReturnedValue Document::load(ExecutionEngine *v4, const QByteArray &data) { Scope scope(v4); - DocumentImpl *document = 0; + DocumentImpl *document = nullptr; QStack<NodeImpl *> nodeStack; QXmlStreamReader reader(data); @@ -885,7 +885,7 @@ ReturnedValue Document::load(ExecutionEngine *v4, const QByteArray &data) bool Node::isNull() const { - return d()->d == 0; + return d()->d == nullptr; } ReturnedValue NamedNodeMap::getIndexed(const Managed *m, uint index, bool *hasProperty) @@ -967,40 +967,40 @@ ReturnedValue NodeList::create(ExecutionEngine *v4, NodeImpl *data) return (v4->memoryManager->allocObject<NodeList>(data))->asReturnedValue(); } -ReturnedValue Document::method_documentElement(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Document::method_documentElement(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r || r->d()->d->type != NodeImpl::Document) RETURN_UNDEFINED(); return Node::create(scope.engine, static_cast<DocumentImpl *>(r->d()->d)->root); } -ReturnedValue Document::method_xmlStandalone(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Document::method_xmlStandalone(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r || r->d()->d->type != NodeImpl::Document) RETURN_UNDEFINED(); return Encode(static_cast<DocumentImpl *>(r->d()->d)->isStandalone); } -ReturnedValue Document::method_xmlVersion(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Document::method_xmlVersion(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r || r->d()->d->type != NodeImpl::Document) RETURN_UNDEFINED(); return Encode(scope.engine->newString(static_cast<DocumentImpl *>(r->d()->d)->version)); } -ReturnedValue Document::method_xmlEncoding(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue Document::method_xmlEncoding(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<Node> r(scope, callData->thisObject.as<Node>()); + Scoped<Node> r(scope, thisObject->as<Node>()); if (!r || r->d()->d->type != NodeImpl::Document) RETURN_UNDEFINED(); @@ -1098,7 +1098,7 @@ private: QQmlXMLHttpRequest::QQmlXMLHttpRequest(QNetworkAccessManager *manager) : m_state(Unsent), m_errorFlag(false), m_sendFlag(false) - , m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager) + , m_redirectCount(0), m_gotXml(false), m_textCodec(nullptr), m_network(nullptr), m_nam(manager) , m_responseType() , m_parsedDocument() { @@ -1443,7 +1443,7 @@ void QQmlXMLHttpRequest::finished() dispatchCallback(); m_thisObject.clear(); - m_qmlContext.setContextData(0); + m_qmlContext.setContextData(nullptr); } @@ -1516,7 +1516,7 @@ QV4::ReturnedValue QQmlXMLHttpRequest::xmlResponseBody(QV4::ExecutionEngine* eng #if QT_CONFIG(textcodec) QTextCodec* QQmlXMLHttpRequest::findTextCodec() const { - QTextCodec *codec = 0; + QTextCodec *codec = nullptr; if (!m_charset.isEmpty()) codec = QTextCodec::codecForName(m_charset); @@ -1528,10 +1528,10 @@ QTextCodec* QQmlXMLHttpRequest::findTextCodec() const } if (!codec && m_mime == "text/html") - codec = QTextCodec::codecForHtml(m_responseEntityBody, 0); + codec = QTextCodec::codecForHtml(m_responseEntityBody, nullptr); if (!codec) - codec = QTextCodec::codecForUtfText(m_responseEntityBody, 0); + codec = QTextCodec::codecForUtfText(m_responseEntityBody, nullptr); if (!codec) codec = QTextCodec::codecForName("UTF-8"); @@ -1595,7 +1595,7 @@ void QQmlXMLHttpRequest::destroyNetwork() if (m_network) { m_network->disconnect(); m_network->deleteLater(); - m_network = 0; + m_network = nullptr; } } @@ -1653,21 +1653,21 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject void setupProto(); - static ReturnedValue method_open(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_setRequestHeader(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_send(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_abort(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_getResponseHeader(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_getAllResponseHeaders(const BuiltinFunction *b, QV4::CallData *callData); - - static ReturnedValue method_get_readyState(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_status(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_statusText(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_responseText(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_responseXML(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_response(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_get_responseType(const BuiltinFunction *b, QV4::CallData *callData); - static ReturnedValue method_set_responseType(const BuiltinFunction *b, QV4::CallData *callData); + static ReturnedValue method_open(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_setRequestHeader(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_send(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_abort(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_getResponseHeader(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_getAllResponseHeaders(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_get_readyState(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_status(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_statusText(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_responseText(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_responseXML(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_response(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_responseType(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_set_responseType(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); }; } @@ -1709,12 +1709,12 @@ void QQmlXMLHttpRequestCtor::setupProto() p->defineDefaultProperty(QStringLiteral("getAllResponseHeaders"), method_getAllResponseHeaders); // Read-only properties - p->defineAccessorProperty(QStringLiteral("readyState"), method_get_readyState, 0); - p->defineAccessorProperty(QStringLiteral("status"),method_get_status, 0); - p->defineAccessorProperty(QStringLiteral("statusText"),method_get_statusText, 0); - p->defineAccessorProperty(QStringLiteral("responseText"),method_get_responseText, 0); - p->defineAccessorProperty(QStringLiteral("responseXML"),method_get_responseXML, 0); - p->defineAccessorProperty(QStringLiteral("response"),method_get_response, 0); + p->defineAccessorProperty(QStringLiteral("readyState"), method_get_readyState, nullptr); + p->defineAccessorProperty(QStringLiteral("status"),method_get_status, nullptr); + p->defineAccessorProperty(QStringLiteral("statusText"),method_get_statusText, nullptr); + p->defineAccessorProperty(QStringLiteral("responseText"),method_get_responseText, nullptr); + p->defineAccessorProperty(QStringLiteral("responseXML"),method_get_responseXML, nullptr); + p->defineAccessorProperty(QStringLiteral("response"),method_get_response, nullptr); // Read-write properties p->defineAccessorProperty(QStringLiteral("responseType"), method_get_responseType, method_set_responseType); @@ -1729,19 +1729,19 @@ void QQmlXMLHttpRequestCtor::setupProto() // XMLHttpRequest methods -ReturnedValue QQmlXMLHttpRequestCtor::method_open(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_open(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - if (callData->argc() < 2 || callData->argc() > 5) + if (argc < 2 || argc > 5) THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count"); // Argument 0 - Method - QString method = callData->args[0].toQStringNoThrow().toUpper(); + QString method = argv[0].toQStringNoThrow().toUpper(); if (method != QLatin1String("GET") && method != QLatin1String("PUT") && method != QLatin1String("HEAD") && @@ -1753,23 +1753,23 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(const BuiltinFunction *b, QV4: THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Unsupported HTTP method type"); // Argument 1 - URL - QUrl url = QUrl(callData->args[1].toQStringNoThrow()); + QUrl url = QUrl(argv[1].toQStringNoThrow()); if (url.isRelative()) url = scope.engine->callingQmlContext()->resolvedUrl(url); bool async = true; // Argument 2 - async (optional) - if (callData->argc() > 2) { - async = callData->args[2].booleanValue(); + if (argc > 2) { + async = argv[2].booleanValue(); } // Argument 3/4 - user/pass (optional) QString username, password; - if (callData->argc() > 3) - username = callData->args[3].toQStringNoThrow(); - if (callData->argc() > 4) - password = callData->args[4].toQStringNoThrow(); + if (argc > 3) + username = argv[3].toQStringNoThrow(); + if (argc > 4) + password = argv[4].toQStringNoThrow(); // Clear the fragment (if any) url.setFragment(QString()); @@ -1781,22 +1781,22 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(const BuiltinFunction *b, QV4: return r->open(w, scope.engine->callingQmlContext(), method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad); } -ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - if (callData->argc() != 2) + if (argc != 2) THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count"); if (r->readyState() != QQmlXMLHttpRequest::Opened || r->sendFlag()) THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state"); - QString name = callData->args[0].toQStringNoThrow(); - QString value = callData->args[1].toQStringNoThrow(); + QString name = argv[0].toQStringNoThrow(); + QString value = argv[1].toQStringNoThrow(); // ### Check that name and value are well formed @@ -1828,10 +1828,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(const BuiltinFunct RETURN_UNDEFINED(); } -ReturnedValue QQmlXMLHttpRequestCtor::method_send(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_send(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1841,21 +1841,21 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_send(const BuiltinFunction *b, QV4: THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state"); QByteArray data; - if (callData->argc() > 0) { - if (const ArrayBuffer *buffer = callData->args[0].as<ArrayBuffer>()) { + if (argc > 0) { + if (const ArrayBuffer *buffer = argv[0].as<ArrayBuffer>()) { data = buffer->asByteArray(); } else { - data = callData->args[0].toQStringNoThrow().toUtf8(); + data = argv[0].toQStringNoThrow().toUtf8(); } } return r->send(w, scope.engine->callingQmlContext(), data); } -ReturnedValue QQmlXMLHttpRequestCtor::method_abort(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_abort(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1863,15 +1863,15 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_abort(const BuiltinFunction *b, QV4 return r->abort(w, scope.engine->callingQmlContext()); } -ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - if (callData->argc() != 1) + if (argc != 1) THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count"); if (r->readyState() != QQmlXMLHttpRequest::Loading && @@ -1879,18 +1879,18 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(const BuiltinFunc r->readyState() != QQmlXMLHttpRequest::HeadersReceived) THROW_DOM(DOMEXCEPTION_INVALID_STATE_ERR, "Invalid state"); - return Encode(scope.engine->newString(r->header(callData->args[0].toQStringNoThrow()))); + return Encode(scope.engine->newString(r->header(argv[0].toQStringNoThrow()))); } -ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(const FunctionObject *b, const Value *thisObject, const Value *, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - if (callData->argc() != 0) + if (argc != 0) THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count"); if (r->readyState() != QQmlXMLHttpRequest::Loading && @@ -1902,10 +1902,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_getAllResponseHeaders(const Builtin } // XMLHttpRequest properties -ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1913,10 +1913,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_readyState(const BuiltinFunctio return Encode(r->readyState()); } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1931,10 +1931,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_status(const BuiltinFunction *b return Encode(r->replyStatus()); } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1949,10 +1949,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_statusText(const BuiltinFunctio return Encode(scope.engine->newString(r->replyStatusText())); } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1964,10 +1964,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseText(const BuiltinFunct return Encode(scope.engine->newString(r->responseBody())); } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -1983,10 +1983,10 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseXML(const BuiltinFuncti } } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_response(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_response(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; @@ -2010,29 +2010,29 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_get_response(const BuiltinFunction } -ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseType(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_get_responseType(const FunctionObject *b, const Value *thisObject, const Value *, int) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; return Encode(scope.engine->newString(r->responseType())); } -ReturnedValue QQmlXMLHttpRequestCtor::method_set_responseType(const BuiltinFunction *b, QV4::CallData *callData) +ReturnedValue QQmlXMLHttpRequestCtor::method_set_responseType(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { Scope scope(b); - Scoped<QQmlXMLHttpRequestWrapper> w(scope, callData->thisObject.as<QQmlXMLHttpRequestWrapper>()); + Scoped<QQmlXMLHttpRequestWrapper> w(scope, thisObject->as<QQmlXMLHttpRequestWrapper>()); if (!w) V4THROW_REFERENCE("Not an XMLHttpRequest object"); QQmlXMLHttpRequest *r = w->d()->request; - if (callData->argc() < 1) + if (argc < 1) THROW_DOM(DOMEXCEPTION_SYNTAX_ERR, "Incorrect argument count"); // Argument 0 - response type - r->setResponseType(callData->args[0].toQStringNoThrow()); + r->setResponseType(argv[0].toQStringNoThrow()); return Encode::undefined(); } diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 3627f29cb2..1371f1f041 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -151,10 +151,10 @@ void Heap::QtObject::init(QQmlEngine *qmlEngine) o->defineDefaultProperty(QStringLiteral("createComponent"), QV4::QtObject::method_createComponent); } - o->defineAccessorProperty(QStringLiteral("platform"), QV4::QtObject::method_get_platform, 0); - o->defineAccessorProperty(QStringLiteral("application"), QV4::QtObject::method_get_application, 0); - o->defineAccessorProperty(QStringLiteral("inputMethod"), QV4::QtObject::method_get_inputMethod, 0); - o->defineAccessorProperty(QStringLiteral("styleHints"), QV4::QtObject::method_get_styleHints, 0); + o->defineAccessorProperty(QStringLiteral("platform"), QV4::QtObject::method_get_platform, nullptr); + o->defineAccessorProperty(QStringLiteral("application"), QV4::QtObject::method_get_application, nullptr); + o->defineAccessorProperty(QStringLiteral("inputMethod"), QV4::QtObject::method_get_inputMethod, nullptr); + o->defineAccessorProperty(QStringLiteral("styleHints"), QV4::QtObject::method_get_styleHints, nullptr); o->defineDefaultProperty(QStringLiteral("callLater"), QV4::QtObject::method_callLater); } @@ -228,12 +228,12 @@ void QtObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint \qmlmethod bool Qt::isQtObject(object) Returns true if \c object is a valid reference to a Qt or QML object, otherwise false. */ -ReturnedValue QtObject::method_isQtObject(const BuiltinFunction *, CallData *callData) +ReturnedValue QtObject::method_isQtObject(const FunctionObject *, const Value *, const Value *argv, int argc) { - if (callData->argc() == 0) + if (argc == 0) RETURN_RESULT(QV4::Encode(false)); - return QV4::Encode(callData->args[0].as<QV4::QObjectWrapper>() != 0); + return QV4::Encode(argv[0].as<QV4::QObjectWrapper>() != nullptr); } /*! @@ -242,17 +242,16 @@ ReturnedValue QtObject::method_isQtObject(const BuiltinFunction *, CallData *cal Returns a color with the specified \c red, \c green, \c blue and \c alpha components. All components should be in the range 0-1 inclusive. */ -ReturnedValue QtObject::method_rgba(const BuiltinFunction *builtin, CallData *callData) +ReturnedValue QtObject::method_rgba(const FunctionObject *f, const Value *, const Value *argv, int argc) { - QV4::Scope scope(builtin); - int argCount = callData->argc(); - if (argCount < 3 || argCount > 4) + QV4::Scope scope(f); + if (argc < 3 || argc > 4) THROW_GENERIC_ERROR("Qt.rgba(): Invalid arguments"); - double r = callData->args[0].toNumber(); - double g = callData->args[1].toNumber(); - double b = callData->args[2].toNumber(); - double a = (argCount == 4) ? callData->args[3].toNumber() : 1; + double r = argv[0].toNumber(); + double g = argv[1].toNumber(); + double b = argv[2].toNumber(); + double a = (argc == 4) ? argv[3].toNumber() : 1; if (r < 0.0) r=0.0; if (r > 1.0) r=1.0; @@ -272,17 +271,17 @@ ReturnedValue QtObject::method_rgba(const BuiltinFunction *builtin, CallData *ca Returns a color with the specified \c hue, \c saturation, \c lightness and \c alpha components. All components should be in the range 0-1 inclusive. */ -ReturnedValue QtObject::method_hsla(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_hsla(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - int argCount = callData->argc(); + int argCount = argc; if (argCount < 3 || argCount > 4) THROW_GENERIC_ERROR("Qt.hsla(): Invalid arguments"); - double h = callData->args[0].toNumber(); - double s = callData->args[1].toNumber(); - double l = callData->args[2].toNumber(); - double a = (argCount == 4) ? callData->args[3].toNumber() : 1; + double h = argv[0].toNumber(); + double s = argv[1].toNumber(); + double l = argv[2].toNumber(); + double a = (argCount == 4) ? argv[3].toNumber() : 1; if (h < 0.0) h=0.0; if (h > 1.0) h=1.0; @@ -304,17 +303,17 @@ All components should be in the range 0-1 inclusive. \since 5.5 */ -ReturnedValue QtObject::method_hsva(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_hsva(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - int argCount = callData->argc(); + int argCount = argc; if (argCount < 3 || argCount > 4) THROW_GENERIC_ERROR("Qt.hsva(): Invalid arguments"); - double h = callData->args[0].toNumber(); - double s = callData->args[1].toNumber(); - double v = callData->args[2].toNumber(); - double a = (argCount == 4) ? callData->args[3].toNumber() : 1; + double h = argv[0].toNumber(); + double s = argv[1].toNumber(); + double v = argv[2].toNumber(); + double a = (argCount == 4) ? argv[3].toNumber() : 1; h = qBound(0.0, h, 1.0); s = qBound(0.0, s, 1.0); @@ -332,15 +331,15 @@ may be either color values or string values. If a string value is supplied it must be convertible to a color, as described for the \l{colorbasictypedocs}{color} basic type. */ -ReturnedValue QtObject::method_colorEqual(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_colorEqual(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 2) + if (argc != 2) THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid arguments"); bool ok = false; - QVariant lhs = scope.engine->toVariant(callData->args[0], -1); + QVariant lhs = scope.engine->toVariant(argv[0], -1); if (lhs.userType() == QVariant::String) { lhs = QQmlStringConverters::colorFromString(lhs.toString(), &ok); if (!ok) { @@ -350,7 +349,7 @@ ReturnedValue QtObject::method_colorEqual(const BuiltinFunction *b, CallData *ca THROW_GENERIC_ERROR("Qt.colorEqual(): Invalid arguments"); } - QVariant rhs = scope.engine->toVariant(callData->args[1], -1); + QVariant rhs = scope.engine->toVariant(argv[1], -1); if (rhs.userType() == QVariant::String) { rhs = QQmlStringConverters::colorFromString(rhs.toString(), &ok); if (!ok) { @@ -371,16 +370,16 @@ Returns a \c rect with the top-left corner at \c x, \c y and the specified \c wi The returned object has \c x, \c y, \c width and \c height attributes with the given values. */ -ReturnedValue QtObject::method_rect(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_rect(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 4) + if (argc != 4) THROW_GENERIC_ERROR("Qt.rect(): Invalid arguments"); - double x = callData->args[0].toNumber(); - double y = callData->args[1].toNumber(); - double w = callData->args[2].toNumber(); - double h = callData->args[3].toNumber(); + double x = argv[0].toNumber(); + double y = argv[1].toNumber(); + double w = argv[2].toNumber(); + double h = argv[3].toNumber(); return scope.engine->fromVariant(QVariant::fromValue(QRectF(x, y, w, h))); } @@ -389,14 +388,14 @@ ReturnedValue QtObject::method_rect(const BuiltinFunction *b, CallData *callData \qmlmethod point Qt::point(int x, int y) Returns a Point with the specified \c x and \c y coordinates. */ -ReturnedValue QtObject::method_point(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_point(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 2) + if (argc != 2) THROW_GENERIC_ERROR("Qt.point(): Invalid arguments"); - double x = callData->args[0].toNumber(); - double y = callData->args[1].toNumber(); + double x = argv[0].toNumber(); + double y = argv[1].toNumber(); return scope.engine->fromVariant(QVariant::fromValue(QPointF(x, y))); } @@ -405,14 +404,14 @@ ReturnedValue QtObject::method_point(const BuiltinFunction *b, CallData *callDat \qmlmethod Qt::size(int width, int height) Returns a Size with the specified \c width and \c height. */ -ReturnedValue QtObject::method_size(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_size(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 2) + if (argc != 2) THROW_GENERIC_ERROR("Qt.size(): Invalid arguments"); - double w = callData->args[0].toNumber(); - double h = callData->args[1].toNumber(); + double w = argv[0].toNumber(); + double h = argv[1].toNumber(); return scope.engine->fromVariant(QVariant::fromValue(QSizeF(w, h))); } @@ -425,15 +424,15 @@ key-value pairs where valid keys are the \l{fontbasictypedocs}{font} type's subproperty names, and the values are valid values for each subproperty. Invalid keys will be ignored. */ -ReturnedValue QtObject::method_font(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_font(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1 || !callData->args[0].isObject()) + if (argc != 1 || !argv[0].isObject()) THROW_GENERIC_ERROR("Qt.font(): Invalid arguments"); QV4::ExecutionEngine *v4 = scope.engine; bool ok = false; - QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(callData->args[0]), v4, &ok); + QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QFont, QQmlV4Handle(argv[0]), v4, &ok); if (!ok) THROW_GENERIC_ERROR("Qt.font(): Invalid argument: no valid font subproperties specified"); return scope.engine->fromVariant(v); @@ -445,15 +444,15 @@ ReturnedValue QtObject::method_font(const BuiltinFunction *b, CallData *callData \qmlmethod Qt::vector2d(real x, real y) Returns a Vector2D with the specified \c x and \c y. */ -ReturnedValue QtObject::method_vector2d(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_vector2d(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 2) + if (argc != 2) THROW_GENERIC_ERROR("Qt.vector2d(): Invalid arguments"); float xy[3]; // qvector2d uses float internally - xy[0] = callData->args[0].toNumber(); - xy[1] = callData->args[1].toNumber(); + xy[0] = argv[0].toNumber(); + xy[1] = argv[1].toNumber(); const void *params[] = { xy }; return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector2D, 1, params)); @@ -463,16 +462,16 @@ ReturnedValue QtObject::method_vector2d(const BuiltinFunction *b, CallData *call \qmlmethod Qt::vector3d(real x, real y, real z) Returns a Vector3D with the specified \c x, \c y and \c z. */ -ReturnedValue QtObject::method_vector3d(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_vector3d(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 3) + if (argc != 3) THROW_GENERIC_ERROR("Qt.vector3d(): Invalid arguments"); float xyz[3]; // qvector3d uses float internally - xyz[0] = callData->args[0].toNumber(); - xyz[1] = callData->args[1].toNumber(); - xyz[2] = callData->args[2].toNumber(); + xyz[0] = argv[0].toNumber(); + xyz[1] = argv[1].toNumber(); + xyz[2] = argv[2].toNumber(); const void *params[] = { xyz }; return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector3D, 1, params)); @@ -482,17 +481,17 @@ ReturnedValue QtObject::method_vector3d(const BuiltinFunction *b, CallData *call \qmlmethod Qt::vector4d(real x, real y, real z, real w) Returns a Vector4D with the specified \c x, \c y, \c z and \c w. */ -ReturnedValue QtObject::method_vector4d(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_vector4d(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 4) + if (argc != 4) THROW_GENERIC_ERROR("Qt.vector4d(): Invalid arguments"); float xyzw[4]; // qvector4d uses float internally - xyzw[0] = callData->args[0].toNumber(); - xyzw[1] = callData->args[1].toNumber(); - xyzw[2] = callData->args[2].toNumber(); - xyzw[3] = callData->args[3].toNumber(); + xyzw[0] = argv[0].toNumber(); + xyzw[1] = argv[1].toNumber(); + xyzw[2] = argv[2].toNumber(); + xyzw[3] = argv[3].toNumber(); const void *params[] = { xyzw }; return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QVector4D, 1, params)); @@ -502,17 +501,17 @@ ReturnedValue QtObject::method_vector4d(const BuiltinFunction *b, CallData *call \qmlmethod Qt::quaternion(real scalar, real x, real y, real z) Returns a Quaternion with the specified \c scalar, \c x, \c y, and \c z. */ -ReturnedValue QtObject::method_quaternion(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_quaternion(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 4) + if (argc != 4) THROW_GENERIC_ERROR("Qt.quaternion(): Invalid arguments"); qreal sxyz[4]; // qquaternion uses qreal internally - sxyz[0] = callData->args[0].toNumber(); - sxyz[1] = callData->args[1].toNumber(); - sxyz[2] = callData->args[2].toNumber(); - sxyz[3] = callData->args[3].toNumber(); + sxyz[0] = argv[0].toNumber(); + sxyz[1] = argv[1].toNumber(); + sxyz[2] = argv[2].toNumber(); + sxyz[3] = argv[3].toNumber(); const void *params[] = { sxyz }; return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QQuaternion, 1, params)); @@ -527,42 +526,42 @@ matrix values. Finally, the function may be called with no arguments and the resulting matrix will be the identity matrix. */ -ReturnedValue QtObject::method_matrix4x4(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_matrix4x4(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() == 0) { + if (argc == 0) { return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 0, nullptr)); } - if (callData->argc() == 1 && callData->args[0].isObject()) { + if (argc == 1 && argv[0].isObject()) { bool ok = false; - QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(callData->args[0]), scope.engine, &ok); + QVariant v = QQml_valueTypeProvider()->createVariantFromJsObject(QMetaType::QMatrix4x4, QQmlV4Handle(argv[0]), scope.engine, &ok); if (!ok) THROW_GENERIC_ERROR("Qt.matrix4x4(): Invalid argument: not a valid matrix4x4 values array"); return scope.engine->fromVariant(v); } - if (callData->argc() != 16) + if (argc != 16) THROW_GENERIC_ERROR("Qt.matrix4x4(): Invalid arguments"); qreal vals[16]; // qmatrix4x4 uses qreal internally - vals[0] = callData->args[0].toNumber(); - vals[1] = callData->args[1].toNumber(); - vals[2] = callData->args[2].toNumber(); - vals[3] = callData->args[3].toNumber(); - vals[4] = callData->args[4].toNumber(); - vals[5] = callData->args[5].toNumber(); - vals[6] = callData->args[6].toNumber(); - vals[7] = callData->args[7].toNumber(); - vals[8] = callData->args[8].toNumber(); - vals[9] = callData->args[9].toNumber(); - vals[10] = callData->args[10].toNumber(); - vals[11] = callData->args[11].toNumber(); - vals[12] = callData->args[12].toNumber(); - vals[13] = callData->args[13].toNumber(); - vals[14] = callData->args[14].toNumber(); - vals[15] = callData->args[15].toNumber(); + vals[0] = argv[0].toNumber(); + vals[1] = argv[1].toNumber(); + vals[2] = argv[2].toNumber(); + vals[3] = argv[3].toNumber(); + vals[4] = argv[4].toNumber(); + vals[5] = argv[5].toNumber(); + vals[6] = argv[6].toNumber(); + vals[7] = argv[7].toNumber(); + vals[8] = argv[8].toNumber(); + vals[9] = argv[9].toNumber(); + vals[10] = argv[10].toNumber(); + vals[11] = argv[11].toNumber(); + vals[12] = argv[12].toNumber(); + vals[13] = argv[13].toNumber(); + vals[14] = argv[14].toNumber(); + vals[15] = argv[15].toNumber(); const void *params[] = { vals }; return scope.engine->fromVariant(QQml_valueTypeProvider()->createValueType(QMetaType::QMatrix4x4, 1, params)); @@ -582,13 +581,13 @@ by factor and converts the color back to RGB. If \c factor is not supplied, returns a color 50% lighter than \c baseColor (factor 1.5). */ -ReturnedValue QtObject::method_lighter(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_lighter(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1 && callData->argc() != 2) + if (argc != 1 && argc != 2) THROW_GENERIC_ERROR("Qt.lighter(): Invalid arguments"); - QVariant v = scope.engine->toVariant(callData->args[0], -1); + QVariant v = scope.engine->toVariant(argv[0], -1); if (v.userType() == QVariant::String) { bool ok = false; v = QQmlStringConverters::colorFromString(v.toString(), &ok); @@ -600,8 +599,8 @@ ReturnedValue QtObject::method_lighter(const BuiltinFunction *b, CallData *callD } qreal factor = 1.5; - if (callData->argc() == 2) - factor = callData->args[1].toNumber(); + if (argc == 2) + factor = argv[1].toNumber(); return scope.engine->fromVariant(QQml_colorProvider()->lighter(v, factor)); } @@ -621,13 +620,13 @@ by factor and converts the color back to RGB. If \c factor is not supplied, returns a color 50% darker than \c baseColor (factor 2.0). */ -ReturnedValue QtObject::method_darker(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_darker(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1 && callData->argc() != 2) + if (argc != 1 && argc != 2) THROW_GENERIC_ERROR("Qt.darker(): Invalid arguments"); - QVariant v = scope.engine->toVariant(callData->args[0], -1); + QVariant v = scope.engine->toVariant(argv[0], -1); if (v.userType() == QVariant::String) { bool ok = false; v = QQmlStringConverters::colorFromString(v.toString(), &ok); @@ -639,8 +638,8 @@ ReturnedValue QtObject::method_darker(const BuiltinFunction *b, CallData *callDa } qreal factor = 2.0; - if (callData->argc() == 2) - factor = callData->args[1].toNumber(); + if (argc == 2) + factor = argv[1].toNumber(); return scope.engine->fromVariant(QQml_colorProvider()->darker(v, factor)); } @@ -669,14 +668,14 @@ ReturnedValue QtObject::method_darker(const BuiltinFunction *b, CallData *callDa Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color. */ -ReturnedValue QtObject::method_tint(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_tint(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 2) + if (argc != 2) THROW_GENERIC_ERROR("Qt.tint(): Invalid arguments"); // base color - QVariant v1 = scope.engine->toVariant(callData->args[0], -1); + QVariant v1 = scope.engine->toVariant(argv[0], -1); if (v1.userType() == QVariant::String) { bool ok = false; v1 = QQmlStringConverters::colorFromString(v1.toString(), &ok); @@ -688,7 +687,7 @@ ReturnedValue QtObject::method_tint(const BuiltinFunction *b, CallData *callData } // tint color - QVariant v2 = scope.engine->toVariant(callData->args[1], -1); + QVariant v2 = scope.engine->toVariant(argv[1], -1); if (v2.userType() == QVariant::String) { bool ok = false; v2 = QQmlStringConverters::colorFromString(v2.toString(), &ok); @@ -718,22 +717,22 @@ If \a format is not specified, \a date is formatted using \sa Locale */ -ReturnedValue QtObject::method_formatDate(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_formatDate(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1 || callData->argc() > 2) + if (argc < 1 || argc > 2) THROW_GENERIC_ERROR("Qt.formatDate(): Invalid arguments"); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; - QDate date = scope.engine->toVariant(callData->args[0], -1).toDateTime().date(); + QDate date = scope.engine->toVariant(argv[0], -1).toDateTime().date(); QString formattedDate; - if (callData->argc() == 2) { - QV4::ScopedString s(scope, callData->args[1]); + if (argc == 2) { + QV4::ScopedString s(scope, argv[1]); if (s) { QString format = s->toQString(); formattedDate = date.toString(format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].asDouble(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].asDouble(); Qt::DateFormat format = Qt::DateFormat(intFormat); formattedDate = date.toString(format); } else { @@ -761,28 +760,28 @@ If \a format is not specified, \a time is formatted using \sa Locale */ -ReturnedValue QtObject::method_formatTime(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_formatTime(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1 || callData->argc() > 2) + if (argc < 1 || argc > 2) THROW_GENERIC_ERROR("Qt.formatTime(): Invalid arguments"); - QVariant argVariant = scope.engine->toVariant(callData->args[0], -1); + QVariant argVariant = scope.engine->toVariant(argv[0], -1); QTime time; - if (callData->args[0].as<DateObject>() || (argVariant.type() == QVariant::String)) + if (argv[0].as<DateObject>() || (argVariant.type() == QVariant::String)) time = argVariant.toDateTime().time(); else // if (argVariant.type() == QVariant::Time), or invalid. time = argVariant.toTime(); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; QString formattedTime; - if (callData->argc() == 2) { - QV4::ScopedString s(scope, callData->args[1]); + if (argc == 2) { + QV4::ScopedString s(scope, argv[1]); if (s) { QString format = s->toQString(); formattedTime = time.toString(format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].asDouble(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].asDouble(); Qt::DateFormat format = Qt::DateFormat(intFormat); formattedTime = time.toString(format); } else { @@ -887,22 +886,22 @@ with the \a format values below to produce the following results: \sa Locale */ -ReturnedValue QtObject::method_formatDateTime(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_formatDateTime(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1 || callData->argc() > 2) + if (argc < 1 || argc > 2) THROW_GENERIC_ERROR("Qt.formatDateTime(): Invalid arguments"); Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate; - QDateTime dt = scope.engine->toVariant(callData->args[0], -1).toDateTime(); + QDateTime dt = scope.engine->toVariant(argv[0], -1).toDateTime(); QString formattedDt; - if (callData->argc() == 2) { - QV4::ScopedString s(scope, callData->args[1]); + if (argc == 2) { + QV4::ScopedString s(scope, argv[1]); if (s) { QString format = s->toQString(); formattedDt = dt.toString(format); - } else if (callData->args[1].isNumber()) { - quint32 intFormat = callData->args[1].asDouble(); + } else if (argv[1].isNumber()) { + quint32 intFormat = argv[1].asDouble(); Qt::DateFormat format = Qt::DateFormat(intFormat); formattedDt = dt.toString(format); } else { @@ -926,14 +925,13 @@ ReturnedValue QtObject::method_formatDateTime(const BuiltinFunction *b, CallData still fail to launch or fail to open the requested URL. This result will not be reported back to the application. */ -ReturnedValue QtObject::method_openUrlExternally(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_openUrlExternally(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) { + if (argc != 1) return QV4::Encode(false); - } - ScopedValue result(scope, method_resolvedUrl(b, callData)); + ScopedValue result(scope, method_resolvedUrl(b, thisObject, argv, argc)); QUrl url(result->toQStringNoThrow()); return scope.engine->fromVariant(QQml_guiProvider()->openUrlExternally(url)); } @@ -942,13 +940,15 @@ ReturnedValue QtObject::method_openUrlExternally(const BuiltinFunction *b, CallD \qmlmethod url Qt::resolvedUrl(url url) Returns \a url resolved relative to the URL of the caller. */ -ReturnedValue QtObject::method_resolvedUrl(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_resolvedUrl(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); + if (argc != 1) + return Encode::undefined(); - QUrl url = scope.engine->toVariant(callData->args[0], -1).toUrl(); + QUrl url = scope.engine->toVariant(argv[0], -1).toUrl(); QQmlEngine *e = scope.engine->qmlEngine(); - QQmlEnginePrivate *p = 0; + QQmlEnginePrivate *p = nullptr; if (e) p = QQmlEnginePrivate::get(e); if (p) { QQmlContextData *ctxt = scope.engine->callingQmlContext(); @@ -965,10 +965,10 @@ ReturnedValue QtObject::method_resolvedUrl(const BuiltinFunction *b, CallData *c \qmlmethod list<string> Qt::fontFamilies() Returns a list of the font families available to the application. */ -ReturnedValue QtObject::method_fontFamilies(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_fontFamilies(const FunctionObject *b, const Value *, const Value *, int argc) { QV4::Scope scope(b); - if (callData->argc() != 0) + if (argc != 0) THROW_GENERIC_ERROR("Qt.fontFamilies(): Invalid arguments"); return scope.engine->fromVariant(QVariant(QQml_guiProvider()->fontFamilies())); @@ -978,13 +978,13 @@ ReturnedValue QtObject::method_fontFamilies(const BuiltinFunction *b, CallData * \qmlmethod string Qt::md5(data) Returns a hex string of the md5 hash of \c data. */ -ReturnedValue QtObject::method_md5(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_md5(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("Qt.md5(): Invalid arguments"); - QByteArray data = callData->args[0].toQStringNoThrow().toUtf8(); + QByteArray data = argv[0].toQStringNoThrow().toUtf8(); QByteArray result = QCryptographicHash::hash(data, QCryptographicHash::Md5); return Encode(scope.engine->newString(QLatin1String(result.toHex()))); } @@ -993,13 +993,13 @@ ReturnedValue QtObject::method_md5(const BuiltinFunction *b, CallData *callData) \qmlmethod string Qt::btoa(data) Binary to ASCII - this function returns a base64 encoding of \c data. */ -ReturnedValue QtObject::method_btoa(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_btoa(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("Qt.btoa(): Invalid arguments"); - QByteArray data = callData->args[0].toQStringNoThrow().toUtf8(); + QByteArray data = argv[0].toQStringNoThrow().toUtf8(); return Encode(scope.engine->newString(QLatin1String(data.toBase64()))); } @@ -1008,13 +1008,13 @@ ReturnedValue QtObject::method_btoa(const BuiltinFunction *b, CallData *callData \qmlmethod string Qt::atob(data) ASCII to binary - this function decodes the base64 encoded \a data string and returns it. */ -ReturnedValue QtObject::method_atob(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_atob(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("Qt.atob(): Invalid arguments"); - QByteArray data = callData->args[0].toQStringNoThrow().toLatin1(); + QByteArray data = argv[0].toQStringNoThrow().toLatin1(); return Encode(scope.engine->newString(QString::fromUtf8(QByteArray::fromBase64(data)))); } @@ -1028,7 +1028,7 @@ QQmlEngine::quit() signal to the QCoreApplication::quit() slot. \sa exit() */ -ReturnedValue QtObject::method_quit(const BuiltinFunction *b, CallData *) +ReturnedValue QtObject::method_quit(const FunctionObject *b, const Value *, const Value *, int) { QQmlEnginePrivate::get(b->engine()->qmlEngine())->sendQuit(); return Encode::undefined(); @@ -1045,13 +1045,13 @@ ReturnedValue QtObject::method_quit(const BuiltinFunction *b, CallData *) \sa quit() */ -ReturnedValue QtObject::method_exit(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_exit(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("Qt.exit(): Invalid arguments"); - int retCode = callData->args[0].toNumber(); + int retCode = argv[0].toNumber(); QQmlEnginePrivate::get(scope.engine->qmlEngine())->sendExit(retCode); return QV4::Encode::undefined(); @@ -1081,10 +1081,10 @@ If this is the case, consider using \l{QtQml::Qt::createComponent()}{Qt.createCo See \l {Dynamic QML Object Creation from JavaScript} for more information on using this function. */ -ReturnedValue QtObject::method_createQmlObject(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_createQmlObject(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 2 || callData->argc() > 3) + if (argc < 2 || argc > 3) THROW_GENERIC_ERROR("Qt.createQmlObject(): Invalid arguments"); struct Error { @@ -1116,33 +1116,37 @@ ReturnedValue QtObject::method_createQmlObject(const BuiltinFunction *b, CallDat } }; - QV8Engine *v8engine = scope.engine->v8Engine; - QQmlEngine *engine = v8engine->engine(); + QQmlEngine *engine = scope.engine->qmlEngine(); QQmlContextData *context = scope.engine->callingQmlContext(); + if (!context) { + QQmlEngine *qmlEngine = scope.engine->qmlEngine(); + if (qmlEngine) + context = QQmlContextData::get(QQmlEnginePrivate::get(qmlEngine)->rootContext); + } Q_ASSERT(context); - QQmlContext *effectiveContext = 0; + QQmlContext *effectiveContext = nullptr; if (context->isPragmaLibraryContext) effectiveContext = engine->rootContext(); else effectiveContext = context->asQQmlContext(); Q_ASSERT(effectiveContext); - QString qml = callData->args[0].toQStringNoThrow(); + QString qml = argv[0].toQStringNoThrow(); if (qml.isEmpty()) RETURN_RESULT(Encode::null()); QUrl url; - if (callData->argc() > 2) - url = QUrl(callData->args[2].toQStringNoThrow()); + if (argc > 2) + url = QUrl(argv[2].toQStringNoThrow()); else url = QUrl(QLatin1String("inline")); if (url.isValid() && url.isRelative()) url = context->resolvedUrl(url); - QObject *parentArg = 0; - QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, callData->args[1]); + QObject *parentArg = nullptr; + QV4::Scoped<QV4::QObjectWrapper> qobjectWrapper(scope, argv[1]); if (!!qobjectWrapper) parentArg = qobjectWrapper->object(); if (!parentArg) @@ -1238,46 +1242,50 @@ See \l {Dynamic QML Object Creation from JavaScript} for more information on usi To create a QML object from an arbitrary string of QML (instead of a file), use \l{QtQml::Qt::createQmlObject()}{Qt.createQmlObject()}. */ -ReturnedValue QtObject::method_createComponent(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_createComponent(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1 || callData->argc() > 3) + if (argc < 1 || argc > 3) THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments"); - QV8Engine *v8engine = scope.engine->v8Engine; - QQmlEngine *engine = v8engine->engine(); + QQmlEngine *engine = scope.engine->qmlEngine(); QQmlContextData *context = scope.engine->callingQmlContext(); + if (!context) { + QQmlEngine *qmlEngine = scope.engine->qmlEngine(); + if (qmlEngine) + context = QQmlContextData::get(QQmlEnginePrivate::get(qmlEngine)->rootContext); + } Q_ASSERT(context); QQmlContextData *effectiveContext = context; if (context->isPragmaLibraryContext) - effectiveContext = 0; + effectiveContext = nullptr; - QString arg = callData->args[0].toQStringNoThrow(); + QString arg = argv[0].toQStringNoThrow(); if (arg.isEmpty()) RETURN_RESULT(QV4::Encode::null()); QQmlComponent::CompilationMode compileMode = QQmlComponent::PreferSynchronous; - QObject *parentArg = 0; + QObject *parentArg = nullptr; int consumedCount = 1; - if (callData->argc() > 1) { - ScopedValue lastArg(scope, callData->args[callData->argc()-1]); + if (argc > 1) { + ScopedValue lastArg(scope, argv[argc-1]); // The second argument could be the mode enum - if (callData->args[1].isInteger()) { - int mode = callData->args[1].integerValue(); + if (argv[1].isInteger()) { + int mode = argv[1].integerValue(); if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous)) THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments"); compileMode = QQmlComponent::CompilationMode(mode); consumedCount += 1; } else { // The second argument could be the parent only if there are exactly two args - if ((callData->argc() != 2) || !(lastArg->isObject() || lastArg->isNull())) + if ((argc != 2) || !(lastArg->isObject() || lastArg->isNull())) THROW_GENERIC_ERROR("Qt.createComponent(): Invalid arguments"); } - if (consumedCount < callData->argc()) { + if (consumedCount < argc) { if (lastArg->isObject()) { Scoped<QObjectWrapper> qobjectWrapper(scope, lastArg); if (qobjectWrapper) @@ -1285,7 +1293,7 @@ ReturnedValue QtObject::method_createComponent(const BuiltinFunction *b, CallDat if (!parentArg) THROW_GENERIC_ERROR("Qt.createComponent(): Invalid parent object"); } else if (lastArg->isNull()) { - parentArg = 0; + parentArg = nullptr; } else { THROW_GENERIC_ERROR("Qt.createComponent(): Invalid parent object"); } @@ -1321,17 +1329,17 @@ ReturnedValue QtObject::method_createComponent(const BuiltinFunction *b, CallDat \sa Locale */ -ReturnedValue QtObject::method_locale(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_locale(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); QString code; - if (callData->argc() > 1) + if (argc > 1) THROW_GENERIC_ERROR("locale() requires 0 or 1 argument"); - if (callData->argc() == 1 && !callData->args[0].isString()) + if (argc == 1 && !argv[0].isString()) THROW_TYPE_ERROR_WITH_MESSAGE("locale(): argument (locale code) must be a string"); - if (callData->argc() == 1) - code = callData->args[0].toQStringNoThrow(); + if (argc == 1) + code = argv[0].toQStringNoThrow(); return QQmlLocale::locale(scope.engine, code); } @@ -1395,12 +1403,12 @@ DEFINE_OBJECT_VTABLE(QQmlBindingFunction); \since 5.0 */ -ReturnedValue QtObject::method_binding(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_binding(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("binding() requires 1 argument"); - const QV4::FunctionObject *f = callData->args[0].as<FunctionObject>(); + const QV4::FunctionObject *f = argv[0].as<FunctionObject>(); if (!f) THROW_TYPE_ERROR_WITH_MESSAGE("binding(): argument (binding expression) must be a function"); @@ -1408,14 +1416,14 @@ ReturnedValue QtObject::method_binding(const BuiltinFunction *b, CallData *callD } -ReturnedValue QtObject::method_get_platform(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_get_platform(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); // ### inefficient. Should be just a value based getter - Object *o = callData->thisObject.as<Object>(); + const Object *o = thisObject->as<Object>(); if (!o) THROW_TYPE_ERROR(); - QtObject *qt = o->as<QtObject>(); + const QtObject *qt = o->as<QtObject>(); if (!qt) THROW_TYPE_ERROR(); @@ -1426,14 +1434,14 @@ ReturnedValue QtObject::method_get_platform(const BuiltinFunction *b, CallData * return QV4::QObjectWrapper::wrap(scope.engine, qt->d()->platform); } -ReturnedValue QtObject::method_get_application(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_get_application(const FunctionObject *b, const Value *thisObject, const Value *, int) { QV4::Scope scope(b); // ### inefficient. Should be just a value based getter - Object *o = callData->thisObject.as<Object>(); + const Object *o = thisObject->as<Object>(); if (!o) THROW_TYPE_ERROR(); - QtObject *qt = o->as<QtObject>(); + const QtObject *qt = o->as<QtObject>(); if (!qt) THROW_TYPE_ERROR(); @@ -1444,13 +1452,13 @@ ReturnedValue QtObject::method_get_application(const BuiltinFunction *b, CallDat return QV4::QObjectWrapper::wrap(scope.engine, qt->d()->application); } -ReturnedValue QtObject::method_get_inputMethod(const BuiltinFunction *b, CallData *) +ReturnedValue QtObject::method_get_inputMethod(const FunctionObject *b, const Value *, const Value *, int) { QObject *o = QQml_guiProvider()->inputMethod(); return QV4::QObjectWrapper::wrap(b->engine(), o); } -ReturnedValue QtObject::method_get_styleHints(const BuiltinFunction *b, CallData *) +ReturnedValue QtObject::method_get_styleHints(const FunctionObject *b, const Value *, const Value *, int) { QObject *o = QQml_guiProvider()->styleHints(); return QV4::QObjectWrapper::wrap(b->engine(), o); @@ -1513,17 +1521,17 @@ static QString jsStack(QV4::ExecutionEngine *engine) { return stack; } -static ReturnedValue writeToConsole(const BuiltinFunction *b, CallData *callData, +static ReturnedValue writeToConsole(const FunctionObject *b, const Value *, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack = false) { - QLoggingCategory *loggingCategory = 0; + QLoggingCategory *loggingCategory = nullptr; QString result; QV4::Scope scope(b); QV4::ExecutionEngine *v4 = scope.engine; int start = 0; - if (callData->argc() > 0) { - if (const QObjectWrapper* wrapper = callData->args[0].as<QObjectWrapper>()) { + if (argc > 0) { + if (const QObjectWrapper* wrapper = argv[0].as<QObjectWrapper>()) { if (QQmlLoggingCategory* category = qobject_cast<QQmlLoggingCategory*>(wrapper->object())) { if (category->category()) loggingCategory = category->category(); @@ -1535,14 +1543,14 @@ static ReturnedValue writeToConsole(const BuiltinFunction *b, CallData *callData } - for (int i = start, ei = callData->argc(); i < ei; ++i) { + for (int i = start, ei = argc; i < ei; ++i) { if (i != start) result.append(QLatin1Char(' ')); - if (callData->args[i].as<ArrayObject>()) - result += QLatin1Char('[') + callData->args[i].toQStringNoThrow() + QLatin1Char(']'); + if (argv[i].as<ArrayObject>()) + result += QLatin1Char('[') + argv[i].toQStringNoThrow() + QLatin1Char(']'); else - result.append(callData->args[i].toQStringNoThrow()); + result.append(argv[i].toQStringNoThrow()); } if (printStack) @@ -1584,25 +1592,25 @@ static ReturnedValue writeToConsole(const BuiltinFunction *b, CallData *callData DEFINE_OBJECT_VTABLE(ConsoleObject); -ReturnedValue ConsoleObject::method_error(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_error(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - return writeToConsole(b, callData, Error); + return writeToConsole(b, thisObject, argv, argc, Error); } -ReturnedValue ConsoleObject::method_log(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_log(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { //console.log //console.debug //print - return writeToConsole(b, callData, Log); + return writeToConsole(b, thisObject, argv, argc, Log); } -ReturnedValue ConsoleObject::method_info(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_info(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - return writeToConsole(b, callData, Info); + return writeToConsole(b, thisObject, argv, argc, Info); } -ReturnedValue ConsoleObject::method_profile(const BuiltinFunction *b, CallData *) +ReturnedValue ConsoleObject::method_profile(const FunctionObject *b, const Value *, const Value *, int) { QV4::Scope scope(b); QV4::ExecutionEngine *v4 = scope.engine; @@ -1622,7 +1630,7 @@ ReturnedValue ConsoleObject::method_profile(const BuiltinFunction *b, CallData * return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_profileEnd(const BuiltinFunction *b, CallData *) +ReturnedValue ConsoleObject::method_profileEnd(const FunctionObject *b, const Value *, const Value *, int) { QV4::Scope scope(b); QV4::ExecutionEngine *v4 = scope.engine; @@ -1643,28 +1651,28 @@ ReturnedValue ConsoleObject::method_profileEnd(const BuiltinFunction *b, CallDat return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_time(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_time(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("console.time(): Invalid arguments"); QV8Engine *v8engine = scope.engine->v8Engine; - QString name = callData->args[0].toQStringNoThrow(); + QString name = argv[0].toQStringNoThrow(); v8engine->startTimer(name); return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_timeEnd(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_timeEnd(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("console.timeEnd(): Invalid arguments"); QV8Engine *v8engine = scope.engine->v8Engine; - QString name = callData->args[0].toQStringNoThrow(); + QString name = argv[0].toQStringNoThrow(); bool wasRunning; qint64 elapsed = v8engine->stopTimer(name, &wasRunning); if (wasRunning) { @@ -1673,12 +1681,12 @@ ReturnedValue ConsoleObject::method_timeEnd(const BuiltinFunction *b, CallData * return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_count(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_count(const FunctionObject *b, const Value *, const Value *argv, int argc) { // first argument: name to print. Ignore any additional arguments QString name; - if (callData->argc() > 0) - name = callData->args[0].toQStringNoThrow(); + if (argc > 0) + name = argv[0].toQStringNoThrow(); Scope scope(b); QV4::ExecutionEngine *v4 = scope.engine; @@ -1698,10 +1706,10 @@ ReturnedValue ConsoleObject::method_count(const BuiltinFunction *b, CallData *ca return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_trace(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_trace(const FunctionObject *b, const Value *, const Value *, int argc) { QV4::Scope scope(b); - if (callData->argc() != 0) + if (argc != 0) THROW_GENERIC_ERROR("console.trace(): Invalid arguments"); QV4::ExecutionEngine *v4 = scope.engine; @@ -1716,26 +1724,26 @@ ReturnedValue ConsoleObject::method_trace(const BuiltinFunction *b, CallData *ca return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_warn(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_warn(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { - return writeToConsole(b, callData, Warn); + return writeToConsole(b, thisObject, argv, argc, Warn); } -ReturnedValue ConsoleObject::method_assert(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_assert(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() == 0) + if (argc == 0) THROW_GENERIC_ERROR("console.assert(): Missing argument"); QV4::ExecutionEngine *v4 = scope.engine; - if (!callData->args[0].toBoolean()) { + if (!argv[0].toBoolean()) { QString message; - for (int i = 1, ei = callData->argc(); i < ei; ++i) { + for (int i = 1, ei = argc; i < ei; ++i) { if (i != 1) message.append(QLatin1Char(' ')); - message.append(callData->args[i].toQStringNoThrow()); + message.append(argv[i].toQStringNoThrow()); } QString stack = jsStack(v4); @@ -1749,13 +1757,13 @@ ReturnedValue ConsoleObject::method_assert(const BuiltinFunction *b, CallData *c return QV4::Encode::undefined(); } -ReturnedValue ConsoleObject::method_exception(const BuiltinFunction *b, CallData *callData) +ReturnedValue ConsoleObject::method_exception(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() == 0) + if (argc == 0) THROW_GENERIC_ERROR("console.exception(): Missing argument"); - return writeToConsole(b, callData, Error, true); + return writeToConsole(b, thisObject, argv, argc, Error, true); } @@ -1811,32 +1819,32 @@ void QV4::GlobalExtensions::init(Object *globalObject, QJSEngine::Extensions ext \sa {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTranslate(const BuiltinFunction *b, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTranslate(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 2) + if (argc < 2) THROW_GENERIC_ERROR("qsTranslate() requires at least two arguments"); - if (!callData->args[0].isString()) + if (!argv[0].isString()) THROW_GENERIC_ERROR("qsTranslate(): first argument (context) must be a string"); - if (!callData->args[1].isString()) + if (!argv[1].isString()) THROW_GENERIC_ERROR("qsTranslate(): second argument (sourceText) must be a string"); - if ((callData->argc() > 2) && !callData->args[2].isString()) + if ((argc > 2) && !argv[2].isString()) THROW_GENERIC_ERROR("qsTranslate(): third argument (disambiguation) must be a string"); - QString context = callData->args[0].toQStringNoThrow(); - QString text = callData->args[1].toQStringNoThrow(); + QString context = argv[0].toQStringNoThrow(); + QString text = argv[1].toQStringNoThrow(); QString comment; - if (callData->argc() > 2) comment = callData->args[2].toQStringNoThrow(); + if (argc > 2) comment = argv[2].toQStringNoThrow(); int i = 3; - if (callData->argc() > i && callData->args[i].isString()) { + if (argc > i && argv[i].isString()) { qWarning("qsTranslate(): specifying the encoding as fourth argument is deprecated"); ++i; } int n = -1; - if (callData->argc() > i) - n = callData->args[i].toInt32(); + if (argc > i) + n = argv[i].toInt32(); QString result = QCoreApplication::translate(context.toUtf8().constData(), text.toUtf8().constData(), @@ -1868,13 +1876,13 @@ ReturnedValue GlobalExtensions::method_qsTranslate(const BuiltinFunction *b, Cal \sa {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTranslateNoOp(const BuiltinFunction *b, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTranslateNoOp(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 2) + if (argc < 2) return QV4::Encode::undefined(); else - return callData->args[1].asReturnedValue(); + return argv[1].asReturnedValue(); } /*! @@ -1894,16 +1902,16 @@ ReturnedValue GlobalExtensions::method_qsTranslateNoOp(const BuiltinFunction *b, \sa {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTr(const BuiltinFunction *b, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTr(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1) + if (argc < 1) THROW_GENERIC_ERROR("qsTr() requires at least one argument"); - if (!callData->args[0].isString()) + if (!argv[0].isString()) THROW_GENERIC_ERROR("qsTr(): first argument (sourceText) must be a string"); - if ((callData->argc() > 1) && !callData->args[1].isString()) + if ((argc > 1) && !argv[1].isString()) THROW_GENERIC_ERROR("qsTr(): second argument (disambiguation) must be a string"); - if ((callData->argc() > 2) && !callData->args[2].isNumber()) + if ((argc > 2) && !argv[2].isNumber()) THROW_GENERIC_ERROR("qsTr(): third argument (n) must be a number"); QString context; @@ -1933,13 +1941,13 @@ ReturnedValue GlobalExtensions::method_qsTr(const BuiltinFunction *b, CallData * } } - QString text = callData->args[0].toQStringNoThrow(); + QString text = argv[0].toQStringNoThrow(); QString comment; - if (callData->argc() > 1) - comment = callData->args[1].toQStringNoThrow(); + if (argc > 1) + comment = argv[1].toQStringNoThrow(); int n = -1; - if (callData->argc() > 2) - n = callData->args[2].toInt32(); + if (argc > 2) + n = argv[2].toInt32(); QString result = QCoreApplication::translate(context.toUtf8().constData(), text.toUtf8().constData(), comment.toUtf8().constData(), n); @@ -1969,12 +1977,12 @@ ReturnedValue GlobalExtensions::method_qsTr(const BuiltinFunction *b, CallData * \sa {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTrNoOp(const BuiltinFunction *, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTrNoOp(const FunctionObject *, const Value *, const Value *argv, int argc) { - if (callData->argc() < 1) + if (argc < 1) return QV4::Encode::undefined(); else - return callData->args[0].asReturnedValue(); + return argv[0].asReturnedValue(); } /*! @@ -2007,21 +2015,21 @@ ReturnedValue GlobalExtensions::method_qsTrNoOp(const BuiltinFunction *, CallDat \sa QT_TRID_NOOP(), {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTrId(const BuiltinFunction *b, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTrId(const FunctionObject *b, const Value *, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() < 1) + if (argc < 1) THROW_GENERIC_ERROR("qsTrId() requires at least one argument"); - if (!callData->args[0].isString()) + if (!argv[0].isString()) THROW_TYPE_ERROR_WITH_MESSAGE("qsTrId(): first argument (id) must be a string"); - if (callData->argc() > 1 && !callData->args[1].isNumber()) + if (argc > 1 && !argv[1].isNumber()) THROW_TYPE_ERROR_WITH_MESSAGE("qsTrId(): second argument (n) must be a number"); int n = -1; - if (callData->argc() > 1) - n = callData->args[1].toInt32(); + if (argc > 1) + n = argv[1].toInt32(); - return Encode(scope.engine->newString(qtTrId(callData->args[0].toQStringNoThrow().toUtf8().constData(), n))); + return Encode(scope.engine->newString(qtTrId(argv[0].toQStringNoThrow().toUtf8().constData(), n))); } /*! @@ -2040,17 +2048,17 @@ ReturnedValue GlobalExtensions::method_qsTrId(const BuiltinFunction *b, CallData \sa qsTrId(), {Internationalization and Localization with Qt Quick} */ -ReturnedValue GlobalExtensions::method_qsTrIdNoOp(const BuiltinFunction *, CallData *callData) +ReturnedValue GlobalExtensions::method_qsTrIdNoOp(const FunctionObject *, const Value *, const Value *argv, int argc) { - if (callData->argc() < 1) + if (argc < 1) return QV4::Encode::undefined(); else - return callData->args[0].asReturnedValue(); + return argv[0].asReturnedValue(); } #endif // translation -ReturnedValue GlobalExtensions::method_gc(const BuiltinFunction *b, CallData *) +ReturnedValue GlobalExtensions::method_gc(const FunctionObject *b, const Value *, const Value *, int) { b->engine()->memoryManager->runGC(); @@ -2059,15 +2067,15 @@ ReturnedValue GlobalExtensions::method_gc(const BuiltinFunction *b, CallData *) -ReturnedValue GlobalExtensions::method_string_arg(const BuiltinFunction *b, CallData *callData) +ReturnedValue GlobalExtensions::method_string_arg(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { QV4::Scope scope(b); - if (callData->argc() != 1) + if (argc != 1) THROW_GENERIC_ERROR("String.arg(): Invalid arguments"); - QString value = callData->thisObject.toQString(); + QString value = thisObject->toQString(); - QV4::ScopedValue arg(scope, callData->args[0]); + QV4::ScopedValue arg(scope, argv[0]); if (arg->isInteger()) RETURN_RESULT(scope.engine->newString(value.arg(arg->integerValue()))); else if (arg->isDouble()) @@ -2098,10 +2106,10 @@ be passed on to the function invoked. Note that if redundant calls are eliminated, then only the last set of arguments will be passed to the function. */ -ReturnedValue QtObject::method_callLater(const BuiltinFunction *b, CallData *callData) +ReturnedValue QtObject::method_callLater(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc) { QV8Engine *v8engine = b->engine()->v8Engine; - return v8engine->delayedCallQueue()->addUniquelyAndExecuteLater(b, callData); + return v8engine->delayedCallQueue()->addUniquelyAndExecuteLater(b, thisObject, argv, argc); } QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index 7d61aa0ada..104dae5d79 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -93,45 +93,45 @@ struct QtObject : Object static ReturnedValue get(const Managed *m, String *name, bool *hasProperty); static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); - static ReturnedValue method_isQtObject(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_rgba(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_hsla(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_hsva(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_colorEqual(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_font(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_rect(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_point(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_size(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_vector2d(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_vector3d(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_vector4d(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_quaternion(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_matrix4x4(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_lighter(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_darker(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_tint(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_formatDate(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_formatTime(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_formatDateTime(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_openUrlExternally(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_fontFamilies(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_md5(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_btoa(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_atob(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_quit(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_exit(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_resolvedUrl(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_createQmlObject(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_createComponent(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_locale(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_binding(const BuiltinFunction *, CallData *callData); - - static ReturnedValue method_get_platform(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_application(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_inputMethod(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_get_styleHints(const BuiltinFunction *, CallData *callData); - - static ReturnedValue method_callLater(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_isQtObject(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_rgba(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_hsla(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_hsva(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_colorEqual(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_font(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_rect(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_point(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_size(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_vector2d(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_vector3d(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_vector4d(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_quaternion(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_matrix4x4(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_lighter(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_darker(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_tint(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_formatDate(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_formatTime(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_formatDateTime(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_openUrlExternally(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_fontFamilies(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_md5(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_btoa(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_atob(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_quit(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_exit(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_resolvedUrl(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_createQmlObject(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_createComponent(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_locale(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_binding(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_get_platform(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_application(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_inputMethod(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_get_styleHints(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + + static ReturnedValue method_callLater(const FunctionObject *, const Value *thisObject, const Value *argv, int argc); private: void addAll(); @@ -142,18 +142,18 @@ struct ConsoleObject : Object { V4_OBJECT2(ConsoleObject, Object) - static ReturnedValue method_error(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_log(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_info(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_profile(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_profileEnd(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_time(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_timeEnd(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_count(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_trace(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_warn(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_assert(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_exception(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_error(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_log(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_info(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_profile(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_profileEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_time(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_timeEnd(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_count(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_trace(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_warn(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_assert(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_exception(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); }; @@ -161,17 +161,17 @@ struct Q_QML_PRIVATE_EXPORT GlobalExtensions { static void init(Object *globalObject, QJSEngine::Extensions extensions); #if QT_CONFIG(translation) - static ReturnedValue method_qsTranslate(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_qsTranslateNoOp(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_qsTr(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_qsTrNoOp(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_qsTrId(const BuiltinFunction *, CallData *callData); - static ReturnedValue method_qsTrIdNoOp(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_qsTranslate(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_qsTranslateNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_qsTr(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_qsTrNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_qsTrId(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); + static ReturnedValue method_qsTrIdNoOp(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); #endif - static ReturnedValue method_gc(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_gc(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); // on String:prototype - static ReturnedValue method_string_arg(const BuiltinFunction *, CallData *callData); + static ReturnedValue method_string_arg(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc); }; diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 624e222241..bdb066267a 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -123,11 +123,11 @@ static void restoreJSValue(QDataStream &stream, void *data) } } -QV8Engine::QV8Engine(QJSEngine* qq) +QV8Engine::QV8Engine(QJSEngine *qq, QV4::ExecutionEngine *v4) : q(qq) - , m_engine(0) - , m_xmlHttpRequestData(0) - , m_listModelData(0) + , m_engine(nullptr) + , m_v4Engine(v4) + , m_xmlHttpRequestData(nullptr) { #ifndef Q_OS_HTML5 #ifdef Q_PROCESSOR_X86_32 @@ -149,8 +149,6 @@ QV8Engine::QV8Engine(QJSEngine* qq) QMetaType::registerConverter<QJSValue, QStringList>(convertJSValueToVariantType<QStringList>); QMetaType::registerStreamOperators(qMetaTypeId<QJSValue>(), saveJSValue, restoreJSValue); - m_v4Engine = new QV4::ExecutionEngine; - m_v4Engine->v8Engine = this; m_delayedCallQueue.init(m_v4Engine); QV4::QObjectWrapper::initializeBindings(m_v4Engine); @@ -163,13 +161,8 @@ QV8Engine::~QV8Engine() #if QT_CONFIG(xmlstreamreader) && QT_CONFIG(qml_network) qt_rem_qmlxmlhttprequest(m_v4Engine, m_xmlHttpRequestData); - m_xmlHttpRequestData = 0; + m_xmlHttpRequestData = nullptr; #endif - - delete m_listModelData; - m_listModelData = 0; - - delete m_v4Engine; } #if QT_CONFIG(qml_network) @@ -294,11 +287,6 @@ void QV8Engine::setEngine(QQmlEngine *engine) initQmlGlobalObject(); } -QV4::ReturnedValue QV8Engine::global() -{ - return m_v4Engine->globalObject->asReturnedValue(); -} - void QV8Engine::startTimer(const QString &timerName) { if (!m_time.isValid()) diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index a430fba0e6..b6a378667e 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -77,12 +77,6 @@ namespace QV4 { struct QObjectMethod; } -#define V4THROW_ERROR(string) \ - return ctx->engine()->throwError(QString::fromUtf8(string)); - -#define V4THROW_TYPE(string) \ - return ctx->engine()->throwTypeError(QStringLiteral(string)); - #define V4_DEFINE_EXTENSION(dataclass, datafunction) \ static inline dataclass *datafunction(QV4::ExecutionEngine *engine) \ { \ @@ -159,12 +153,11 @@ class Q_QML_PRIVATE_EXPORT QV8Engine { friend class QJSEngine; public: - static QV8Engine* get(QJSEngine* q) { Q_ASSERT(q); return q->handle(); } // static QJSEngine* get(QV8Engine* d) { Q_ASSERT(d); return d->q; } - static QV4::ExecutionEngine *getV4(QJSEngine *q) { return q->handle()->m_v4Engine; } + static QV4::ExecutionEngine *getV4(QJSEngine *q) { return q->handle(); } static QV4::ExecutionEngine *getV4(QV8Engine *d) { return d->m_v4Engine; } - QV8Engine(QJSEngine* qq); + QV8Engine(QJSEngine* qq, QV4::ExecutionEngine *v4); virtual ~QV8Engine(); // This enum should be in sync with QQmlEngine::ObjectOwnership @@ -178,14 +171,10 @@ public: void setEngine(QQmlEngine *engine); QQmlEngine *engine() { return m_engine; } QJSEngine *publicEngine() { return q; } - QV4::ReturnedValue global(); QQmlDelayedCallQueue *delayedCallQueue() { return &m_delayedCallQueue; } void *xmlHttpRequestData() const { return m_xmlHttpRequestData; } - Deletable *listModelData() const { return m_listModelData; } - void setListModelData(Deletable *d) { if (m_listModelData) delete m_listModelData; m_listModelData = d; } - void freezeObject(const QV4::Value &value); #if QT_CONFIG(qml_network) @@ -222,7 +211,6 @@ protected: void *m_xmlHttpRequestData; QVector<Deletable *> m_extensionData; - Deletable *m_listModelData; QSet<QString> m_illegalNames; @@ -242,7 +230,7 @@ inline QV8Engine::Deletable *QV8Engine::extensionData(int index) const if (index < m_extensionData.count()) return m_extensionData[index]; else - return 0; + return nullptr; } |