From b9bfdea0e2c6721d2306af0ecc44f88da9988957 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 19 Jun 2023 09:29:34 +0200 Subject: QML: Un-specialcase QStringList and QVariantList conversion Those are just regular sequences these days. They can be written back. Drop some now-dead code and deduplicate the value type conversion code in the process. We should try the (more common) value type conversion before the sequence conversion, but after all the "simple" conversions. [ChangeLog][QtQml][Important Behavior Changes] Converting a QVariantList to a QJSValue via, for example QJSEngine::toScriptValue() does not produce a JavaScript array anymore, but rather a better suited sequence object that behaves almost like a JavaScript array. The only difference is that its QJSValue::isArray() will return false now. Fixes: QTBUG-113690 Change-Id: Ib176c34d59c45a6b5cff68d029c4b1b87d7aa192 Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4jscall_p.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/qml/jsruntime/qv4jscall_p.h') diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index e824863b29..7bb38a5fe9 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -233,9 +233,17 @@ inline ReturnedValue coerceListType( ExecutionEngine *engine, const Value &value, const QQmlType &qmlType) { QMetaType type = qmlType.qListTypeId(); + const auto metaSequence = [&]() { + // TODO: We should really add the metasequence to the same QQmlType that holds + // all the other type information. Then we can get rid of the extra + // QQmlMetaType::qmlListType() here. + return qmlType.isSequentialContainer() + ? qmlType.listMetaSequence() + : QQmlMetaType::qmlListType(type).listMetaSequence(); + }; + if (const QV4::Sequence *sequence = value.as()) { - const QQmlTypePrivate *typePrivate = sequence->d()->typePrivate(); - if (typePrivate->listId == type) + if (sequence->d()->listType() == type) return value.asReturnedValue(); } @@ -256,7 +264,7 @@ inline ReturnedValue coerceListType( if (!array) { return (listValueType.flags() & QMetaType::PointerToQObject) ? QmlListWrapper::create(engine, listValueType) - : SequencePrototype::fromData(engine, type, nullptr); + : SequencePrototype::fromData(engine, type, metaSequence(), nullptr); } if (listValueType.flags() & QMetaType::PointerToQObject) { @@ -273,7 +281,8 @@ inline ReturnedValue coerceListType( return newList->asReturnedValue(); } - QV4::Scoped sequence(scope, SequencePrototype::fromData(engine, type, nullptr)); + QV4::Scoped sequence( + scope, SequencePrototype::fromData(engine, type, metaSequence(), nullptr)); const qsizetype length = array->getLength(); for (qsizetype i = 0; i < length; ++i) sequence->containerPutIndexed(i, array->get(i)); -- cgit v1.2.3