diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-02-15 13:04:03 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-02-21 12:13:59 +0100 |
| commit | b9834e0ee9f086add6dd8a42e5cb40f87f91756b (patch) | |
| tree | 741415067c35d6734da7232c56a8fcb4cc989bb3 /src/qml/jsruntime/qv4engine.cpp | |
| parent | dda138f467465c01573690eca13c6fd3ee1c8da5 (diff) | |
QmlCompiler: Fix coercion of undefined to float and double
It should result in NaN, not in 0. The typedArray() test exposes that
ExecutionEngine::toVariant() also gets this wrong. Fix that, too.
[ChangeLog][QtQml][Important Behavior Changes] Converting a JavaScript
value to a double or float, for example by inserting it into a typed
array, now assumes JavaScript type coercion semantics. In particular,
converting a value that is not actually a number now results in NaN
where it previously sometimes resulted in 0.
Pick-to: 6.5 6.4 6.2
Fixes: QTBUG-111179
Change-Id: If24444ae9014c8972761c565a6920f06699e485c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 20be25be2f..56cc4efb48 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1502,6 +1502,12 @@ static QVariant toVariant( if (metaType == QMetaType::fromType<bool>()) return QVariant(value.toBoolean()); + if (metaType == QMetaType::fromType<double>()) + return QVariant(value.toNumber()); + + if (metaType == QMetaType::fromType<float>()) + return QVariant(float(value.toNumber())); + if (metaType == QMetaType::fromType<QJsonValue>()) return QVariant::fromValue(QV4::JsonObject::toJsonValue(value)); |
