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 if (parent) parent->release();
267 void QDeclarativePropertyCache::destroy()
269 Q_ASSERT(engine || constructor.IsEmpty());
270 if (constructor.IsEmpty())
273 QDeclarativeEnginePrivate::deleteInEngineThread(engine, this);
276 // This is inherited from QDeclarativeCleanup, so it should only clear the things
277 // that are tied to the specific QDeclarativeEngine.
278 void QDeclarativePropertyCache::clear()
280 qPersistentDispose(constructor);
284 QDeclarativePropertyCache *QDeclarativePropertyCache::copy(int reserve)
286 QDeclarativePropertyCache *cache = new QDeclarativePropertyCache(engine);
287 cache->parent = this;
288 cache->parent->addref();
289 cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart;
290 cache->methodIndexCacheStart = methodIndexCache.count() + methodIndexCacheStart;
291 cache->signalHanderIndexCacheStart = signalHandlerIndexCache.count() + signalHanderIndexCacheStart;
292 cache->stringCache.copyAndReserve(stringCache, reserve);
293 cache->allowedRevisionCache = allowedRevisionCache;
294 cache->metaObject = metaObject;
296 // We specifically do *NOT* copy the constructor
301 QDeclarativePropertyCache *QDeclarativePropertyCache::copy()
306 QDeclarativePropertyCache *
307 QDeclarativePropertyCache::copyAndAppend(QDeclarativeEngine *engine, const QMetaObject *metaObject,
308 QDeclarativePropertyData::Flag propertyFlags,
309 QDeclarativePropertyData::Flag methodFlags,
310 QDeclarativePropertyData::Flag signalFlags)
312 return copyAndAppend(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
315 QDeclarativePropertyCache *
316 QDeclarativePropertyCache::copyAndAppend(QDeclarativeEngine *engine, const QMetaObject *metaObject,
318 QDeclarativePropertyData::Flag propertyFlags,
319 QDeclarativePropertyData::Flag methodFlags,
320 QDeclarativePropertyData::Flag signalFlags)
322 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
324 // Reserve enough space in the name hash for all the methods (including signals), all the
325 // signal handlers and all the properties. This assumes no name clashes, but this is the
327 QDeclarativePropertyCache *rv = copy(QMetaObjectPrivate::get(metaObject)->methodCount +
328 QMetaObjectPrivate::get(metaObject)->signalCount +
329 QMetaObjectPrivate::get(metaObject)->propertyCount);
331 rv->append(engine, metaObject, revision, propertyFlags, methodFlags, signalFlags);
336 void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject,
337 QDeclarativePropertyData::Flag propertyFlags,
338 QDeclarativePropertyData::Flag methodFlags,
339 QDeclarativePropertyData::Flag signalFlags)
341 append(engine, metaObject, -1, propertyFlags, methodFlags, signalFlags);
344 void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaObject *metaObject,
346 QDeclarativePropertyData::Flag propertyFlags,
347 QDeclarativePropertyData::Flag methodFlags,
348 QDeclarativePropertyData::Flag signalFlags)
351 Q_ASSERT(constructor.IsEmpty()); // We should not be appending to an in-use property cache
353 this->metaObject = metaObject;
355 bool dynamicMetaObject = isDynamicMetaObject(metaObject);
357 allowedRevisionCache.append(0);
359 int methodCount = metaObject->methodCount();
360 Q_ASSERT(QMetaObjectPrivate::get(metaObject)->revision >= 4);
361 int signalCount = metaObjectSignalCount(metaObject);
362 int classInfoCount = QMetaObjectPrivate::get(metaObject)->classInfoCount;
364 QDeclarativeAccessorProperties::Properties accessorProperties;
366 // Special case QObject as we don't want to add a qt_HasQmlAccessors classinfo to it
367 if (metaObject == &QObject::staticMetaObject) {
368 accessorProperties = QDeclarativeAccessorProperties::properties(metaObject);
369 } else if (classInfoCount) {
370 int classInfoOffset = metaObject->classInfoOffset();
371 bool hasFastProperty = false;
372 for (int ii = 0; ii < classInfoCount; ++ii) {
373 int idx = ii + classInfoOffset;
375 if (0 == qstrcmp(metaObject->classInfo(idx).name(), "qt_HasQmlAccessors")) {
376 hasFastProperty = true;
381 if (hasFastProperty) {
382 accessorProperties = QDeclarativeAccessorProperties::properties(metaObject);
383 if (accessorProperties.count == 0)
384 qFatal("QDeclarativePropertyCache: %s has FastProperty class info, but has not "
385 "installed property accessors", metaObject->className());
388 accessorProperties = QDeclarativeAccessorProperties::properties(metaObject);
389 if (accessorProperties.count != 0)
390 qFatal("QDeclarativePropertyCache: %s has fast property accessors, but is missing "
391 "FastProperty class info", metaObject->className());
396 // qMax(defaultMethods, methodOffset) to block the signals and slots of QObject::staticMetaObject
397 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
398 int methodOffset = qMax(QObject::staticMetaObject.methodCount(), metaObject->methodOffset());
399 int signalOffset = signalCount - QMetaObjectPrivate::get(metaObject)->signalCount;
401 // update() should have reserved enough space in the vector that this doesn't cause a realloc
402 // and invalidate the stringCache.
403 methodIndexCache.resize(methodCount - methodIndexCacheStart);
404 signalHandlerIndexCache.resize(signalCount - signalHanderIndexCacheStart);
405 int signalHandlerIndex = signalOffset;
406 for (int ii = methodOffset; ii < methodCount; ++ii) {
407 QMetaMethod m = metaObject->method(ii);
408 if (m.access() == QMetaMethod::Private)
411 // Extract method name
412 const char *signature = m.signature();
413 const char *cptr = signature;
415 while (*cptr != '(') {
416 Q_ASSERT(*cptr != 0);
417 utf8 |= *cptr & 0x80;
421 QDeclarativePropertyData *data = &methodIndexCache[ii - methodIndexCacheStart];
422 QDeclarativePropertyData *sigdata = 0;
426 if (data->isSignal())
427 data->flags |= signalFlags;
429 data->flags |= methodFlags;
431 if (!dynamicMetaObject)
432 data->flags |= QDeclarativePropertyData::IsDirect;
434 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
435 data->metaObjectOffset = allowedRevisionCache.count() - 1;
437 if (data->isSignal()) {
438 sigdata = &signalHandlerIndexCache[signalHandlerIndex - signalHanderIndexCacheStart];
440 sigdata->flags |= QDeclarativePropertyData::IsSignalHandler;
443 QDeclarativePropertyData *old = 0;
446 QHashedString methodName(QString::fromUtf8(signature, cptr - signature));
447 if (QDeclarativePropertyData **it = stringCache.value(methodName))
449 stringCache.insert(methodName, data);
451 if (data->isSignal()) {
452 QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1));
453 stringCache.insert(on, sigdata);
454 ++signalHandlerIndex;
457 QHashedCStringRef methodName(signature, cptr - signature);
458 if (QDeclarativePropertyData **it = stringCache.value(methodName))
460 stringCache.insert(methodName, data);
462 if (data->isSignal()) {
463 int length = methodName.length();
465 QVarLengthArray<char, 128> str(length+3);
468 str[2] = toupper(signature[0]);
470 memcpy(&str[3], &signature[1], length - 1);
471 str[length + 2] = '\0';
473 QHashedString on(QString::fromLatin1(str.data()));
474 stringCache.insert(on, sigdata);
475 ++signalHandlerIndex;
480 // We only overload methods in the same class, exactly like C++
481 if (old->isFunction() && old->coreIndex >= methodOffset)
482 data->flags |= QDeclarativePropertyData::IsOverload;
483 data->overrideIndexIsProperty = !old->isFunction();
484 data->overrideIndex = old->coreIndex;
488 int propCount = metaObject->propertyCount();
489 int propOffset = metaObject->propertyOffset();
491 // update() should have reserved enough space in the vector that this doesn't cause a realloc
492 // and invalidate the stringCache.
493 propertyIndexCache.resize(propCount - propertyIndexCacheStart);
494 for (int ii = propOffset; ii < propCount; ++ii) {
495 QMetaProperty p = metaObject->property(ii);
496 if (!p.isScriptable())
499 const char *str = p.name();
501 const char *cptr = str;
503 utf8 |= *cptr & 0x80;
507 QDeclarativePropertyData *data = &propertyIndexCache[ii - propertyIndexCacheStart];
509 data->lazyLoad(p, engine);
510 data->flags |= propertyFlags;
512 if (!dynamicMetaObject)
513 data->flags |= QDeclarativePropertyData::IsDirect;
515 Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
516 data->metaObjectOffset = allowedRevisionCache.count() - 1;
518 QDeclarativePropertyData *old = 0;
521 QHashedString propName(QString::fromUtf8(str, cptr - str));
522 if (QDeclarativePropertyData **it = stringCache.value(propName))
524 stringCache.insert(propName, data);
526 QHashedCStringRef propName(str, cptr - str);
527 if (QDeclarativePropertyData **it = stringCache.value(propName))
529 stringCache.insert(propName, data);
532 QDeclarativeAccessorProperties::Property *accessorProperty = accessorProperties.property(str);
534 // Fast properties may not be overrides
535 Q_ASSERT(accessorProperty == 0 || old == 0);
537 if (accessorProperty) {
538 data->flags |= QDeclarativePropertyData::HasAccessors;
539 data->accessors = accessorProperty->accessors;
540 data->accessorData = accessorProperty->data;
542 data->overrideIndexIsProperty = !old->isFunction();
543 data->overrideIndex = old->coreIndex;
548 void QDeclarativePropertyCache::resolve(QDeclarativePropertyData *data) const
550 Q_ASSERT(data->notFullyResolved());
552 data->propType = QMetaType::type(data->propTypeName);
554 if (!data->isFunction())
555 data->flags |= flagsForPropertyType(data->propType, engine);
557 data->flags &= ~QDeclarativePropertyData::NotFullyResolved;
560 void QDeclarativePropertyCache::updateRecur(QDeclarativeEngine *engine, const QMetaObject *metaObject)
565 updateRecur(engine, metaObject->superClass());
567 append(engine, metaObject);
570 void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaObject *metaObject)
573 Q_ASSERT(metaObject);
574 Q_ASSERT(stringCache.isEmpty());
576 // Preallocate enough space in the index caches for all the properties/methods/signals that
577 // are not cached in a parent cache so that the caches never need to be reallocated as this
578 // would invalidate pointers stored in the stringCache.
579 int pc = metaObject->propertyCount();
580 int mc = metaObject->methodCount();
581 int sc = metaObjectSignalCount(metaObject);
582 propertyIndexCache.reserve(pc - propertyIndexCacheStart);
583 methodIndexCache.reserve(mc - methodIndexCacheStart);
584 signalHandlerIndexCache.reserve(sc - signalHanderIndexCacheStart);
586 // Reserve enough space in the stringCache for all properties/methods/signals including those
587 // cached in a parent cache.
588 stringCache.reserve(pc + mc + sc);
590 updateRecur(engine,metaObject);
593 QDeclarativePropertyData *
594 QDeclarativePropertyCache::property(int index) const
596 if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
599 if (index < propertyIndexCacheStart)
600 return parent->property(index);
602 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&propertyIndexCache.at(index - propertyIndexCacheStart));
603 if (rv->notFullyResolved()) resolve(rv);
607 QDeclarativePropertyData *
608 QDeclarativePropertyCache::method(int index) const
610 if (index < 0 || index >= (methodIndexCacheStart + methodIndexCache.count()))
613 if (index < methodIndexCacheStart)
614 return parent->method(index);
616 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&methodIndexCache.at(index - methodIndexCacheStart));
617 if (rv->notFullyResolved()) resolve(rv);
621 QDeclarativePropertyData *
622 QDeclarativePropertyCache::property(const QHashedStringRef &str) const
624 QDeclarativePropertyData **rv = stringCache.value(str);
625 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
629 QDeclarativePropertyData *
630 QDeclarativePropertyCache::property(const QHashedCStringRef &str) const
632 QDeclarativePropertyData **rv = stringCache.value(str);
633 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
637 QDeclarativePropertyData *
638 QDeclarativePropertyCache::property(const QString &str) const
640 QDeclarativePropertyData **rv = stringCache.value(str);
641 if (rv && (*rv)->notFullyResolved()) resolve(*rv);
645 QString QDeclarativePropertyData::name(QObject *object)
650 return name(object->metaObject());
653 QString QDeclarativePropertyData::name(const QMetaObject *metaObject)
655 if (!metaObject || coreIndex == -1)
658 if (flags & IsFunction) {
659 QMetaMethod m = metaObject->method(coreIndex);
661 QString name = QString::fromUtf8(m.signature());
662 int parenIdx = name.indexOf(QLatin1Char('('));
664 name = name.left(parenIdx);
667 QMetaProperty p = metaObject->property(coreIndex);
668 return QString::fromUtf8(p.name());
672 QStringList QDeclarativePropertyCache::propertyNames() const
675 for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
676 keys.append(iter.key());
680 static int EnumType(const QMetaObject *meta, const QByteArray &str)
684 int scopeIdx = str.lastIndexOf("::");
685 if (scopeIdx != -1) {
686 scope = str.left(scopeIdx);
687 name = str.mid(scopeIdx + 2);
691 for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
692 QMetaEnum m = meta->enumerator(i);
693 if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
694 return QVariant::Int;
696 return QVariant::Invalid;
699 // Returns an array of the arguments for method \a index. The first entry in the array
700 // is the number of arguments.
701 int *QDeclarativePropertyCache::methodParameterTypes(QObject *object, int index,
702 QVarLengthArray<int, 9> &dummy,
703 QByteArray *unknownTypeError)
705 Q_ASSERT(object && index >= 0);
707 QDeclarativeData *ddata = QDeclarativeData::get(object, false);
709 if (ddata && ddata->propertyCache) {
710 typedef QDeclarativePropertyCacheMethodArguments A;
712 QDeclarativePropertyCache *c = ddata->propertyCache;
713 Q_ASSERT(index < c->methodIndexCacheStart + c->methodIndexCache.count());
715 while (index < c->methodIndexCacheStart)
718 QDeclarativePropertyData *rv = const_cast<QDeclarativePropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
721 return static_cast<A *>(rv->arguments)->arguments;
723 const QMetaObject *metaObject = object->metaObject();
724 QMetaMethod m = metaObject->method(index);
725 QList<QByteArray> argTypeNames = m.parameterTypes();
727 A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int)));
728 args->arguments[0] = argTypeNames.count();
730 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
731 int type = QMetaType::type(argTypeNames.at(ii));
732 if (type == QVariant::Invalid)
733 type = EnumType(object->metaObject(), argTypeNames.at(ii));
734 if (type == QVariant::Invalid) {
735 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
739 args->arguments[ii + 1] = type;
742 rv->arguments = args;
743 args->next = c->argumentsCache;
744 c->argumentsCache = args;
745 return static_cast<A *>(rv->arguments)->arguments;
748 QMetaMethod m = object->metaObject()->method(index);
749 QList<QByteArray> argTypeNames = m.parameterTypes();
750 dummy.resize(argTypeNames.count() + 1);
751 dummy[0] = argTypeNames.count();
753 for (int ii = 0; ii < argTypeNames.count(); ++ii) {
754 int type = QMetaType::type(argTypeNames.at(ii));
755 if (type == QVariant::Invalid)
756 type = EnumType(object->metaObject(), argTypeNames.at(ii));
757 if (type == QVariant::Invalid) {
758 if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
761 dummy[ii + 1] = type;
768 QDeclarativePropertyData qDeclarativePropertyCacheCreate(const QMetaObject *metaObject,
769 const QString &property)
771 Q_ASSERT(metaObject);
773 QDeclarativePropertyData rv;
775 const QMetaObject *cmo = metaObject;
776 const QByteArray propertyName = property.toUtf8();
778 int idx = cmo->indexOfProperty(propertyName);
780 QMetaProperty p = cmo->property(idx);
781 if (p.isScriptable()) {
785 while (cmo && cmo->propertyOffset() >= idx)
786 cmo = cmo->superClass();
794 int methodCount = metaObject->methodCount();
795 int defaultMethods = QObject::staticMetaObject.methodCount();
796 for (int ii = methodCount - 1; ii >= defaultMethods; --ii) {
797 // >=defaultMethods to block the signals and slots of QObject::staticMetaObject
798 // incl. destroyed signals, objectNameChanged signal, deleteLater slot, _q_reregisterTimers slot.
799 QMetaMethod m = metaObject->method(ii);
800 if (m.access() == QMetaMethod::Private)
802 QString methodName = QString::fromUtf8(m.signature());
804 int parenIdx = methodName.indexOf(QLatin1Char('('));
805 Q_ASSERT(parenIdx != -1);
806 QStringRef methodNameRef = methodName.leftRef(parenIdx);
808 if (methodNameRef == property) {
817 inline const QString &qDeclarativePropertyCacheToString(const QString &string)
822 inline QString qDeclarativePropertyCacheToString(const QHashedV8String &string)
824 return QV8Engine::toStringStatic(string.string());
828 QDeclarativePropertyData *
829 qDeclarativePropertyCacheProperty(QDeclarativeEngine *engine, QObject *obj,
830 const T &name, QDeclarativePropertyData &local)
832 QDeclarativePropertyCache *cache = 0;
835 QDeclarativeData *ddata = QDeclarativeData::get(obj);
837 if (ddata && ddata->propertyCache) {
838 cache = ddata->propertyCache;
840 QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
841 cache = ep->cache(obj);
843 ddata = QDeclarativeData::get(obj, true);
845 ddata->propertyCache = cache;
850 QDeclarativePropertyData *rv = 0;
853 rv = cache->property(name);
855 local = qDeclarativePropertyCacheCreate(obj->metaObject(),
856 qDeclarativePropertyCacheToString(name));
864 QDeclarativePropertyData *
865 QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
866 const QHashedV8String &name, QDeclarativePropertyData &local)
868 return qDeclarativePropertyCacheProperty<QHashedV8String>(engine, obj, name, local);
871 QDeclarativePropertyData *
872 QDeclarativePropertyCache::property(QDeclarativeEngine *engine, QObject *obj,
873 const QString &name, QDeclarativePropertyData &local)
875 return qDeclarativePropertyCacheProperty<QString>(engine, obj, name, local);
878 static inline const QMetaObjectPrivate *priv(const uint* data)
879 { return reinterpret_cast<const QMetaObjectPrivate*>(data); }
881 bool QDeclarativePropertyCache::isDynamicMetaObject(const QMetaObject *mo)
883 return priv(mo->d.data)->revision >= 3 && priv(mo->d.data)->flags & DynamicMetaObject;