aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4sequenceobject.cpp
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2022-02-03 14:43:47 +0100
committerUlf Hermann <[email protected]>2022-02-11 09:36:59 +0100
commitd2737bdedb6a53f83bab1c1c5606bcfc1df91687 (patch)
treef9cd94276d5a422675f7bbce3005aa56c31e269a /src/qml/jsruntime/qv4sequenceobject.cpp
parent1e8206f7e6bd7a37138921520e0ae43d9ec68eb6 (diff)
QML: Clean up sequence registrations for value types
We want to be able to construct a meaningful list type by surrounding the internal name of the type with QList<>. Usually this works because of the way we auto-register sequential containers for types. Only for the builtins we need to do some special casing. That special casing should happen in the builtins, not in QtQml, though. The generic QList<foo> sequence type is implicitly given for any value type foo these days. There is no need to mention it in .qmltypes. QtQml retains some extra container declarations that are not straight QList<foo> for a value type foo. Everything that's registered by the value type registration anyway is dropped. We keep the aliases QStringList and QVariantList in the builtins because they are really common. Since we now register QVariantList the way it's mandated by the builtins, we also have to handle it correctly in qv4sequenceobject.cpp. In particular, we need to append variants as-is rather than poking into them. As QStringList is an additional builtin now, we need to teach the type resolver about it. Change-Id: I0dfb5b780b27250f36f6886bc4e0926a03c114b4 Reviewed-by: Andrei Golubev <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 42ad6b8716..a265a67e24 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -129,8 +129,14 @@ public:
QVariant at(int index) const
{
const auto *p = d();
- QVariant result(valueMetaType(p));
- metaSequence(p)->valueAtIndex(p->container, index, result.data());
+ const QMetaType v = valueMetaType(p);
+ QVariant result;
+ if (v == QMetaType::fromType<QVariant>()) {
+ metaSequence(p)->valueAtIndex(p->container, index, &result);
+ } else {
+ result = QVariant(v);
+ metaSequence(p)->valueAtIndex(p->container, index, result.data());
+ }
return result;
}
@@ -141,6 +147,8 @@ public:
const QMetaType v = valueMetaType(p);
if (item.metaType() == v) {
m->addValueAtEnd(p->container, item.constData());
+ } else if (v == QMetaType::fromType<QVariant>()) {
+ m->addValueAtEnd(p->container, &item);
} else {
QVariant converted = item;
if (!converted.convert(v))
@@ -156,6 +164,8 @@ public:
const QMetaType v = valueMetaType(p);
if (item.metaType() == v) {
m->setValueAtIndex(p->container, index, item.constData());
+ } else if (v == QMetaType::fromType<QVariant>()) {
+ m->setValueAtIndex(p->container, index, &item);
} else {
QVariant converted = item;
if (!converted.convert(v))
@@ -270,8 +280,11 @@ public:
} else {
/* according to ECMA262r3 we need to insert */
/* the value at the given index, increasing length to index+1. */
- while (index > count++)
- append(QVariant(valueType));
+ while (index > count++) {
+ append(valueType == QMetaType::fromType<QVariant>()
+ ? QVariant()
+ : QVariant(valueType));
+ }
append(element);
}
@@ -687,15 +700,19 @@ QVariant SequencePrototype::toVariant(const QV4::Value &array, QMetaType typeHin
for (quint32 i = 0; i < length; ++i) {
const QMetaType valueMetaType = priv->typeId;
QVariant variant = scope.engine->toVariant(a->get(i), valueMetaType, false);
- const QMetaType originalType = variant.metaType();
- if (originalType != valueMetaType && !variant.convert(valueMetaType)) {
- qWarning() << QLatin1String(
- "Could not convert array value at position %1 from %2 to %3")
- .arg(QString::number(i), QString::fromUtf8(originalType.name()),
- QString::fromUtf8(valueMetaType.name()));
- variant = QVariant(valueMetaType);
+ if (valueMetaType == QMetaType::fromType<QVariant>()) {
+ meta->addValueAtEnd(result.data(), &variant);
+ } else {
+ const QMetaType originalType = variant.metaType();
+ if (originalType != valueMetaType && !variant.convert(valueMetaType)) {
+ qWarning() << QLatin1String(
+ "Could not convert array value at position %1 from %2 to %3")
+ .arg(QString::number(i), QString::fromUtf8(originalType.name()),
+ QString::fromUtf8(valueMetaType.name()));
+ variant = QVariant(valueMetaType);
+ }
+ meta->addValueAtEnd(result.data(), variant.constData());
}
- meta->addValueAtEnd(result.data(), variant.constData());
}
return result;
}