diff options
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 35 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmldata_p.h | 31 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 60 | ||||
-rw-r--r-- | src/qml/qml/qqmlincubator.cpp | 19 | ||||
-rw-r--r-- | src/qml/qml/qqmlincubator_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 27 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator_p.h | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 150 | ||||
-rw-r--r-- | src/qml/qml/qqmlproperty_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 80 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlvme.cpp | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmlvme_p.h | 1 |
14 files changed, 218 insertions, 220 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 8ec8669c60..e895f1df1b 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -496,8 +496,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, QObject *parent) Create a QQmlComponent from the given \a url and give it the specified \a parent and \a engine. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note \sa loadUrl() */ @@ -511,8 +510,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, const QUrl &url, QObject *paren specified \a parent and \a engine. If \a mode is \l Asynchronous, the component will be loaded and compiled asynchronously. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note \sa loadUrl() */ @@ -548,7 +546,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, const QString &fileName, : QQmlComponent(engine, parent) { Q_D(QQmlComponent); - const QUrl url = QDir::isAbsolutePath(fileName) ? QUrl::fromLocalFile(fileName) : d->engine->baseUrl().resolved(QUrl(fileName)); + const QUrl url = QDir::isAbsolutePath(fileName) ? QUrl::fromLocalFile(fileName) : QUrl(fileName); d->loadUrl(url, mode); } @@ -561,7 +559,7 @@ QQmlComponent::QQmlComponent(QQmlEngine *engine, QV4::CompiledData::CompilationU Q_D(QQmlComponent); d->compilationUnit = compilationUnit; d->start = start; - d->url = compilationUnit->url(); + d->url = compilationUnit->finalUrl(); d->progress = 1.0; } @@ -608,8 +606,7 @@ QQmlContext *QQmlComponent::creationContext() const /*! Load the QQmlComponent from the provided \a url. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note */ void QQmlComponent::loadUrl(const QUrl &url) { @@ -621,8 +618,7 @@ void QQmlComponent::loadUrl(const QUrl &url) Load the QQmlComponent from the provided \a url. If \a mode is \l Asynchronous, the component will be loaded and compiled asynchronously. - Ensure that the URL provided is full and correct, in particular, use - \l QUrl::fromLocalFile() when loading a file from the local filesystem. + \include qqmlcomponent.qdoc url-note */ void QQmlComponent::loadUrl(const QUrl &url, QQmlComponent::CompilationMode mode) { @@ -635,11 +631,21 @@ void QQmlComponentPrivate::loadUrl(const QUrl &newUrl, QQmlComponent::Compilatio Q_Q(QQmlComponent); clear(); - if ((newUrl.isRelative() && !newUrl.isEmpty()) - || newUrl.scheme() == QLatin1String("file")) // Workaround QTBUG-11929 - url = engine->baseUrl().resolved(newUrl); - else + if (newUrl.isRelative()) { + // The new URL is a relative URL like QUrl("main.qml"). + url = engine->baseUrl().resolved(QUrl(newUrl.toString())); + } else if (engine->baseUrl().isLocalFile() && newUrl.isLocalFile() && !QDir::isAbsolutePath(newUrl.toLocalFile())) { + // The new URL is a file on disk but it's a relative path; e.g.: + // QUrl::fromLocalFile("main.qml") or QUrl("file:main.qml") + // We need to remove the scheme so that it becomes a relative URL with a relative path: + QUrl fixedUrl(newUrl); + fixedUrl.setScheme(QString()); + // Then, turn it into an absolute URL with an absolute path by resolving it against the engine's baseUrl(). + // This is a compatibility hack for QTBUG-58837. + url = engine->baseUrl().resolved(fixedUrl); + } else { url = newUrl; + } if (newUrl.isEmpty()) { QQmlError error; @@ -1073,7 +1079,6 @@ void QQmlComponentPrivate::incubateObject( QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component); incubatorPriv->compilationUnit = componentPriv->compilationUnit; - incubatorPriv->compilationUnit->addref(); incubatorPriv->enginePriv = enginePriv; incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext)); incubatorPriv->subComponentToCreate = componentPriv->start; diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 37cb328b36..59e2c83a63 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -845,14 +845,14 @@ QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames() QUrl QQmlContextData::url() const { if (typeCompilationUnit) - return typeCompilationUnit->url(); + return typeCompilationUnit->finalUrl(); return baseUrl; } QString QQmlContextData::urlString() const { if (typeCompilationUnit) - return typeCompilationUnit->fileName(); + return typeCompilationUnit->finalUrlString(); return baseUrlString; } diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h index 63994a392d..5794e6f0c5 100644 --- a/src/qml/qml/qqmldata_p.h +++ b/src/qml/qml/qqmldata_p.h @@ -156,18 +156,21 @@ public: quint32 hasInterceptorMetaObject:1; quint32 hasVMEMetaObject:1; quint32 parentFrozen:1; - quint32 dummy:22; + quint32 dummy:6; // When bindingBitsSize < sizeof(ptr), we store the binding bit flags inside // bindingBitsValue. When we need more than sizeof(ptr) bits, we allocated // sufficient space and use bindingBits to point to it. - int bindingBitsSize; + quint32 bindingBitsArraySize : 16; typedef quintptr BindingBitsType; + enum { + BitsPerType = sizeof(BindingBitsType) * 8, + InlineBindingArraySize = 2 + }; union { BindingBitsType *bindingBits; - BindingBitsType bindingBitsValue; + BindingBitsType bindingBitsValue[InlineBindingArraySize]; }; - enum { MaxInlineBits = sizeof(BindingBitsType) * 8 }; struct NotifyList { quint64 connectionMask; @@ -259,7 +262,7 @@ public: bool hasExtendedData() const { return extendedData != 0; } QHash<int, QObject *> *attachedProperties() const; - static inline bool wasDeleted(QObject *); + static inline bool wasDeleted(const QObject *); static void markAsDeleted(QObject *); static void setQueuedForDeletion(QObject *); @@ -275,6 +278,9 @@ public: return createPropertyCache(engine, object); } + Q_ALWAYS_INLINE static uint offsetForBit(int bit) { return static_cast<uint>(bit) / BitsPerType; } + Q_ALWAYS_INLINE static BindingBitsType bitFlagForBit(int bit) { return BindingBitsType(1) << (static_cast<uint>(bit) & (BitsPerType - 1)); } + private: // For attachedProperties mutable QQmlDataExtended *extendedData; @@ -286,26 +292,25 @@ private: Q_ALWAYS_INLINE bool hasBitSet(int bit) const { - if (bindingBitsSize <= bit) + uint offset = offsetForBit(bit); + if (bindingBitsArraySize <= offset) return false; - if (bindingBitsSize == MaxInlineBits) - return bindingBitsValue & (BindingBitsType(1) << bit); - else - return bindingBits[bit / MaxInlineBits] & (BindingBitsType(1) << (bit % MaxInlineBits)); + const BindingBitsType *bits = (bindingBitsArraySize == InlineBindingArraySize) ? bindingBitsValue : bindingBits; + return bits[offset] & bitFlagForBit(bit); } }; -bool QQmlData::wasDeleted(QObject *object) +bool QQmlData::wasDeleted(const QObject *object) { if (!object) return true; - QObjectPrivate *priv = QObjectPrivate::get(object); + const QObjectPrivate *priv = QObjectPrivate::get(object); if (!priv || priv->wasDeleted) return true; - QQmlData *ddata = QQmlData::get(object); + const QQmlData *ddata = QQmlData::get(object); return ddata && ddata->isQueuedForDeletion; } diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 20f9b6439d..d53c94e901 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -110,7 +110,10 @@ Q_DECLARE_METATYPE(QQmlProperty) QT_BEGIN_NAMESPACE typedef QQmlData::BindingBitsType BindingBitsType; -enum { MaxInlineBits = QQmlData::MaxInlineBits }; +enum { + BitsPerType = QQmlData::BitsPerType, + InlineBindingArraySize = QQmlData::InlineBindingArraySize +}; void qmlRegisterBaseTypes(const char *uri, int versionMajor, int versionMinor) { @@ -747,11 +750,12 @@ QQmlData::QQmlData() : ownedByQml1(false), ownMemory(true), indestructible(true), explicitIndestructibleSet(false), hasTaintedV4Object(false), isQueuedForDeletion(false), rootObjectInCreation(false), hasInterceptorMetaObject(false), hasVMEMetaObject(false), parentFrozen(false), - bindingBitsSize(MaxInlineBits), bindingBitsValue(0), notifyList(0), + bindingBitsArraySize(InlineBindingArraySize), notifyList(0), bindings(0), signalHandlers(0), nextContextObject(0), prevContextObject(0), lineNumber(0), columnNumber(0), jsEngineId(0), compilationUnit(0), propertyCache(0), guards(0), extendedData(0) { + memset(bindingBitsValue, 0, sizeof(bindingBitsValue)); init(); } @@ -1825,7 +1829,7 @@ void QQmlData::destroyed(QObject *object) signalHandler = next; } - if (bindingBitsSize > MaxInlineBits) + if (bindingBitsArraySize > InlineBindingArraySize) free(bindingBits); if (propertyCache) @@ -1874,47 +1878,35 @@ void QQmlData::parentChanged(QObject *object, QObject *parent) static void QQmlData_setBit(QQmlData *data, QObject *obj, int bit) { - if (Q_UNLIKELY(data->bindingBitsSize <= bit)) { + uint offset = QQmlData::offsetForBit(bit); + BindingBitsType *bits = (data->bindingBitsArraySize == InlineBindingArraySize) ? data->bindingBitsValue : data->bindingBits; + if (Q_UNLIKELY(data->bindingBitsArraySize <= offset)) { int props = QQmlMetaObject(obj).propertyCount(); Q_ASSERT(bit < 2 * props); - int arraySize = (2 * props + MaxInlineBits - 1) / MaxInlineBits; - Q_ASSERT(arraySize > 1); - - // special handling for 32 here is to make sure we wipe the first byte - // when going from bindingBitsValue to bindingBits, and preserve the old - // set bits so we can restore them after the allocation - int oldArraySize = data->bindingBitsSize > MaxInlineBits ? data->bindingBitsSize / MaxInlineBits : 0; - quintptr oldValue = data->bindingBitsSize == MaxInlineBits ? data->bindingBitsValue : 0; - - data->bindingBits = static_cast<BindingBitsType *>(realloc((data->bindingBitsSize == MaxInlineBits) ? 0 : data->bindingBits, - arraySize * sizeof(BindingBitsType))); - - memset(data->bindingBits + oldArraySize, - 0x00, - sizeof(BindingBitsType) * (arraySize - oldArraySize)); + uint arraySize = (2 * static_cast<uint>(props) + BitsPerType - 1) / BitsPerType; + Q_ASSERT(arraySize > InlineBindingArraySize && arraySize > data->bindingBitsArraySize); - data->bindingBitsSize = arraySize * MaxInlineBits; + BindingBitsType *newBits = static_cast<BindingBitsType *>(malloc(arraySize*sizeof(BindingBitsType))); + memcpy(newBits, bits, data->bindingBitsArraySize * sizeof(BindingBitsType)); + memset(newBits + data->bindingBitsArraySize, 0, sizeof(BindingBitsType) * (arraySize - data->bindingBitsArraySize)); - // reinstate bindingBitsValue after we dropped it - if (oldValue) { - memcpy(data->bindingBits, &oldValue, sizeof(oldValue)); - } + if (data->bindingBitsArraySize > InlineBindingArraySize) + free(bits); + data->bindingBits = newBits; + bits = newBits; + data->bindingBitsArraySize = arraySize; } - - if (data->bindingBitsSize == MaxInlineBits) - data->bindingBitsValue |= BindingBitsType(1) << bit; - else - data->bindingBits[bit / MaxInlineBits] |= (BindingBitsType(1) << (bit % MaxInlineBits)); + Q_ASSERT(offset < data->bindingBitsArraySize); + bits[offset] |= QQmlData::bitFlagForBit(bit); } static void QQmlData_clearBit(QQmlData *data, int bit) { - if (data->bindingBitsSize > bit) { - if (data->bindingBitsSize == MaxInlineBits) - data->bindingBitsValue &= ~(BindingBitsType(1) << (bit % MaxInlineBits)); - else - data->bindingBits[bit / MaxInlineBits] &= ~(BindingBitsType(1) << (bit % MaxInlineBits)); + uint offset = QQmlData::offsetForBit(bit); + if (data->bindingBitsArraySize > offset) { + BindingBitsType *bits = (data->bindingBitsArraySize == InlineBindingArraySize) ? data->bindingBitsValue : data->bindingBits; + bits[offset] &= ~QQmlData::bitFlagForBit(bit); } } diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index 6d0e4b915a..9855c27375 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -272,7 +272,7 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) if (!compilationUnit) return; - QML_MEMORY_SCOPE_URL(compilationUnit->url()); + QML_MEMORY_SCOPE_URL(compilationUnit->finalUrl()); QExplicitlySharedDataPointer<QQmlIncubatorPrivate> protectThis(this); @@ -377,23 +377,6 @@ finishIncubate: } } -void QQmlIncubatorPrivate::cancel(QObject *object, QQmlContext *context) -{ - if (!context) - context = qmlContext(object); - if (!context) - return; - - QQmlContextData *data = QQmlContextData::get(context); - QQmlIncubatorPrivate *p = data->incubator; - if (!p) - return; - - p->vmeGuard.unguard(object); - if (!p->creator.isNull()) - p->creator->cancel(object); -} - /*! Incubate objects for \a msecs, or until there are no more objects to incubate. */ diff --git a/src/qml/qml/qqmlincubator_p.h b/src/qml/qml/qqmlincubator_p.h index 758e0a29f6..676ba1a29a 100644 --- a/src/qml/qml/qqmlincubator_p.h +++ b/src/qml/qml/qqmlincubator_p.h @@ -102,9 +102,6 @@ public: void forceCompletion(QQmlInstantiationInterrupt &i); void incubate(QQmlInstantiationInterrupt &i); - - // used by Qt Quick Controls 2 - Q_QML_PRIVATE_EXPORT static void cancel(QObject *object, QQmlContext *context = 0); }; QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 7761eb4677..7caab2a5d3 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -445,7 +445,7 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QString string = binding->valueAsString(qmlUnit); // Encoded dir-separators defeat QUrl processing - decode them first string.replace(QLatin1String("%2f"), QLatin1String("/"), Qt::CaseInsensitive); - QUrl value = string.isEmpty() ? QUrl() : compilationUnit->url().resolved(QUrl(string)); + QUrl value = string.isEmpty() ? QUrl() : compilationUnit->finalUrl().resolved(QUrl(string)); // Apply URL interceptor if (engine->urlInterceptor()) value = engine->urlInterceptor()->intercept(value, QQmlAbstractUrlInterceptor::UrlString); @@ -643,7 +643,8 @@ void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const } else if (property->propType() == qMetaTypeId<QList<QUrl> >()) { Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_String); QString urlString = binding->valueAsString(qmlUnit); - QUrl u = urlString.isEmpty() ? QUrl() : compilationUnit->url().resolved(QUrl(urlString)); + QUrl u = urlString.isEmpty() ? QUrl() + : compilationUnit->finalUrl().resolved(QUrl(urlString)); QList<QUrl> value; value.append(u); property->writeProperty(_qobject, &value, propertyWriteFlags); @@ -1103,12 +1104,9 @@ void QQmlObjectCreator::registerObjectWithContextById(const QV4::CompiledData::O context->setIdProperty(object->id, instance); } -QV4::QmlContext *QQmlObjectCreator::currentQmlContext() +void QQmlObjectCreator::createQmlContext() { - if (!_qmlContext->isManaged()) - _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); - - return _qmlContext; + _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); } QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isContextObject) @@ -1349,21 +1347,6 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru return sharedState->rootContext; } -void QQmlObjectCreator::cancel(QObject *object) -{ - int last = sharedState->allCreatedObjects.count() - 1; - int i = last; - while (i >= 0) { - if (sharedState->allCreatedObjects.at(i) == object) { - if (i < last) - qSwap(sharedState->allCreatedObjects[i], sharedState->allCreatedObjects[last]); - sharedState->allCreatedObjects.pop(); - break; - } - --i; - } -} - void QQmlObjectCreator::clear() { if (phase == Done || phase == Finalizing || phase == Startup) diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 593d89e5d5..f4c03af5b7 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -92,7 +92,6 @@ public: bool populateDeferredProperties(QObject *instance, QQmlData::DeferredData *deferredData); bool populateDeferredBinding(const QQmlProperty &qmlProperty, QQmlData::DeferredData *deferredData, const QV4::CompiledData::Binding *binding); QQmlContextData *finalize(QQmlInstantiationInterrupt &interrupt); - void cancel(QObject *object); void clear(); QQmlComponentAttached **componentAttachment() const { return &sharedState->componentAttached; } @@ -124,7 +123,8 @@ private: void registerObjectWithContextById(const QV4::CompiledData::Object *object, QObject *instance) const; - QV4::QmlContext *currentQmlContext(); + inline QV4::QmlContext *currentQmlContext(); + Q_NEVER_INLINE void createQmlContext(); enum Phase { Startup, @@ -174,6 +174,14 @@ private: QRecursionWatcher<QQmlObjectCreatorSharedState, &QQmlObjectCreatorSharedState::recursionNode> watcher; }; +QV4::QmlContext *QQmlObjectCreator::currentQmlContext() +{ + if (!_qmlContext->isManaged()) + _qmlContext->setM(QV4::QmlContext::create(v4->rootContext(), context, _scopeObject)); + + return _qmlContext; +} + QT_END_NAMESPACE #endif // QQMLOBJECTCREATOR_P_H diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 9a138dcf80..50d9f13049 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -223,6 +223,22 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine if (!isValid()) { d->object = 0; d->context = 0; d->engine = 0; } } +QQmlProperty QQmlPropertyPrivate::create(QObject *target, const QString &propertyName, QQmlContextData *context) +{ + QQmlProperty result; + auto d = new QQmlPropertyPrivate; + result.d = d; + d->context = context; + d->engine = context ? context->engine : nullptr; + d->initProperty(target, propertyName); + if (!result.isValid()) { + d->object = nullptr; + d->context = nullptr; + d->engine = nullptr; + } + return result; +} + QQmlPropertyPrivate::QQmlPropertyPrivate() : context(0), engine(0), object(0), isNameCached(false) { @@ -241,89 +257,93 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) QQmlTypeNameCache *typeNameCache = context?context->imports:0; - const auto path = name.splitRef(QLatin1Char('.')); - if (path.isEmpty()) return; - QObject *currentObject = obj; - - // Everything up to the last property must be an "object type" property - for (int ii = 0; ii < path.count() - 1; ++ii) { - const QStringRef &pathName = path.at(ii); - - if (typeNameCache) { - QQmlTypeNameCache::Result r = typeNameCache->query(pathName); - if (r.isValid()) { - if (r.type.isValid()) { - QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - } else if (r.importNamespace) { - if ((ii + 1) == path.count()) return; // No type following the namespace - - ++ii; r = typeNameCache->query(path.at(ii), r.importNamespace); - if (!r.type.isValid()) return; // Invalid type in namespace - - QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); - QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); - if (!func) return; // Not an attachable type - - currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); - if (!currentObject) return; // Something is broken with the attachable type - - } else if (r.scriptIndex != -1) { - return; // Not a type - } else { - Q_ASSERT(!"Unreachable"); + QVector<QStringRef> path; + QStringRef terminal(&name); + + if (name.contains(QLatin1Char('.'))) { + path = name.splitRef(QLatin1Char('.')); + if (path.isEmpty()) return; + + // Everything up to the last property must be an "object type" property + for (int ii = 0; ii < path.count() - 1; ++ii) { + const QStringRef &pathName = path.at(ii); + + if (typeNameCache) { + QQmlTypeNameCache::Result r = typeNameCache->query(pathName); + if (r.isValid()) { + if (r.type.isValid()) { + QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + } else if (r.importNamespace) { + if ((ii + 1) == path.count()) return; // No type following the namespace + + ++ii; r = typeNameCache->query(path.at(ii), r.importNamespace); + if (!r.type.isValid()) return; // Invalid type in namespace + + QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); + QQmlAttachedPropertiesFunc func = r.type.attachedPropertiesFunction(enginePrivate); + if (!func) return; // Not an attachable type + + currentObject = qmlAttachedPropertiesObjectById(r.type.attachedPropertiesId(enginePrivate), currentObject); + if (!currentObject) return; // Something is broken with the attachable type + + } else if (r.scriptIndex != -1) { + return; // Not a type + } else { + Q_ASSERT(!"Unreachable"); + } + continue; } - continue; + } - } + QQmlPropertyData local; + QQmlPropertyData *property = + QQmlPropertyCache::property(engine, currentObject, pathName, context, local); - QQmlPropertyData local; - QQmlPropertyData *property = - QQmlPropertyCache::property(engine, currentObject, pathName, context, local); + if (!property) return; // Not a property + if (property->isFunction()) + return; // Not an object property - if (!property) return; // Not a property - if (property->isFunction()) - return; // Not an object property + if (ii == (path.count() - 2) && QQmlValueTypeFactory::isValueType(property->propType())) { + // We're now at a value type property + const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(property->propType()); + if (!valueTypeMetaObject) return; // Not a value type - if (ii == (path.count() - 2) && QQmlValueTypeFactory::isValueType(property->propType())) { - // We're now at a value type property - const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(property->propType()); - if (!valueTypeMetaObject) return; // Not a value type + int idx = valueTypeMetaObject->indexOfProperty(path.last().toUtf8().constData()); + if (idx == -1) return; // Value type property does not exist - int idx = valueTypeMetaObject->indexOfProperty(path.last().toUtf8().constData()); - if (idx == -1) return; // Value type property does not exist + QMetaProperty vtProp = valueTypeMetaObject->property(idx); - QMetaProperty vtProp = valueTypeMetaObject->property(idx); + Q_ASSERT(vtProp.userType() <= 0x0000FFFF); + Q_ASSERT(idx <= 0x0000FFFF); - Q_ASSERT(vtProp.userType() <= 0x0000FFFF); - Q_ASSERT(idx <= 0x0000FFFF); + object = currentObject; + core = *property; + valueTypeData.setFlags(QQmlPropertyData::flagsForProperty(vtProp)); + valueTypeData.setPropType(vtProp.userType()); + valueTypeData.setCoreIndex(idx); - object = currentObject; - core = *property; - valueTypeData.setFlags(QQmlPropertyData::flagsForProperty(vtProp)); - valueTypeData.setPropType(vtProp.userType()); - valueTypeData.setCoreIndex(idx); + return; + } else { + if (!property->isQObject()) + return; // Not an object property - return; - } else { - if (!property->isQObject()) - return; // Not an object property + property->readProperty(currentObject, ¤tObject); + if (!currentObject) return; // No value - property->readProperty(currentObject, ¤tObject); - if (!currentObject) return; // No value + } } + terminal = path.last(); } - const QStringRef &terminal = path.last(); - if (terminal.count() >= 3 && terminal.at(0) == QLatin1Char('o') && terminal.at(1) == QLatin1Char('n') && diff --git a/src/qml/qml/qqmlproperty_p.h b/src/qml/qml/qqmlproperty_p.h index 53062a2f13..7a66d8113c 100644 --- a/src/qml/qml/qqmlproperty_p.h +++ b/src/qml/qml/qqmlproperty_p.h @@ -144,6 +144,8 @@ public: static void flushSignal(const QObject *sender, int signal_index); static QVariant resolvedUrlSequence(const QVariant &value, QQmlContextData *context); + static QQmlProperty create(QObject *target, const QString &propertyName, QQmlContextData *context); + }; Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlPropertyPrivate::BindingFlags) diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index a4db62eebf..4b6e69e617 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -356,8 +356,10 @@ qreal QQmlDataBlob::progress() const } /*! -Returns the blob url passed to the constructor. If a network redirect -happens while fetching the data, this url remains the same. +Returns the physical url of the data. Initially this is the same as +finalUrl(), but if a network redirect happens while fetching the data, this url +is updated to reflect the new location. Also, if a URL interceptor is set, it +will work on this URL and leave finalUrl() alone. \sa finalUrl() */ @@ -366,16 +368,25 @@ QUrl QQmlDataBlob::url() const return m_url; } +QString QQmlDataBlob::urlString() const +{ + if (m_urlString.isEmpty()) + m_urlString = m_url.toString(); + + return m_urlString; +} + /*! -Returns the final url of the data. Initially this is the same as -url(), but if a network redirect happens while fetching the data, this url -is updated to reflect the new location. +Returns the logical URL to be used for resolving further URLs referred to in +the code. -May only be called from the load thread, or after the blob isCompleteOrError(). +This is the blob url passed to the constructor. If a network redirect +happens while fetching the data, this url remains the same. + +\sa url() */ QUrl QQmlDataBlob::finalUrl() const { - Q_ASSERT(isCompleteOrError() || (m_typeLoader && m_typeLoader->m_thread->isThisThread())); return m_finalUrl; } @@ -384,7 +395,6 @@ Returns the finalUrl() as a string. */ QString QQmlDataBlob::finalUrlString() const { - Q_ASSERT(isCompleteOrError() || (m_typeLoader && m_typeLoader->m_thread->isThisThread())); if (m_finalUrlString.isEmpty()) m_finalUrlString = m_finalUrl.toString(); @@ -433,7 +443,7 @@ void QQmlDataBlob::setError(const QList<QQmlError> &errors) m_data.setStatus(Error); if (dumpErrors()) { - qWarning().nospace() << "Errors for " << m_finalUrl.toString(); + qWarning().nospace() << "Errors for " << urlString(); for (int ii = 0; ii < errors.count(); ++ii) qWarning().nospace() << " " << qPrintable(errors.at(ii).toString()); } @@ -472,7 +482,7 @@ void QQmlDataBlob::setError(const QString &description) { QQmlError e; e.setDescription(description); - e.setUrl(finalUrl()); + e.setUrl(url()); setError(e); } @@ -537,7 +547,7 @@ void QQmlDataBlob::networkError(QNetworkReply::NetworkError networkError) Q_UNUSED(networkError); QQmlError error; - error.setUrl(m_finalUrl); + error.setUrl(m_url); const char *errorString = 0; switch (networkError) { @@ -654,7 +664,7 @@ void QQmlDataBlob::tryDone() addref(); #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob::done() %s", qPrintable(url().toString())); + qWarning("QQmlDataBlob::done() %s", qPrintable(urlString())); #endif done(); @@ -893,7 +903,7 @@ void QQmlTypeLoaderThread::callCompletedMain(QQmlDataBlob *b) { QML_MEMORY_SCOPE_URL(b->url()); #ifdef DATABLOB_DEBUG - qWarning("QQmlTypeLoaderThread: %s completed() callback", qPrintable(b->url().toString())); + qWarning("QQmlTypeLoaderThread: %s completed() callback", qPrintable(b->urlString())); #endif b->completed(); b->release(); @@ -903,7 +913,7 @@ void QQmlTypeLoaderThread::callDownloadProgressChangedMain(QQmlDataBlob *b, qrea { #ifdef DATABLOB_DEBUG qWarning("QQmlTypeLoaderThread: %s downloadProgressChanged(%f) callback", - qPrintable(b->url().toString()), p); + qPrintable(b->urlString()), p); #endif b->downloadProgressChanged(p); b->release(); @@ -1037,7 +1047,7 @@ template<typename Loader> void QQmlTypeLoader::doLoad(const Loader &loader, QQmlDataBlob *blob, Mode mode) { #ifdef DATABLOB_DEBUG - qWarning("QQmlTypeLoader::doLoad(%s): %s thread", qPrintable(blob->m_url.toString()), + qWarning("QQmlTypeLoader::doLoad(%s): %s thread", qPrintable(blob->urlString()), m_thread->isThisThread()?"Compile":"Engine"); #endif blob->startLoading(); @@ -1159,7 +1169,7 @@ void QQmlTypeLoader::loadThread(QQmlDataBlob *blob) } #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob: requested %s", qPrintable(blob->url().toString())); + qWarning("QQmlDataBlob: requested %s", qPrintable(blob->urlString())); #endif // DATABLOB_DEBUG #endif // qml_network } @@ -1185,14 +1195,15 @@ void QQmlTypeLoader::networkReplyFinished(QNetworkReply *reply) QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (redirect.isValid()) { QUrl url = reply->url().resolved(redirect.toUrl()); - blob->m_finalUrl = url; + blob->m_url = url; + blob->m_urlString.clear(); QNetworkReply *reply = m_thread->networkAccessManager()->get(QNetworkRequest(url)); QObject *nrp = m_thread->networkReplyProxy(); QObject::connect(reply, SIGNAL(finished()), nrp, SLOT(finished())); m_networkReplies.insert(reply, blob); #ifdef DATABLOB_DEBUG - qWarning("QQmlDataBlob: redirected to %s", qPrintable(blob->m_finalUrl.toString())); + qWarning("QQmlDataBlob: redirected to %s", qPrintable(blob->urlString())); #endif return; } @@ -1348,7 +1359,7 @@ bool QQmlTypeLoader::Blob::fetchQmldir(const QUrl &url, const QV4::CompiledData: bool QQmlTypeLoader::Blob::updateQmldir(QQmlQmldirData *data, const QV4::CompiledData::Import *import, QList<QQmlError> *errors) { - QString qmldirIdentifier = data->url().toString(); + QString qmldirIdentifier = data->urlString(); QString qmldirUrl = qmldirIdentifier.left(qmldirIdentifier.lastIndexOf(QLatin1Char('/')) + 1); typeLoader()->setQmldirContent(qmldirIdentifier, data->content()); @@ -2104,7 +2115,7 @@ bool QQmlTypeData::tryLoadFromDiskCache() { QString error; if (!unit->loadFromDisk(url(), m_backupSourceCode.sourceTimeStamp(), v4->iselFactory.data(), &error)) { - qCDebug(DBG_DISK_CACHE) << "Error loading" << url().toString() << "from disk cache:" << error; + qCDebug(DBG_DISK_CACHE) << "Error loading" << urlString() << "from disk cache:" << error; return false; } } @@ -2224,10 +2235,10 @@ void QQmlTypeData::done() if (script.script->isError()) { QList<QQmlError> errors = script.script->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(script.location.line); error.setColumn(script.location.column); - error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->url().toString())); + error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->urlString())); errors.prepend(error); setError(errors); return; @@ -2244,7 +2255,7 @@ void QQmlTypeData::done() QList<QQmlError> errors = type.typeData->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(type.location.line); error.setColumn(type.location.column); error.setDescription(QQmlTypeLoader::tr("Type %1 unavailable").arg(typeName)); @@ -2263,7 +2274,7 @@ void QQmlTypeData::done() QList<QQmlError> errors = type.typeData->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(type.location.line); error.setColumn(type.location.column); error.setDescription(QQmlTypeLoader::tr("Type %1 unavailable").arg(typeName)); @@ -2293,7 +2304,7 @@ void QQmlTypeData::done() // verify if any dependencies changed if we're using a cache if (m_document.isNull() && !m_compiledData->verifyChecksum(dependencyHasher)) { - qCDebug(DBG_DISK_CACHE) << "Checksum mismatch for cached version of" << m_compiledData->url().toString(); + qCDebug(DBG_DISK_CACHE) << "Checksum mismatch for cached version of" << m_compiledData->fileName(); if (!loadFromSource()) return; m_backupSourceCode = SourceCodeData(); @@ -2458,7 +2469,7 @@ bool QQmlTypeData::loadFromSource() errors.reserve(compiler.errors.count()); for (const QQmlJS::DiagnosticMessage &msg : qAsConst(compiler.errors)) { QQmlError e; - e.setUrl(finalUrl()); + e.setUrl(url()); e.setLine(msg.loc.startLine); e.setColumn(msg.loc.startColumn); e.setDescription(msg.message); @@ -2475,7 +2486,8 @@ void QQmlTypeData::restoreIR(QQmlRefPointer<QV4::CompiledData::CompilationUnit> m_document.reset(new QmlIR::Document(isDebugging())); QmlIR::IRLoader loader(unit->data, m_document.data()); loader.load(); - m_document->jsModule.setFileName(finalUrlString()); + m_document->jsModule.setFileName(urlString()); + m_document->jsModule.setFinalUrl(finalUrlString()); m_document->javaScriptCompilationUnit = unit; continueLoadFromIR(); } @@ -2598,7 +2610,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCach // ignore error, keep using the in-memory compilation unit. } } else { - qCDebug(DBG_DISK_CACHE) << "Error saving cached version of" << m_compiledData->url().toString() << "to disk:" << errorString; + qCDebug(DBG_DISK_CACHE) << "Error saving cached version of" << m_compiledData->fileName() << "to disk:" << errorString; } } } @@ -2973,7 +2985,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) initializeFromCompilationUnit(unit); return; } else { - qCDebug(DBG_DISK_CACHE()) << "Error loading" << url().toString() << "from disk cache:" << error; + qCDebug(DBG_DISK_CACHE()) << "Error loading" << urlString() << "from disk cache:" << error; } } @@ -2991,7 +3003,9 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) QmlIR::ScriptDirectivesCollector collector(&irUnit.jsParserEngine, &irUnit.jsGenerator); QList<QQmlError> errors; - QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Script::precompile(&irUnit.jsModule, &irUnit.jsGenerator, v4, finalUrl(), source, &errors, &collector); + QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Script::precompile( + &irUnit.jsModule, &irUnit.jsGenerator, v4, urlString(), finalUrlString(), + source, &errors, &collector); // No need to addref on unit, it's initial refcount is 1 source.clear(); if (!errors.isEmpty()) { @@ -3015,7 +3029,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data) if (!disableDiskCache() || forceDiskCache()) { QString errorString; if (!unit->saveToDisk(url(), &errorString)) { - qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->url().toString() << "to disk:" << errorString; + qCDebug(DBG_DISK_CACHE()) << "Error saving cached version of" << unit->fileName() << "to disk:" << errorString; } } @@ -3039,10 +3053,10 @@ void QQmlScriptBlob::done() if (script.script->isError()) { QList<QQmlError> errors = script.script->errors(); QQmlError error; - error.setUrl(finalUrl()); + error.setUrl(url()); error.setLine(script.location.line); error.setColumn(script.location.column); - error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->url().toString())); + error.setDescription(QQmlTypeLoader::tr("Script %1 unavailable").arg(script.script->urlString())); errors.prepend(error); setError(errors); return; diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 22ac61968f..ab32bac7b2 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -129,6 +129,7 @@ public: qreal progress() const; QUrl url() const; + QString urlString() const; QUrl finalUrl() const; QString finalUrlString() const; @@ -207,6 +208,7 @@ private: QUrl m_url; QUrl m_finalUrl; + mutable QString m_urlString; mutable QString m_finalUrlString; // List of QQmlDataBlob's that are waiting for me to complete. diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp index c60f4edc80..72d4ab7e8f 100644 --- a/src/qml/qml/qqmlvme.cpp +++ b/src/qml/qml/qqmlvme.cpp @@ -120,18 +120,6 @@ void QQmlVMEGuard::guard(QQmlObjectCreator *creator) m_contexts[0] = creator->parentContextData(); } -void QQmlVMEGuard::unguard(QObject *object) -{ - for (int ii = 0; ii < m_objectCount; ++ii) { - if (m_objects[ii] == object) { - if (ii < m_objectCount - 1) - ::memmove((void *) m_objects[ii], (void *) m_objects[ii + 1], sizeof(QPointer<QObject> *)); - delete m_objects[--m_objectCount]; - break; - } - } -} - void QQmlVMEGuard::clear() { delete [] m_objects; diff --git a/src/qml/qml/qqmlvme_p.h b/src/qml/qml/qqmlvme_p.h index 9585b5b6df..99d63380ad 100644 --- a/src/qml/qml/qqmlvme_p.h +++ b/src/qml/qml/qqmlvme_p.h @@ -131,7 +131,6 @@ public: ~QQmlVMEGuard(); void guard(QQmlObjectCreator *); - void unguard(QObject *); void clear(); bool isOK() const; |