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 Q_DECLARE_METATYPE(QJSValue)
54 Q_DECLARE_METATYPE(QQmlV8Handle);
58 #define Q_INT16_MAX 32767
60 class QQmlPropertyCacheMethodArguments
63 QQmlPropertyCacheMethodArguments *next;
67 // Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
69 static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p)
71 QQmlPropertyData::Flags flags;
74 flags |= QQmlPropertyData::IsConstant;
76 flags |= QQmlPropertyData::IsWritable;
78 flags |= QQmlPropertyData::IsResettable;
80 flags |= QQmlPropertyData::IsFinal;
82 flags |= QQmlPropertyData::IsEnumType;
87 // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
89 static QQmlPropertyData::Flags flagsForPropertyType(int propType, QQmlEngine *engine)
91 Q_ASSERT(propType != -1);
93 QQmlPropertyData::Flags flags;
95 if (propType == QMetaType::QObjectStar || propType == QMetaType::QWidgetStar) {
96 flags |= QQmlPropertyData::IsQObjectDerived;
97 } else if (propType == QMetaType::QVariant) {
98 flags |= QQmlPropertyData::IsQVariant;
99 } else if (propType < (int)QVariant::UserType) {
100 } else if (propType == qMetaTypeId<QQmlBinding *>()) {
101 flags |= QQmlPropertyData::IsQmlBinding;
102 } else if (propType == qMetaTypeId<QJSValue>()) {
103 flags |= QQmlPropertyData::IsQJSValue;
104 } else if (propType == qMetaTypeId<QQmlV8Handle>()) {
105 flags |= QQmlPropertyData::IsV8Handle;
107 QQmlMetaType::TypeCategory cat =
108 engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType)
109 : QQmlMetaType::typeCategory(propType);
111 if (cat == QQmlMetaType::Object)
112 flags |= QQmlPropertyData::IsQObjectDerived;
113 else if (cat == QQmlMetaType::List)
114 flags |= QQmlPropertyData::IsQList;
120 static int metaObjectSignalCount(const QMetaObject *metaObject)
123 for (const QMetaObject *obj = metaObject; obj; obj = obj->superClass())
124 signalCount += QMetaObjectPrivate::get(obj)->signalCount;
128 QQmlPropertyData::Flags
129 QQmlPropertyData::flagsForProperty(const QMetaProperty &p, QQmlEngine *engine)
131 return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
134 void QQmlPropertyData::lazyLoad(const QMetaProperty &p, QQmlEngine *engine)
138 coreIndex = p.propertyIndex();
139 notifyIndex = p.notifySignalIndex();
140 Q_ASSERT(p.revision() <= Q_INT16_MAX);
141 revision = p.revision();
143 flags = fastFlagsForProperty(p);
146 if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
148 flags |= QQmlPropertyData::IsQObjectDerived;
149 } else if (type == QMetaType::QVariant) {
151 flags |= QQmlPropertyData::IsQVariant;
152 } else if (type == QVariant::UserType || type == -1) {
153 propTypeName = p.typeName();
154 flags |= QQmlPropertyData::NotFullyResolved;
160 void QQmlPropertyData::load(const QMetaProperty &p, QQmlEngine *engine)
162 propType = p.userType();
163 coreIndex = p.propertyIndex();
164 notifyIndex = p.notifySignalIndex();
165 flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
166 Q_ASSERT(p.revision() <= Q_INT16_MAX);
167 revision = p.revision();
170 void QQmlPropertyData::load(const QMetaMethod &m)
172 coreIndex = m.methodIndex();
175 if (m.methodType() == QMetaMethod::Signal)
177 propType = QVariant::Invalid;
179 const char *returnType = m.typeName();
181 propType = QMetaType::type(returnType);
183 const char *signature = m.signature();
184 while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
187 if (*signature != ')') {
188 flags |= HasArguments;
189 if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
190 flags |= IsV8Function;
194 Q_ASSERT(m.revision() <= Q_INT16_MAX);
195 revision = m.revision();
198 void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
200 coreIndex = m.methodIndex();
203 if (m.methodType() == QMetaMethod::Signal)
205 propType = QVariant::Invalid;
207 const char *returnType = m.typeName();
208 if (returnType && *returnType) {
209 propTypeName = returnType;
210 flags |= NotFullyResolved;
213 const char *signature = m.signature();
214 while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
217 if (*signature != ')') {
218 flags |= HasArguments;
219 if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
220 flags |= IsV8Function;
224 Q_ASSERT(m.revision() <= Q_INT16_MAX);
225 revision = m.revision();
229 Creates a new empty QQmlPropertyCache.
231 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e)
232 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
233 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
239 Creates a new QQmlPropertyCache of \a metaObject.
241 QQmlPropertyCache::QQmlPropertyCache(QQmlEngine *e, const QMetaObject *metaObject)
242 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
243 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
246 Q_ASSERT(metaObject);
248 update(engine, metaObject);
251 QQmlPropertyCache::~QQmlPropertyCache()
255 QQmlPropertyCacheMethodArguments *args = argumentsCache;
257 QQmlPropertyCacheMethodArguments *next = args->next;
262 // We must clear this prior to releasing the parent incase it is a
265 if (parent) parent->release();
270 void QQmlPropertyCache::destroy()
272 Q_ASSERT(engine || constructor.IsEmpty());
273 if (constructor.IsEmpty())
276 QQmlEnginePrivate::deleteInEngineThread(engine, this);
279 // This is inherited from QQmlCleanup, so it should only clear the things
280 // that are tied to the specific QQmlEngine.
281 void QQmlPropertyCache::clear()
283 qPersistentDispose(constructor);
287 QQmlPropertyCache *QQmlPropertyCache::copy(int reserve)
289 QQmlPropertyCache *cache = new QQmlPropertyCache(engine);
290 cache->parent = this;
291 cache->parent->addref();
292 cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
293 cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
294 cache->signalHanderIndexCacheStart = signalHandlerIndexCache.count() + signalHanderIndexCacheStart;
295 cache->stringCache.linkAndReserve(stringCache, reserve);
296 cache->allowedRevisionCache = allowedRevisionCache;
297 cache->metaObject = metaObject;
299 // We specifically do *NOT* copy the constructor
304 QQmlPropertyCache *QQmlPropertyCache::copy()
310 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
311 QQmlPropertyData::Flag propertyFlags,
312 QQmlPropertyData::Flag methodFlags,
313 QQmlPropertyData::Flag signalFlags)
315 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
319 QQmlPropertyCache::copyAndAppend(QQmlEngine *engine, const QMetaObject *metaObject,
321 QQmlPropertyData::Flag propertyFlags,
322 QQmlPropertyData::Flag methodFlags,
323 QQmlPropertyData::Flag signalFlags)
325 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
327 // Reserve enough space in the name hash for all the methods (including signals), all the
328 // signal handlers and all the properties. This assumes no name clashes, but this is the
330 QQmlPropertyCache *rv = copy(QMetaObjectPrivate::get(metaObject)->methodCount +
331 QMetaObjectPrivate::get(metaObject)->signalCount +
332 QMetaObjectPrivate::get(metaObject)->propertyCount);
334 rv->append(engine, metaObject, revision, propertyFlags, methodFlags, signalFlags);
339 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
340 QQmlPropertyData::Flag propertyFlags,
341 QQmlPropertyData::Flag methodFlags,
342 QQmlPropertyData::Flag signalFlags)
344 append(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
347 void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
349 QQmlPropertyData::Flag propertyFlags,
350 QQmlPropertyData::Flag methodFlags,
351 QQmlPropertyData::Flag signalFlags)
354 Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache
356 this->metaObject = metaObject;
358 bool dynamicMetaObject = isDynamicMetaObject(metaObject);
360 allowedRevisionCache.append(0);
362 int methodCount = metaObject->methodCount();
363 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
364 int signalCount = metaObjectSignalCount(metaObject);
365 int classInfoCount = QMetaObjectPrivate::get(metaObject)->classInfoCount;
367 QQmlAccessorProperties::Properties accessorProperties;
369 // Special case QObject as we don't want to add a qt_HasQmlAccessors classinfo to it
370 if (metaObject == &QObject::staticMetaObject) {
371 accessorProperties = QQmlAccessorProperties::properties(metaObject);
372 } else if (classInfoCount) {
373 int classInfoOffset = metaObject->classInfoOffset();
374 bool hasFastProperty = false;
375 for (int ii = 0; ii < classInfoCount; ++ii) {
376 int idx = ii + classInfoOffset;
378 if (0 == qstrcmp(metaObject->classInfo(idx).name(), "qt_HasQmlAccessors")) {
379 hasFastProperty = true;
384 if (hasFastProperty) {
385 accessorProperties = QQmlAccessorProperties::properties(metaObject);
386 if (accessorProperties.count == 0)
387 qFatal("QQmlPropertyCache: %s has FastProperty class info, but has not "
388 "installed property accessors", metaObject->className());
391 accessorProperties = QQmlAccessorProperties::properties(metaObject);
392 if (accessorProperties.count != 0)
393 qFatal("QQmlPropertyCache: %s has fast property accessors, but is missing "
394 "FastProperty class info", metaObject->className());
399 // qMax(defaultMethods, methodOffset) to block the signals and slots of QObject::staticMetaObject
400 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
401 int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
402 int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
404 // update() should have reserved enough space in the vector that this doesn't cause a realloc
405 // and invalidate the stringCache.
406 methodIndexCache.resize(methodCount - methodIndexCacheStart);
407 signalHandlerIndexCache.resize(signalCount - signalHanderIndexCacheStart);
408 int signalHandlerIndex = signalOffset;
409 for (int ii = methodOffset; ii < methodCount; ++ii) {
410 QMetaMethod m = metaObject->method(ii);
411 if (m.access() == QMetaMethod::Private)
414 // Extract method name
415 const char *signature = m.signature();
416 const char *cptr = signature;
418 while (*cptr != '(') {
419 Q_ASSERT(*cptr != 0);
420 utf8 |= *cptr & 0x80;
424 QQmlPropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
425 QQmlPropertyData *sigdata = 0;
429 if (data->isSignal())
430 data->flags |= signalFlags;
432 data->flags |= methodFlags;
434 if (!dynamicMetaObject)
435 data->flags |= QQmlPropertyData::IsDirect;
437 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
438 data->metaObjectOffset = allowedRevisionCache.count() - 1;
440 if (data->isSignal()) {
441 sigdata = &signalHandlerIndexCache[signalHandlerIndex - signalHanderIndexCacheStart];
443 sigdata->flags |= QQmlPropertyData::IsSignalHandler;
446 QQmlPropertyData *old = 0;
449 QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
450 if (QQmlPropertyData **it = stringCache.value(methodName))
452 stringCache.insert(methodName, data);
454 if (data->isSignal()) {
455 QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1));
456 stringCache.insert(on, sigdata);
457 ++signalHandlerIndex;
460 QHashedCStringRef methodName(signature, cptr - signature);
461 if (QQmlPropertyData **it = stringCache.value(methodName))
463 stringCache.insert(methodName, data);
465 if (data->isSignal()) {
466 int length = methodName.length();
468 QVarLengthArray<char, 128> str(length+3);
471 str[2] = toupper(signature[0]);
473 memcpy(&str[3], &signature[1], length - 1);
474 str[length + 2] = '\0';
476 QHashedString on(QString::fromLatin1(str.data()));
477 stringCache.insert(on, sigdata);
478 ++signalHandlerIndex;
483 // We only overload methods in the same class, exactly like C++
484 if (old->isFunction() && old->coreIndex >= methodOffset)
485 data->flags |= QQmlPropertyData::IsOverload;
486 data->overrideIndexIsProperty = !old->isFunction();
487 data->overrideIndex = old->coreIndex;
491 int propCount = metaObject->propertyCount();
492 int propOffset = metaObject->propertyOffset();
494 // update() should have reserved enough space in the vector that this doesn't cause a realloc
495 // and invalidate the stringCache.
496 propertyIndexCache.resize(propCount - propertyIndexCacheStart);
497 for (int ii = propOffset; ii < propCount; ++ii) {
498 QMetaProperty p = metaObject->property(ii);
499 if (!p.isScriptable())
502 const char *str = p.name();
504 const char *cptr = str;
506 utf8 |= *cptr & 0x80;
510 QQmlPropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
512 data->lazyLoad(p, engine);
513 data->flags |= propertyFlags;
515 if (!dynamicMetaObject)
516 data->flags |= QQmlPropertyData::IsDirect;
518 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
519 data->metaObjectOffset = allowedRevisionCache.count() - 1;
521 QQmlPropertyData *old = 0;
524 QHashedString propName(QString::fromUtf8(str, cptr - str));
525 if (QQmlPropertyData **it = stringCache.value(propName))
527 stringCache.insert(propName, data);
529 QHashedCStringRef propName(str, cptr - str);
530 if (QQmlPropertyData **it = stringCache.value(propName))
532 stringCache.insert(propName, data);
535 QQmlAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
537 // Fast properties may not be overrides or revisioned
538 Q_ASSERT(accessorProperty == 0 || (old == 0 && data->revision == 0));
540 if (accessorProperty) {
541 data->flags |= QQmlPropertyData::HasAccessors;
542 data->accessors = accessorProperty->accessors;
543 data->accessorData = accessorProperty->data;
545 data->overrideIndexIsProperty = !old->isFunction();
546 data->overrideIndex = old->coreIndex;
551 void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
553 Q_ASSERT(data->notFullyResolved());
555 data->propType = QMetaType::type(data->propTypeName);
557 if (!data->isFunction())
558 data->flags |= flagsForPropertyType(data->propType, engine);
560 data->flags &= ~QQmlPropertyData::NotFullyResolved;
563 void QQmlPropertyCache::updateRecur(QQmlEngine *engine, const QMetaObject *metaObject)
568 updateRecur(engine, metaObject->superClass());
570 append(engine, metaObject);
573 void QQmlPropertyCache::update(QQmlEngine *engine, const QMetaObject *metaObject)
576 Q_ASSERT(metaObject);
577 Q_ASSERT(stringCache.isEmpty());
579 // Preallocate enough space in the index caches for all the properties/methods/signals that
580 // are not cached in a parent cache so that the caches never need to be reallocated as this
581 // would invalidate pointers stored in the stringCache.
582 int pc = metaObject->propertyCount();
583 int mc = metaObject->methodCount();
584 int sc = metaObjectSignalCount(metaObject);
585 propertyIndexCache.reserve(pc - propertyIndexCacheStart);
586 methodIndexCache.reserve(mc - methodIndexCacheStart);
587 signalHandlerIndexCache.reserve(sc - signalHanderIndexCacheStart);
589 // Reserve enough space in the stringCache for all properties/methods/signals including those
590 // cached in a parent cache.
591 stringCache.reserve(pc + mc + sc);
593 updateRecur(engine,metaObject);
597 QQmlPropertyCache::property(int index) const
599 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
602 if (index < propertyIndexCacheStart)
603 return parent->property(index);
605 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
606 if (rv->notFullyResolved()) resolve(rv);
611 QQmlPropertyCache::method(int index) const
613 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
616 if (index < methodIndexCacheStart)
617 return parent->method(index);
619 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
620 if (rv->notFullyResolved()) resolve(rv);
625 QQmlPropertyCache::property(const QHashedStringRef &str) const
627 QQmlPropertyData **rv = stringCache.value(str);
628 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
633 QQmlPropertyCache::property(const QHashedCStringRef &str) const
635 QQmlPropertyData **rv = stringCache.value(str);
636 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
641 QQmlPropertyCache::property(const QString &str) const
643 QQmlPropertyData **rv = stringCache.value(str);
644 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
648 QString QQmlPropertyData::name(QObject *object)
653 return name(object->metaObject());
656 QString QQmlPropertyData::name(const QMetaObject *metaObject)
658 if (!metaObject || coreIndex == -1)
661 if (flags & IsFunction) {
662 QMetaMethod m = metaObject->method(coreIndex);
664 QString name = QString::fromUtf8(m.signature());
665 int parenIdx = name.indexOf(QLatin1Char('('));
667 name = name.left(parenIdx);
670 QMetaProperty p = metaObject->property(coreIndex);
671 return QString::fromUtf8(p.name());
675 QStringList QQmlPropertyCache::propertyNames() const
678 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
679 keys.append(iter.key());
683 static int EnumType(const QMetaObject *meta, const QByteArray &str)
687 int scopeIdx = str.lastIndexOf("::");
688 if (scopeIdx != -1) {
689 scope = str.left(scopeIdx);
690 name = str.mid(scopeIdx + 2);
694 for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
695 QMetaEnum m = meta->enumerator(i);
696 if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
697 return QVariant::Int;
699 return QVariant::Invalid;
702 // Returns an array of the arguments for method \a index. The first entry in the array
703 // is the number of arguments.
704 int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
705 QVarLengthArray<int, 9> &dummy,
706 QByteArray *unknownTypeError)
708 Q_ASSERT(object && index >= 0);
710 QQmlData *ddata = QQmlData::get(object, false);
712 if (ddata && ddata->propertyCache) {
713 typedef QQmlPropertyCacheMethodArguments A;
715 QQmlPropertyCache *c = ddata->propertyCache;
716 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
718 while (index < c->methodIndexCacheStart)
721 QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
724 return static_cast<A *>(rv->arguments)->arguments;
726 const QMetaObject *metaObject = object->metaObject();
727 QMetaMethod m = metaObject->method(index);
728 QList<QByteArray> argTypeNames = m.parameterTypes();
730 A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int)));
731 args->arguments[0] = argTypeNames.count();
733 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
734 int type = QMetaType::type(argTypeNames.at(ii));
735 if (type == QVariant::Invalid)
736 type = EnumType(object->metaObject(), argTypeNames.at(ii));
737 if (type == QVariant::Invalid) {
738 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
742 args->arguments[ii + 1] = type;
745 rv->arguments = args;
746 args->next = c->argumentsCache;
747 c->argumentsCache = args;
748 return static_cast<A *>(rv->arguments)->arguments;
751 QMetaMethod m = object->metaObject()->method(index);
752 QList<QByteArray> argTypeNames = m.parameterTypes();
753 dummy.resize(argTypeNames.count() + 1);
754 dummy[0] = argTypeNames.count();
756 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
757 int type = QMetaType::type(argTypeNames.at(ii));
758 if (type == QVariant::Invalid)
759 type = EnumType(object->metaObject(), argTypeNames.at(ii));
760 if (type == QVariant::Invalid) {
761 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
764 dummy[ii + 1] = type;
771 QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject,
772 const QString &property)
774 Q_ASSERT(metaObject);
778 const QMetaObject *cmo = metaObject;
779 const QByteArray propertyName = property.toUtf8();
781 int idx = cmo->indexOfProperty(propertyName);
783 QMetaProperty p = cmo->property(idx);
784 if (p.isScriptable()) {
788 while (cmo && cmo->propertyOffset() >= idx)
789 cmo = cmo->superClass();
797 int methodCount = metaObject->methodCount();
798 int defaultMethods = QObject::staticMetaObject.methodCount();
799 for (int ii = methodCount - 1; ii >= defaultMethods; --ii) {
800 // >=defaultMethods to block the signals and slots of QObject::staticMetaObject
801 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
802 QMetaMethod m = metaObject->method(ii);
803 if (m.access() == QMetaMethod::Private)
805 QString methodName = QString::fromUtf8(m.signature());
807 int parenIdx = methodName.indexOf(QLatin1Char('('));
808 Q_ASSERT(parenIdx != -1);
809 QStringRef methodNameRef = methodName.leftRef(parenIdx);
811 if (methodNameRef == property) {
820 inline const QString &qQmlPropertyCacheToString(const QString &string)
825 inline QString qQmlPropertyCacheToString(const QHashedV8String &string)
827 return QV8Engine::toStringStatic(string.string());
832 qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj,
833 const T &name, QQmlPropertyData &local)
835 QQmlPropertyCache *cache = 0;
838 QQmlData *ddata = QQmlData::get(obj);
840 if (ddata && ddata->propertyCache) {
841 cache = ddata->propertyCache;
843 QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
844 cache = ep->cache(obj);
846 ddata = QQmlData::get(obj, true);
848 ddata->propertyCache = cache;
853 QQmlPropertyData *rv = 0;
856 rv = cache->property(name);
858 local = qQmlPropertyCacheCreate(obj->metaObject(),
859 qQmlPropertyCacheToString(name));
868 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
869 const QHashedV8String &name, QQmlPropertyData &local)
871 return qQmlPropertyCacheProperty<QHashedV8String>(engine, obj, name, local);
875 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
876 const QString &name, QQmlPropertyData &local)
878 return qQmlPropertyCacheProperty<QString>(engine, obj, name, local);
881 static inline const QMetaObjectPrivate *priv(const uint* data)
882 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
884 bool QQmlPropertyCache::isDynamicMetaObject(const QMetaObject *mo)
886 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;