aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4engine.cpp8
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.cpp17
-rw-r--r--tests/auto/qml/qjsvalue/tst_qjsvalue.h1
3 files changed, 26 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 320dc15a15..21aee81985 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -2338,6 +2338,14 @@ bool ExecutionEngine::metaTypeFromJS(const Value &value, int type, void *data)
}
{
+ const QMetaType metaType(type);
+ if (metaType.flags() & QMetaType::IsEnumeration) {
+ *reinterpret_cast<int *>(data) = value.toInt32();
+ return true;
+ }
+ }
+
+ {
const QQmlValueTypeWrapper *vtw = value.as<QQmlValueTypeWrapper>();
if (vtw && vtw->typeId() == type) {
return vtw->toGadget(data);
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
index fd2eb40717..2b91ca0019 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp
@@ -2872,4 +2872,21 @@ void tst_QJSValue::jsFunctionInVariant()
}
}
+void tst_QJSValue::integerToEnum()
+{
+ QJSEngine engine;
+
+ QJSValue enumVal = engine.toScriptValue(QQmlComponent::Error);
+ QJSValue intVal(static_cast<int>(QQmlComponent::Error));
+
+ QVERIFY(enumVal.equals(intVal));
+ QVERIFY(intVal.equals(enumVal));
+
+ QCOMPARE(qjsvalue_cast<QQmlComponent::Status>(intVal), QQmlComponent::Error);
+ QCOMPARE(qjsvalue_cast<QQmlComponent::Status>(enumVal), QQmlComponent::Error);
+
+ QCOMPARE(qjsvalue_cast<int>(intVal), static_cast<int>(QQmlComponent::Error));
+ QCOMPARE(qjsvalue_cast<int>(enumVal), static_cast<int>(QQmlComponent::Error));
+}
+
QTEST_MAIN(tst_QJSValue)
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.h b/tests/auto/qml/qjsvalue/tst_qjsvalue.h
index 0b35b58c58..db6ed4e413 100644
--- a/tests/auto/qml/qjsvalue/tst_qjsvalue.h
+++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.h
@@ -148,6 +148,7 @@ private slots:
void deleteFromDifferentThread();
void stringAndUrl();
void jsFunctionInVariant();
+ void integerToEnum();
private:
void newEngine()