diff options
-rw-r--r-- | src/qml/jsapi/qjsprimitivevalue.h | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/equalityVarAndNonStorable.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/wrapwithvariant.h | 18 | ||||
-rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 5 |
5 files changed, 47 insertions, 0 deletions
diff --git a/src/qml/jsapi/qjsprimitivevalue.h b/src/qml/jsapi/qjsprimitivevalue.h index 93a3d0ff00..6070b07ede 100644 --- a/src/qml/jsapi/qjsprimitivevalue.h +++ b/src/qml/jsapi/qjsprimitivevalue.h @@ -16,6 +16,8 @@ QT_BEGIN_NAMESPACE +namespace QV4 { struct ExecutionEngine; } + struct QJSPrimitiveUndefined {}; struct QJSPrimitiveNull {}; @@ -522,6 +524,7 @@ public: private: friend class QJSManagedValue; friend class QJSValue; + friend struct QV4::ExecutionEngine; constexpr bool asBoolean() const { return d.getBool(); } constexpr int asInteger() const { return d.getInt(); } diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index e0a545fd32..4c7b7b3e9a 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1876,6 +1876,22 @@ QV4::ReturnedValue ExecutionEngine::fromData( return QV4::QObjectWrapper::wrapConst(this, *reinterpret_cast<QObject* const *>(ptr)); else return QV4::QObjectWrapper::wrap(this, *reinterpret_cast<QObject* const *>(ptr)); + } else if (metaType == QMetaType::fromType<QJSPrimitiveValue>()) { + const QJSPrimitiveValue *primitive = static_cast<const QJSPrimitiveValue *>(ptr); + switch (primitive->type()) { + case QJSPrimitiveValue::Boolean: + return Encode(primitive->asBoolean()); + case QJSPrimitiveValue::Integer: + return Encode(primitive->asInteger()); + case QJSPrimitiveValue::String: + return newString(primitive->asString())->asReturnedValue(); + case QJSPrimitiveValue::Undefined: + return Encode::undefined(); + case QJSPrimitiveValue::Null: + return Encode::null(); + case QJSPrimitiveValue::Double: + return Encode(primitive->asDouble()); + } } QV4::Scoped<Sequence> sequence(scope); diff --git a/tests/auto/qml/qmlcppcodegen/data/equalityVarAndNonStorable.qml b/tests/auto/qml/qmlcppcodegen/data/equalityVarAndNonStorable.qml index 54c8a0b84d..baf679aab2 100644 --- a/tests/auto/qml/qmlcppcodegen/data/equalityVarAndNonStorable.qml +++ b/tests/auto/qml/qmlcppcodegen/data/equalityVarAndNonStorable.qml @@ -28,4 +28,9 @@ QtObject { property bool jsValueIsNull: wrapped.nullJsValue === null property bool jsValueIsDefined: wrapped.intJSValue !== null && undefined !== wrapped.intJSValue property bool jsValueIsUndefined: wrapped.undefinedJsValue === undefined + + // QJSPrimitiveType + property bool primitiveIsNull: wrapped.nullPrimitiveValue === null + property bool primitiveIsDefined: wrapped.intPrimitiveValue !== null && undefined !== wrapped.intPrimitiveValue + property bool primitiveIsUndefined: wrapped.undefinedPrimitiveValue === undefined } diff --git a/tests/auto/qml/qmlcppcodegen/data/wrapwithvariant.h b/tests/auto/qml/qmlcppcodegen/data/wrapwithvariant.h index 9493068d94..dce78fa9c9 100644 --- a/tests/auto/qml/qmlcppcodegen/data/wrapwithvariant.h +++ b/tests/auto/qml/qmlcppcodegen/data/wrapwithvariant.h @@ -16,12 +16,30 @@ struct WrapWithVariant QML_VALUE_TYPE(wrappedWithVariant) QML_CONSTRUCTIBLE_VALUE + Q_PROPERTY(QVariant intPrimitiveValue READ intPrimitiveValue CONSTANT) + Q_PROPERTY(QVariant undefinedPrimitiveValue READ undefinedPrimitiveValue CONSTANT) + Q_PROPERTY(QVariant nullPrimitiveValue READ nullPrimitiveValue CONSTANT) Q_PROPERTY(QVariant intJSValue READ intJSValue CONSTANT) Q_PROPERTY(QVariant undefinedJsValue READ undefinedJsValue CONSTANT) Q_PROPERTY(QVariant nullJsValue READ nullJsValue CONSTANT) public: WrapWithVariant() = default; + QVariant intPrimitiveValue() const + { + return QVariant::fromValue<QJSPrimitiveValue>(QJSPrimitiveValue(12)); + } + + QVariant undefinedPrimitiveValue() const + { + return QVariant::fromValue<QJSPrimitiveValue>(QJSPrimitiveValue(QJSPrimitiveUndefined())); + } + + QVariant nullPrimitiveValue() const + { + return QVariant::fromValue<QJSPrimitiveValue>(QJSPrimitiveValue(QJSPrimitiveNull())); + } + QVariant intJSValue() const { return QVariant::fromValue<QJSValue>(QJSValue(23)); } QVariant undefinedJsValue() const diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index b43194cd93..65e882a089 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -3062,6 +3062,11 @@ void tst_QmlCppCodegen::equalityVarAndNonStorable() QVERIFY(!object->property("typedArrayIsNull").toBool()); QVERIFY(object->property("isUndefined").toBool()); QVERIFY(!object->property("derivedIsNull").toBool()); + + QVERIFY(object->property("primitiveIsNull").toBool()); + QVERIFY(object->property("primitiveIsDefined").toBool()); + QVERIFY(object->property("primitiveIsUndefined").toBool()); + QVERIFY(object->property("jsValueIsNull").toBool()); QVERIFY(object->property("jsValueIsDefined").toBool()); QVERIFY(object->property("jsValueIsUndefined").toBool()); |