diff options
| author | Olivier De Cannière <olivier.decanniere@qt.io> | 2024-04-08 15:28:12 +0200 |
|---|---|---|
| committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2024-04-22 15:50:08 +0200 |
| commit | 152e6716baeffd22c381df8c37c188b8eab7d9df (patch) | |
| tree | 8fd390b5ea7b77b443f7a569310015c6a19ad0ea /src/qml/jsruntime/qv4jsonobject.cpp | |
| parent | 2f2345ee4e4af5bfe7749b24b8e85f30ccd97316 (diff) | |
V4: Handle all array-like containers when converting to QJsonArray
Commit b9bfdea0e2c6721d2306af0ecc44f88da9988957 removed specialized
code for QVariantList conversions by relying on sequences instead.
Some checks for sequences and other array-like containers were missed.
Add those and perform all calls to QJsonObject::toJsonArray through a
common QV4::Object interface.
Amends b9bfdea0e2c6721d2306af0ecc44f88da9988957
Pick-to: 6.7
Fixes: QTBUG-123993
Change-Id: Ia671d556af4f2b4d44f652fa93182977d88621f2
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4jsonobject.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4jsonobject.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index a834cf20d5..d78d09113a 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -988,12 +988,16 @@ QJsonValue JsonObject::toJsonValue(const Value &value, V4ObjectSet &visitedObjec Q_ASSERT(value.isObject()); Scope scope(value.as<Object>()->engine()); - ScopedArrayObject a(scope, value); - if (a) + if (ScopedArrayObject a{ scope, value }) { return toJsonArray(a, visitedObjects); - ScopedObject o(scope, value); - if (o) + } else if (Scoped<QV4::Sequence> a{ scope, value }) { + return toJsonArray(a, visitedObjects); + } else if (Scoped<QmlListWrapper> lw{ scope, value }) { + return toJsonArray(lw, visitedObjects); + } else if (ScopedObject o{ scope, value }) { return toJsonObject(o, visitedObjects); + } + return QJsonValue(value.toQString()); } @@ -1058,7 +1062,7 @@ QV4::ReturnedValue JsonObject::fromJsonArray(ExecutionEngine *engine, const QJso return a.asReturnedValue(); } -QJsonArray JsonObject::toJsonArray(const ArrayObject *a, V4ObjectSet &visitedObjects) +QJsonArray JsonObject::toJsonArray(const Object *a, V4ObjectSet &visitedObjects) { QJsonArray result; if (!a) |
