diff options
author | Ulf Hermann <[email protected]> | 2022-12-01 17:09:23 +0100 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2022-12-15 17:47:11 +0100 |
commit | b13e22f2745562d0549461c85cfee1bbada631ce (patch) | |
tree | 55a84898ccb65084aa0e135c3e57b13604c16327 /src/qml/jsruntime/qv4engine_p.h | |
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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4engine_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 6fcf5e1b04..57aa7a782c 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -746,9 +746,28 @@ public: QMetaType type, const void *ptr, Heap::Object *parent = nullptr, int property = -1, uint flags = 0); + static void setMaxCallDepth(int maxCallDepth) { s_maxCallDepth = maxCallDepth; } static int maxCallDepth() { return s_maxCallDepth; } + template<typename Value> + static QJSPrimitiveValue createPrimitive(const Value &v) + { + if (v->isUndefined()) + return QJSPrimitiveValue(QJSPrimitiveUndefined()); + if (v->isNull()) + return QJSPrimitiveValue(QJSPrimitiveNull()); + if (v->isBoolean()) + return QJSPrimitiveValue(v->toBoolean()); + if (v->isInteger()) + return QJSPrimitiveValue(v->integerValue()); + if (v->isDouble()) + return QJSPrimitiveValue(v->doubleValue()); + bool ok; + const QString result = v->toQString(&ok); + return ok ? QJSPrimitiveValue(result) : QJSPrimitiveValue(QJSPrimitiveUndefined()); + } + private: template<int Frames> friend struct ExecutionEngineCallDepthRecorder; |