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 QtDeclarative 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 "qdeclarativepropertycache_p.h"
44 #include "qdeclarativeengine_p.h"
45 #include "qdeclarativebinding_p.h"
46 #include <private/qv8engine_p.h>
48 #include <private/qmetaobject_p.h>
49 #include <private/qdeclarativeaccessors_p.h>
51 #include <QtCore/qdebug.h>
53 Q_DECLARE_METATYPE(QJSValue)
54 Q_DECLARE_METATYPE(QDeclarativeV8Handle);
58 #define Q_INT16_MAX 32767
60 class QDeclarativePropertyCacheMethodArguments
63 QDeclarativePropertyCacheMethodArguments *next;
67 // Flags that do *NOT* depend on the property's QMetaProperty::userType() and thus are quick
69 static QDeclarativePropertyData::Flags fastFlagsForProperty(const QMetaProperty &p)
71 QDeclarativePropertyData::Flags flags;
74 flags |= QDeclarativePropertyData::IsConstant;
76 flags |= QDeclarativePropertyData::IsWritable;
78 flags |= QDeclarativePropertyData::IsResettable;
80 flags |= QDeclarativePropertyData::IsFinal;
82 flags |= QDeclarativePropertyData::IsEnumType;
87 // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
89 static QDeclarativePropertyData::Flags flagsForPropertyType(int propType, QDeclarativeEngine *engine)
91 Q_ASSERT(propType != -1);
93 QDeclarativePropertyData::Flags flags;
95 if (propType == QMetaType::QObjectStar || propType == QMetaType::QWidgetStar) {
96 flags |= QDeclarativePropertyData::IsQObjectDerived;
97 } else if (propType == QMetaType::QVariant) {
98 flags |= QDeclarativePropertyData::IsQVariant;
99 } else if (propType < (int)QVariant::UserType) {
100 } else if (propType == qMetaTypeId<QDeclarativeBinding *>()) {
101 flags |= QDeclarativePropertyData::IsQmlBinding;
102 } else if (propType == qMetaTypeId<QJSValue>()) {
103 flags |= QDeclarativePropertyData::IsQJSValue;
104 } else if (propType == qMetaTypeId<QDeclarativeV8Handle>()) {
105 flags |= QDeclarativePropertyData::IsV8Handle;
107 QDeclarativeMetaType::TypeCategory cat =
108 engine ? QDeclarativeEnginePrivate::get(engine)->typeCategory(propType)
109 : QDeclarativeMetaType::typeCategory(propType);
111 if (cat == QDeclarativeMetaType::Object)
112 flags |= QDeclarativePropertyData::IsQObjectDerived;
113 else if (cat == QDeclarativeMetaType::List)
114 flags |= QDeclarativePropertyData::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 QDeclarativePropertyData::Flags
129 QDeclarativePropertyData::flagsForProperty(const QMetaProperty &p, QDeclarativeEngine *engine)
131 return fastFlagsForProperty(p) | flagsForPropertyType(p.userType(), engine);
134 void QDeclarativePropertyData::lazyLoad(const QMetaProperty &p, QDeclarativeEngine *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 |= QDeclarativePropertyData::IsQObjectDerived;
149 } else if (type == QMetaType::QVariant) {
151 flags |= QDeclarativePropertyData::IsQVariant;
152 } else if (type == QVariant::UserType || type == -1) {
153 propTypeName = p.typeName();
154 flags |= QDeclarativePropertyData::NotFullyResolved;
160 void QDeclarativePropertyData::load(const QMetaProperty &p, QDeclarativeEngine *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 QDeclarativePropertyData::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, "QDeclarativeV8Function*)")) {
190 flags |= IsV8Function;
194 Q_ASSERT(m.revision() <= Q_INT16_MAX);
195 revision = m.revision();
198 void QDeclarativePropertyData::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, "QDeclarativeV8Function*)")) {
220 flags |= IsV8Function;
224 Q_ASSERT(m.revision() <= Q_INT16_MAX);
225 revision = m.revision();
229 Creates a new empty QDeclarativePropertyCache.
231 QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *e)
232 : engine(e), parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
233 signalHanderIndexCacheStart(0), metaObject(0), argumentsCache(0)
239 Creates a new QDeclarativePropertyCache of \a metaObject.
241 QDeclarativePropertyCache::QDeclarativePropertyCache(QDeclarativeEngine *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 QDeclarativePropertyCache::~QDeclarativePropertyCache()
255 QDeclarativePropertyCacheMethodArguments *args = argumentsCache;
257 QDeclarativePropertyCacheMethodArguments *next = args->next;
262 // We must clear this prior to releasing the parent incase it is a
265 if (parent) parent->release();
270 void QDeclarativePropertyCache::destroy()
272 Q_ASSERT(engine || constructor.IsEmpty());
273 if (constructor.IsEmpty())
276 QDeclarativeEnginePrivate::deleteInEngineThread(engine, this);
279 // This is inherited from QDeclarativeCleanup, so it should only clear the things
280 // that are tied to the specific QDeclarativeEngine.
281 void QDeclarativePropertyCache::clear()
283 qPersistentDispose(constructor);
287 QDeclarativePropertyCache *QDeclarativePropertyCache::copy(int reserve)
289 QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(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 QDeclarativePropertyCache *QDeclarativePropertyCache::copy()
309 QDeclarativePropertyCache *
310 QDeclarativePropertyCache::copyAndAppend(QDeclarativeEngine *engine, const QMetaObject *metaObject,
311 QDeclarativePropertyData::Flag propertyFlags,
312 QDeclarativePropertyData::Flag methodFlags,
313 QDeclarativePropertyData::Flag signalFlags)
315 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
318 QDeclarativePropertyCache *
319 QDeclarativePropertyCache::copyAndAppend(QDeclarativeEngine *engine, const QMetaObject *metaObject,
321 QDeclarativePropertyData::Flag propertyFlags,
322 QDeclarativePropertyData::Flag methodFlags,
323 QDeclarativePropertyData::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 QDeclarativePropertyCache *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 QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject,
340 QDeclarativePropertyData::Flag propertyFlags,
341 QDeclarativePropertyData::Flag methodFlags,
342 QDeclarativePropertyData::Flag signalFlags)
344 append(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
347 void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject,
349 QDeclarativePropertyData::Flag propertyFlags,
350 QDeclarativePropertyData::Flag methodFlags,
351 QDeclarativePropertyData::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 QDeclarativeAccessorProperties::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 = QDeclarativeAccessorProperties::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 = QDeclarativeAccessorProperties::properties(metaObject);
386 if (accessorProperties.count == 0)
387 qFatal("QDeclarativePropertyCache: %s has FastProperty class info, but has not "
388 "installed property accessors", metaObject->className());
391 accessorProperties = QDeclarativeAccessorProperties::properties(metaObject);
392 if (accessorProperties.count != 0)
393 qFatal("QDeclarativePropertyCache: %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 QDeclarativePropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
425 QDeclarativePropertyData *sigdata = 0;
429 if (data->isSignal())
430 data->flags |= signalFlags;
432 data->flags |= methodFlags;
434 if (!dynamicMetaObject)
435 data->flags |= QDeclarativePropertyData::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 |= QDeclarativePropertyData::IsSignalHandler;
446 QDeclarativePropertyData *old = 0;
449 QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
450 if (QDeclarativePropertyData **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 (QDeclarativePropertyData **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 |= QDeclarativePropertyData::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 QDeclarativePropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
512 data->lazyLoad(p, engine);
513 data->flags |= propertyFlags;
515 if (!dynamicMetaObject)
516 data->flags |= QDeclarativePropertyData::IsDirect;
518 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
519 data->metaObjectOffset = allowedRevisionCache.count() - 1;
521 QDeclarativePropertyData *old = 0;
524 QHashedString propName(QString::fromUtf8(str, cptr - str));
525 if (QDeclarativePropertyData **it = stringCache.value(propName))
527 stringCache.insert(propName, data);
529 QHashedCStringRef propName(str, cptr - str);
530 if (QDeclarativePropertyData **it = stringCache.value(propName))
532 stringCache.insert(propName, data);
535 QDeclarativeAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
537 // Fast properties may not be overrides
538 Q_ASSERT(accessorProperty == 0 || old == 0);
540 if (accessorProperty) {
541 data->flags |= QDeclarativePropertyData::HasAccessors;
542 data->accessors = accessorProperty->accessors;
543 data->accessorData = accessorProperty->data;
545 data->overrideIndexIsProperty = !old->isFunction();
546 data->overrideIndex = old->coreIndex;
551 void QDeclarativePropertyCache::resolve(QDeclarativePropertyData *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 &= ~QDeclarativePropertyData::NotFullyResolved;
563 void QDeclarativePropertyCache::updateRecur(QDeclarativeEngine *engine, const QMetaObject *metaObject)
568 updateRecur(engine, metaObject->superClass());
570 append(engine, metaObject);
573 void QDeclarativePropertyCache::update(QDeclarativeEngine *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);
596 QDeclarativePropertyData *
597 QDeclarativePropertyCache::property(int index) const
599 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
602 if (index < propertyIndexCacheStart)
603 return parent->property(index);
605 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
606 if (rv->notFullyResolved()) resolve(rv);
610 QDeclarativePropertyData *
611 QDeclarativePropertyCache::method(int index) const
613 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
616 if (index < methodIndexCacheStart)
617 return parent->method(index);
619 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
620 if (rv->notFullyResolved()) resolve(rv);
624 QDeclarativePropertyData *
625 QDeclarativePropertyCache::property(const QHashedStringRef &str) const
627 QDeclarativePropertyData **rv = stringCache.value(str);
628 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
632 QDeclarativePropertyData *
633 QDeclarativePropertyCache::property(const QHashedCStringRef &str) const
635 QDeclarativePropertyData **rv = stringCache.value(str);
636 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
640 QDeclarativePropertyData *
641 QDeclarativePropertyCache::property(const QString &str) const
643 QDeclarativePropertyData **rv = stringCache.value(str);
644 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
648 QString QDeclarativePropertyData::name(QObject *object)
653 return name(object->metaObject());
656 QString QDeclarativePropertyData::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 QDeclarativePropertyCache::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 *QDeclarativePropertyCache::methodParameterTypes(QObject *object, int index,
705 QVarLengthArray<int, 9> &dummy,
706 QByteArray *unknownTypeError)
708 Q_ASSERT(object && index >= 0);
710 QDeclarativeData *ddata = QDeclarativeData::get(object, false);
712 if (ddata && ddata->propertyCache) {
713 typedef QDeclarativePropertyCacheMethodArguments A;
715 QDeclarativePropertyCache *c = ddata->propertyCache;
716 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
718 while (index < c->methodIndexCacheStart)
721 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&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 QDeclarativePropertyData qDeclarativePropertyCacheCreate(const QMetaObject *metaObject,
772 const QString &property)
774 Q_ASSERT(metaObject);
776 QDeclarativePropertyData rv;
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 &qDeclarativePropertyCacheToString(const QString &string)
825 inline QString qDeclarativePropertyCacheToString(const QHashedV8String &string)
827 return QV8Engine::toStringStatic(string.string());
831 QDeclarativePropertyData *
832 qDeclarativePropertyCacheProperty(QDeclarativeEngine *engine, QObject *obj,
833 const T &name, QDeclarativePropertyData &local)
835 QDeclarativePropertyCache *cache = 0;
838 QDeclarativeData *ddata = QDeclarativeData::get(obj);
840 if (ddata && ddata->propertyCache) {
841 cache = ddata->propertyCache;
843 QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
844 cache = ep->cache(obj);
846 ddata = QDeclarativeData::get(obj, true);
848 ddata->propertyCache = cache;
853 QDeclarativePropertyData *rv = 0;
856 rv = cache->property(name);
858 local = qDeclarativePropertyCacheCreate(obj->metaObject(),
859 qDeclarativePropertyCacheToString(name));
867 QDeclarativePropertyData *
868 QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
869 const QHashedV8String &name, QDeclarativePropertyData &local)
871 return qDeclarativePropertyCacheProperty<QHashedV8String>(engine, obj, name, local);
874 QDeclarativePropertyData *
875 QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
876 const QString &name, QDeclarativePropertyData &local)
878 return qDeclarativePropertyCacheProperty<QString>(engine, obj, name, local);
881 static inline const QMetaObjectPrivate *priv(const uint* data)
882 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
884 bool QDeclarativePropertyCache::isDynamicMetaObject(const QMetaObject *mo)
886 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;