1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qqmlpropertycache_p.h"
44 #include "qqmlengine_p.h"
45 #include "qqmlbinding_p.h"
46 #include <private/qv8engine_p.h>
48 #include <private/qmetaobject_p.h>
49 #include <private/qqmlaccessors_p.h>
51 #include <QtCore/qdebug.h>
53 #include <ctype.h> // for toupper
55 Q_DECLARE_METATYPE(QJSValue)
56 Q_DECLARE_METATYPE(QQmlV8Handle);
60 #define Q_INT16_MAX 32767
62 class QQmlPropertyCacheMethodArguments
65 QQmlPropertyCacheMethodArguments *next;
69 // Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
71 static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p)
73 QQmlPropertyData::Flags flags;
76 flags |= QQmlPropertyData::IsConstant;
78 flags |= QQmlPropertyData::IsWritable;
80 flags |= QQmlPropertyData::IsResettable;
82 flags |= QQmlPropertyData::IsFinal;
84 flags |= QQmlPropertyData::IsEnumType;
89 // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
91 static QQmlPropertyData::Flags flagsForPropertyType(int propType, QQmlEngine *engine)
93 Q_ASSERT(propType != -1);
95 QQmlPropertyData::Flags flags;
97 if (propType == QMetaType::QObjectStar || propType == QMetaType::QWidgetStar) {
98 flags |= QQmlPropertyData::IsQObjectDerived;
99 } else if (propType == QMetaType::QVariant) {
100 flags |= QQmlPropertyData::IsQVariant;
101 } else if (propType < (int)QVariant::UserType) {
102 } else if (propType == qMetaTypeId<QQmlBinding *>()) {
103 flags |= QQmlPropertyData::IsQmlBinding;
104 } else if (propType == qMetaTypeId<QJSValue>()) {
105 flags |= QQmlPropertyData::IsQJSValue;
106 } else if (propType == qMetaTypeId<QQmlV8Handle>()) {
107 flags |= QQmlPropertyData::IsV8Handle;
109 QQmlMetaType::TypeCategory cat =
110 engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType)
111 : QQmlMetaType::typeCategory(propType);
113 if (cat == QQmlMetaType::Object)
114 flags |= QQmlPropertyData::IsQObjectDerived;
115 else if (cat == QQmlMetaType::List)
116 flags |= QQmlPropertyData::IsQList;
122 static int metaObjectSignalCount(const QMetaObject *metaObject)
125 for (const QMetaObject *obj = metaObject; obj; obj = obj->superClass())
126 signalCount += QMetaObjectPrivate::get(obj)->signalCount;
130 QQmlPropertyData::Flags
131 QQmlPropertyData::flagsForProperty(const QMetaProperty &p, QQmlEngine *engine)
133 return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
136 void QQmlPropertyData::lazyLoad(const QMetaProperty &p, QQmlEngine *engine)
140 coreIndex = p.propertyIndex();
141 notifyIndex = p.notifySignalIndex();
142 Q_ASSERT(p.revision() <= Q_INT16_MAX);
143 revision = p.revision();
145 flags = fastFlagsForProperty(p);
148 if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
150 flags |= QQmlPropertyData::IsQObjectDerived;
151 } else if (type == QMetaType::QVariant) {
153 flags |= QQmlPropertyData::IsQVariant;
154 } else if (type == QVariant::UserType || type == -1) {
155 propTypeName = p.typeName();
156 flags |= QQmlPropertyData::NotFullyResolved;
162 void QQmlPropertyData::load(const QMetaProperty &p, QQmlEngine *engine)
164 propType = p.userType();
165 coreIndex = p.propertyIndex();
166 notifyIndex = p.notifySignalIndex();
167 flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
168 Q_ASSERT(p.revision() <= Q_INT16_MAX);
169 revision = p.revision();
172 void QQmlPropertyData::load(const QMetaMethod &m)
174 coreIndex = m.methodIndex();
177 if (m.methodType() == QMetaMethod::Signal)
179 propType = QVariant::Invalid;
181 const char *returnType = m.typeName();
183 propType = QMetaType::type(returnType);
185 const char *signature = m.signature();
186 while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
189 if (*signature != ')') {
190 flags |= HasArguments;
191 if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
192 flags |= IsV8Function;
196 Q_ASSERT(m.revision() <= Q_INT16_MAX);
197 revision = m.revision();
200 void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
202 coreIndex = m.methodIndex();
205 if (m.methodType() == QMetaMethod::Signal)
207 propType = QVariant::Invalid;
209 const char *returnType = m.typeName();
210 if (returnType && *returnType) {
211 propTypeName = returnType;
212 flags |= NotFullyResolved;
215 const char *signature = m.signature();
216 while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
219 if (*signature != ')') {
220 flags |= HasArguments;
221 if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
222 flags |= IsV8Function;
226 Q_ASSERT(m.revision() <= Q_INT16_MAX);
227 revision = m.revision();
231 Creates a new empty QQmlPropertyCache.
233 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e)
234 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
235 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
241 Creates a new QQmlPropertyCache of \a metaObject.
243 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e, const QMetaObject *metaObject)
244 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
245 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
248 Q_ASSERT(metaObject);
250 update(engine, metaObject);
253 QQmlPropertyCache::~QQmlPropertyCache()
257 QQmlPropertyCacheMethodArguments *args = argumentsCache;
259 QQmlPropertyCacheMethodArguments *next = args->next;
264 // We must clear this prior to releasing the parent incase it is a
267 if (parent) parent->release();
272 void QQmlPropertyCache::destroy()
274 Q_ASSERT(engine || constructor.IsEmpty());
275 if (constructor.IsEmpty())
278 QQmlEnginePrivate::deleteInEngineThread(engine, this);
281 // This is inherited from QQmlCleanup, so it should only clear the things
282 // that are tied to the specific QQmlEngine.
283 void QQmlPropertyCache::clear()
285 qPersistentDispose(constructor);
289 QQmlPropertyCache *QQmlPropertyCache::copy(int reserve)
291 QQmlPropertyCache *cache = new QQmlPropertyCache(engine);
292 cache->parent = this;
293 cache->parent->addref();
294 cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
295 cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
296 cache->signalHanderIndexCacheStart = signalHandlerIndexCache.count() + signalHanderIndexCacheStart;
297 cache->stringCache.linkAndReserve(stringCache, reserve);
298 cache->allowedRevisionCache = allowedRevisionCache;
299 cache->metaObject = metaObject;
301 // We specifically do *NOT* copy the constructor
306 QQmlPropertyCache *QQmlPropertyCache::copy()
312 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
313 QQmlPropertyData::Flag propertyFlags,
314 QQmlPropertyData::Flag methodFlags,
315 QQmlPropertyData::Flag signalFlags)
317 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
321 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
323 QQmlPropertyData::Flag propertyFlags,
324 QQmlPropertyData::Flag methodFlags,
325 QQmlPropertyData::Flag signalFlags)
327 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
329 // Reserve enough space in the name hash for all the methods (including signals), all the
330 // signal handlers and all the properties. This assumes no name clashes, but this is the
332 QQmlPropertyCache *rv = copy(QMetaObjectPrivate::get(metaObject)->methodCount +
333 QMetaObjectPrivate::get(metaObject)->signalCount +
334 QMetaObjectPrivate::get(metaObject)->propertyCount);
336 rv->append(engine, metaObject, revision, propertyFlags, methodFlags, signalFlags);
341 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
342 QQmlPropertyData::Flag propertyFlags,
343 QQmlPropertyData::Flag methodFlags,
344 QQmlPropertyData::Flag signalFlags)
346 append(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
349 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
351 QQmlPropertyData::Flag propertyFlags,
352 QQmlPropertyData::Flag methodFlags,
353 QQmlPropertyData::Flag signalFlags)
356 Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache
358 this->metaObject = metaObject;
360 bool dynamicMetaObject = isDynamicMetaObject(metaObject);
362 allowedRevisionCache.append(0);
364 int methodCount = metaObject->methodCount();
365 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
366 int signalCount = metaObjectSignalCount(metaObject);
367 int classInfoCount = QMetaObjectPrivate::get(metaObject)->classInfoCount;
369 QQmlAccessorProperties::Properties accessorProperties;
371 // Special case QObject as we don't want to add a qt_HasQmlAccessors classinfo to it
372 if (metaObject == &QObject::staticMetaObject) {
373 accessorProperties = QQmlAccessorProperties::properties(metaObject);
374 } else if (classInfoCount) {
375 int classInfoOffset = metaObject->classInfoOffset();
376 bool hasFastProperty = false;
377 for (int ii = 0; ii < classInfoCount; ++ii) {
378 int idx = ii + classInfoOffset;
380 if (0 == qstrcmp(metaObject->classInfo(idx).name(), "qt_HasQmlAccessors")) {
381 hasFastProperty = true;
386 if (hasFastProperty) {
387 accessorProperties = QQmlAccessorProperties::properties(metaObject);
388 if (accessorProperties.count == 0)
389 qFatal("QQmlPropertyCache: %s has FastProperty class info, but has not "
390 "installed property accessors", metaObject->className());
393 accessorProperties = QQmlAccessorProperties::properties(metaObject);
394 if (accessorProperties.count != 0)
395 qFatal("QQmlPropertyCache: %s has fast property accessors, but is missing "
396 "FastProperty class info", metaObject->className());
401 // qMax(defaultMethods, methodOffset) to block the signals and slots of QObject::staticMetaObject
402 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
403 int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
404 int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
406 // update() should have reserved enough space in the vector that this doesn't cause a realloc
407 // and invalidate the stringCache.
408 methodIndexCache.resize(methodCount - methodIndexCacheStart);
409 signalHandlerIndexCache.resize(signalCount - signalHanderIndexCacheStart);
410 int signalHandlerIndex = signalOffset;
411 for (int ii = methodOffset; ii < methodCount; ++ii) {
412 QMetaMethod m = metaObject->method(ii);
413 if (m.access() == QMetaMethod::Private)
416 // Extract method name
417 const char *signature = m.signature();
418 const char *cptr = signature;
420 while (*cptr != '(') {
421 Q_ASSERT(*cptr != 0);
422 utf8 |= *cptr & 0x80;
426 QQmlPropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
427 QQmlPropertyData *sigdata = 0;
431 if (data->isSignal())
432 data->flags |= signalFlags;
434 data->flags |= methodFlags;
436 if (!dynamicMetaObject)
437 data->flags |= QQmlPropertyData::IsDirect;
439 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
440 data->metaObjectOffset = allowedRevisionCache.count() - 1;
442 if (data->isSignal()) {
443 sigdata = &signalHandlerIndexCache[signalHandlerIndex - signalHanderIndexCacheStart];
445 sigdata->flags |= QQmlPropertyData::IsSignalHandler;
448 QQmlPropertyData *old = 0;
451 QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
452 if (QQmlPropertyData **it = stringCache.value(methodName))
454 stringCache.insert(methodName, data);
456 if (data->isSignal()) {
457 QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1));
458 stringCache.insert(on, sigdata);
459 ++signalHandlerIndex;
462 QHashedCStringRef methodName(signature, cptr - signature);
463 if (QQmlPropertyData **it = stringCache.value(methodName))
465 stringCache.insert(methodName, data);
467 if (data->isSignal()) {
468 int length = methodName.length();
470 QVarLengthArray<char, 128> str(length+3);
473 str[2] = toupper(signature[0]);
475 memcpy(&str[3], &signature[1], length - 1);
476 str[length + 2] = '\0';
478 QHashedString on(QString::fromLatin1(str.data()));
479 stringCache.insert(on, sigdata);
480 ++signalHandlerIndex;
485 // We only overload methods in the same class, exactly like C++
486 if (old->isFunction() && old->coreIndex >= methodOffset)
487 data->flags |= QQmlPropertyData::IsOverload;
488 data->overrideIndexIsProperty = !old->isFunction();
489 data->overrideIndex = old->coreIndex;
493 int propCount = metaObject->propertyCount();
494 int propOffset = metaObject->propertyOffset();
496 // update() should have reserved enough space in the vector that this doesn't cause a realloc
497 // and invalidate the stringCache.
498 propertyIndexCache.resize(propCount - propertyIndexCacheStart);
499 for (int ii = propOffset; ii < propCount; ++ii) {
500 QMetaProperty p = metaObject->property(ii);
501 if (!p.isScriptable())
504 const char *str = p.name();
506 const char *cptr = str;
508 utf8 |= *cptr & 0x80;
512 QQmlPropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
514 data->lazyLoad(p, engine);
515 data->flags |= propertyFlags;
517 if (!dynamicMetaObject)
518 data->flags |= QQmlPropertyData::IsDirect;
520 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
521 data->metaObjectOffset = allowedRevisionCache.count() - 1;
523 QQmlPropertyData *old = 0;
526 QHashedString propName(QString::fromUtf8(str, cptr - str));
527 if (QQmlPropertyData **it = stringCache.value(propName))
529 stringCache.insert(propName, data);
531 QHashedCStringRef propName(str, cptr - str);
532 if (QQmlPropertyData **it = stringCache.value(propName))
534 stringCache.insert(propName, data);
537 QQmlAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
539 // Fast properties may not be overrides or revisioned
540 Q_ASSERT(accessorProperty == 0 || (old == 0 && data->revision == 0));
542 if (accessorProperty) {
543 data->flags |= QQmlPropertyData::HasAccessors;
544 data->accessors = accessorProperty->accessors;
545 data->accessorData = accessorProperty->data;
547 data->overrideIndexIsProperty = !old->isFunction();
548 data->overrideIndex = old->coreIndex;
553 void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
555 Q_ASSERT(data->notFullyResolved());
557 data->propType = QMetaType::type(data->propTypeName);
559 if (!data->isFunction())
560 data->flags |= flagsForPropertyType(data->propType, engine);
562 data->flags &= ~QQmlPropertyData::NotFullyResolved;
565 void QQmlPropertyCache::updateRecur(QQmlEngine *engine, const QMetaObject *metaObject)
570 updateRecur(engine, metaObject->superClass());
572 append(engine, metaObject);
575 void QQmlPropertyCache::update(QQmlEngine *engine, const QMetaObject *metaObject)
578 Q_ASSERT(metaObject);
579 Q_ASSERT(stringCache.isEmpty());
581 // Preallocate enough space in the index caches for all the properties/methods/signals that
582 // are not cached in a parent cache so that the caches never need to be reallocated as this
583 // would invalidate pointers stored in the stringCache.
584 int pc = metaObject->propertyCount();
585 int mc = metaObject->methodCount();
586 int sc = metaObjectSignalCount(metaObject);
587 propertyIndexCache.reserve(pc - propertyIndexCacheStart);
588 methodIndexCache.reserve(mc - methodIndexCacheStart);
589 signalHandlerIndexCache.reserve(sc - signalHanderIndexCacheStart);
591 // Reserve enough space in the stringCache for all properties/methods/signals including those
592 // cached in a parent cache.
593 stringCache.reserve(pc + mc + sc);
595 updateRecur(engine,metaObject);
599 QQmlPropertyCache::property(int index) const
601 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
604 if (index < propertyIndexCacheStart)
605 return parent->property(index);
607 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
608 if (rv->notFullyResolved()) resolve(rv);
613 QQmlPropertyCache::method(int index) const
615 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
618 if (index < methodIndexCacheStart)
619 return parent->method(index);
621 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
622 if (rv->notFullyResolved()) resolve(rv);
627 QQmlPropertyCache::property(const QHashedStringRef &str) const
629 QQmlPropertyData **rv = stringCache.value(str);
630 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
635 QQmlPropertyCache::property(const QHashedCStringRef &str) const
637 QQmlPropertyData **rv = stringCache.value(str);
638 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
643 QQmlPropertyCache::property(const QString &str) const
645 QQmlPropertyData **rv = stringCache.value(str);
646 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
650 QString QQmlPropertyData::name(QObject *object)
655 return name(object->metaObject());
658 QString QQmlPropertyData::name(const QMetaObject *metaObject)
660 if (!metaObject || coreIndex == -1)
663 if (flags & IsFunction) {
664 QMetaMethod m = metaObject->method(coreIndex);
666 QString name = QString::fromUtf8(m.signature());
667 int parenIdx = name.indexOf(QLatin1Char('('));
669 name = name.left(parenIdx);
672 QMetaProperty p = metaObject->property(coreIndex);
673 return QString::fromUtf8(p.name());
677 QStringList QQmlPropertyCache::propertyNames() const
680 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
681 keys.append(iter.key());
685 static int EnumType(const QMetaObject *meta, const QByteArray &str)
689 int scopeIdx = str.lastIndexOf("::");
690 if (scopeIdx != -1) {
691 scope = str.left(scopeIdx);
692 name = str.mid(scopeIdx + 2);
696 for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
697 QMetaEnum m = meta->enumerator(i);
698 if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
699 return QVariant::Int;
701 return QVariant::Invalid;
704 // Returns an array of the arguments for method \a index. The first entry in the array
705 // is the number of arguments.
706 int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
707 QVarLengthArray<int, 9> &dummy,
708 QByteArray *unknownTypeError)
710 Q_ASSERT(object && index >= 0);
712 QQmlData *ddata = QQmlData::get(object, false);
714 if (ddata && ddata->propertyCache) {
715 typedef QQmlPropertyCacheMethodArguments A;
717 QQmlPropertyCache *c = ddata->propertyCache;
718 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
720 while (index < c->methodIndexCacheStart)
723 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
726 return static_cast<A *>(rv->arguments)->arguments;
728 const QMetaObject *metaObject = object->metaObject();
729 QMetaMethod m = metaObject->method(index);
730 QList<QByteArray> argTypeNames = m.parameterTypes();
732 A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int)));
733 args->arguments[0] = argTypeNames.count();
735 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
736 int type = QMetaType::type(argTypeNames.at(ii));
737 if ((QMetaType::typeFlags(type) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
738 type = QVariant::Int;
739 else if (type == QVariant::Invalid)
740 type = EnumType(object->metaObject(), argTypeNames.at(ii));
741 if (type == QVariant::Invalid) {
742 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
746 args->arguments[ii + 1] = type;
749 rv->arguments = args;
750 args->next = c->argumentsCache;
751 c->argumentsCache = args;
752 return static_cast<A *>(rv->arguments)->arguments;
755 QMetaMethod m = object->metaObject()->method(index);
756 QList<QByteArray> argTypeNames = m.parameterTypes();
757 dummy.resize(argTypeNames.count() + 1);
758 dummy[0] = argTypeNames.count();
760 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
761 int type = QMetaType::type(argTypeNames.at(ii));
762 if ((QMetaType::typeFlags(type) & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
763 type = QVariant::Int;
764 else if (type == QVariant::Invalid)
765 type = EnumType(object->metaObject(), argTypeNames.at(ii));
766 if (type == QVariant::Invalid) {
767 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
770 dummy[ii + 1] = type;
777 QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject,
778 const QString &property)
780 Q_ASSERT(metaObject);
784 const QMetaObject *cmo = metaObject;
785 const QByteArray propertyName = property.toUtf8();
787 int idx = cmo->indexOfProperty(propertyName);
789 QMetaProperty p = cmo->property(idx);
790 if (p.isScriptable()) {
794 while (cmo && cmo->propertyOffset() >= idx)
795 cmo = cmo->superClass();
803 int methodCount = metaObject->methodCount();
804 int defaultMethods = QObject::staticMetaObject.methodCount();
805 for (int ii = methodCount - 1; ii >= defaultMethods; --ii) {
806 // >=defaultMethods to block the signals and slots of QObject::staticMetaObject
807 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
808 QMetaMethod m = metaObject->method(ii);
809 if (m.access() == QMetaMethod::Private)
811 QString methodName = QString::fromUtf8(m.signature());
813 int parenIdx = methodName.indexOf(QLatin1Char('('));
814 Q_ASSERT(parenIdx != -1);
815 QStringRef methodNameRef = methodName.leftRef(parenIdx);
817 if (methodNameRef == property) {
826 inline const QString &qQmlPropertyCacheToString(const QString &string)
831 inline QString qQmlPropertyCacheToString(const QHashedV8String &string)
833 return QV8Engine::toStringStatic(string.string());
838 qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj,
839 const T &name, QQmlPropertyData &local)
841 QQmlPropertyCache *cache = 0;
844 QQmlData *ddata = QQmlData::get(obj);
846 if (ddata && ddata->propertyCache) {
847 cache = ddata->propertyCache;
849 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
850 cache = ep->cache(obj);
852 ddata = QQmlData::get(obj, true);
854 ddata->propertyCache = cache;
859 QQmlPropertyData *rv = 0;
862 rv = cache->property(name);
864 local = qQmlPropertyCacheCreate(obj->metaObject(),
865 qQmlPropertyCacheToString(name));
874 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
875 const QHashedV8String &name, QQmlPropertyData &local)
877 return qQmlPropertyCacheProperty<QHashedV8String>(engine, obj, name, local);
881 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
882 const QString &name, QQmlPropertyData &local)
884 return qQmlPropertyCacheProperty<QString>(engine, obj, name, local);
887 static inline const QMetaObjectPrivate *priv(const uint* data)
888 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
890 bool QQmlPropertyCache::isDynamicMetaObject(const QMetaObject *mo)
892 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;