diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-01 17:09:23 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-15 17:47:11 +0100 |
commit | b13e22f2745562d0549461c85cfee1bbada631ce (patch) | |
tree | 55a84898ccb65084aa0e135c3e57b13604c16327 /src/qml/jsapi/qjsvalue.cpp | |
parent | dfdba3b12bc10a3e1da8cde99a8697969ac165ef (diff) |
QmlCompiler: Fix wrapping of numbers in QJSPrimitiveValue
We need to explicitly cast to double if we are wrapping a number type
that's not natively accepted by the ctors.
As a side effect, correctly run conversions from generic QVariant to
QJSPrimitiveValue through the engine now. For that we need another
clause in metaTypeFromJS().
Since we are calling methods that return list types in the test, we need
to add another clause that converts JS arrays to list types. Otherwise
we cannot run that test in interpreted mode.
Pick-to: 6.5 6.2 6.4 6.4.2
Task-number: QTBUG-109111
Change-Id: I87f7aafd24371d2c1ffe85569e1f2cd3a1979742
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsapi/qjsvalue.cpp')
-rw-r--r-- | src/qml/jsapi/qjsvalue.cpp | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp index 5d1cfc4cd2..7306d00d6a 100644 --- a/src/qml/jsapi/qjsvalue.cpp +++ b/src/qml/jsapi/qjsvalue.cpp @@ -633,20 +633,7 @@ QJSPrimitiveValue QJSValue::toPrimitive() const return *string; const QV4::Value val = QV4::Value::fromReturnedValue(QJSValuePrivate::asReturnedValue(this)); - if (val.isUndefined()) - return QJSPrimitiveUndefined(); - if (val.isNull()) - return QJSPrimitiveNull(); - if (val.isBoolean()) - return val.toBoolean(); - if (val.isInteger()) - return val.integerValue(); - if (val.isDouble()) - return val.doubleValue(); - - bool ok; - const QString result = val.toQString(&ok); - return ok ? QJSPrimitiveValue(result) : QJSPrimitiveValue(QJSPrimitiveUndefined()); + return QV4::ExecutionEngine::createPrimitive(&val); } /*! |