From b13e22f2745562d0549461c85cfee1bbada631ce Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 1 Dec 2022 17:09:23 +0100 Subject: 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 --- src/qml/jsruntime/qv4engine_p.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/qml/jsruntime/qv4engine_p.h') 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 + 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 friend struct ExecutionEngineCallDepthRecorder; -- cgit v1.2.3