From d911034f461859a72b45aeca0f34c34808e3f09b Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 11 May 2020 13:16:10 +0200 Subject: QV4Engine: Fix type conversion When converting JS arrays to sequence type, check first for the existence of a QJSValue -> T converter function. This restores the behavior from Qt <= 5.14. Amends ecdb4ed275a0869dc668d73d774735575d43a0a3 Fixes: QTBUG-84104 Change-Id: I14c86ab37e34a3c8cff072574d4b90fe9e558535 Reviewed-by: Ulf Hermann --- src/qml/jsruntime/qv4engine.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index b308737434..4d4013db48 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1576,7 +1576,18 @@ static QVariant toVariant(QV4::ExecutionEngine *e, const QV4::Value &value, int QV4::ScopedValue arrayValue(scope); for (qint64 i = 0; i < length; ++i) { arrayValue = a->get(i); - QVariant asVariant = toVariant(e, arrayValue, retnAsIterable._metaType_id, false, visitedObjects); + QVariant asVariant; + if (QMetaType::hasRegisteredConverterFunction(qMetaTypeId(), retnAsIterable._metaType_id)) { + // before attempting a conversion from the concrete types, + // check if there exists a conversion from QJSValue -> out type + // prefer that one for compatibility reasons + asVariant = QVariant::fromValue(QJSValuePrivate::fromReturnedValue(arrayValue->asReturnedValue())); + if (asVariant.convert(retnAsIterable._metaType_id)) { + retnAsIterable.append(asVariant.constData()); + continue; + } + } + asVariant = toVariant(e, arrayValue, retnAsIterable._metaType_id, false, visitedObjects); auto originalType = asVariant.userType(); bool couldConvert = asVariant.convert(retnAsIterable._metaType_id); if (!couldConvert) { -- cgit v1.2.3