diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-05-23 13:51:15 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-05-28 15:22:14 +0200 |
| commit | c16a3e5adb59f6da5e39e51ca15a4d5324d68d1c (patch) | |
| tree | 20a8b5e59f392e332b49e0854fe869d001c139e1 /src/qml/jsruntime/qv4engine.cpp | |
| parent | d2e355d10179890e41df1fe50e3f2322ff08c038 (diff) | |
QtQml: Document and uphold precondition of metaTypeFromJS()
The value needs to be a default-constructed instance. Otherwise a number
of branches in this method produce unwanted effects, such as appending
to an already existing array rather than creating a new one.
Amends commit 1b89c1edcae68351632c2755e5408410c2ff98e3.
Pick-to: 6.7 6.5
Fixes: QTBUG-125429
Change-Id: If175a02b3a794573abc03df206fbddd41f2855b4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index bd6251caa9..6754c3c887 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -2479,18 +2479,22 @@ bool convertToIterable(QMetaType metaType, void *data, Source *sequence) return false; const QMetaType elementMetaType = iterable.valueMetaType(); - QVariant element(elementMetaType); for (qsizetype i = 0, end = sequence->getLength(); i < end; ++i) { - if (!ExecutionEngine::metaTypeFromJS(sequence->get(i), elementMetaType, element.data())) - element = QVariant(elementMetaType); + QVariant element(elementMetaType); + ExecutionEngine::metaTypeFromJS(sequence->get(i), elementMetaType, element.data()); iterable.addValue(element, QSequentialIterable::AtEnd); } return true; } -// Converts a JS value to a meta-type. -// data must point to a place that can store a value of the given type. -// Returns true if conversion succeeded, false otherwise. +/*! + * \internal + * + * Converts a JS value to a meta-type. + * \a data must point to a default-constructed instance of \a metaType. + * Returns \c true if conversion succeeded, \c false otherwise. In the latter case, + * \a data is not modified. + */ bool ExecutionEngine::metaTypeFromJS(const Value &value, QMetaType metaType, void *data) { // check if it's one of the types we know |
