diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-05-11 13:16:10 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-05-19 09:21:00 +0200 |
commit | d911034f461859a72b45aeca0f34c34808e3f09b (patch) | |
tree | cbe6ec5a93c7efd95ca71dfefe6c91f517100b89 /src | |
parent | 3c1e3552d301e064cf8b9380c4c6f5564f797ec4 (diff) |
QV4Engine: Fix type conversion
When converting JS arrays to sequence<T> 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 <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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<QJSValue>(), 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) { |