diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-25 14:18:05 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-26 08:27:28 +0100 |
commit | 6b08c24297f39f3c67bc5c16f46198b33af66529 (patch) | |
tree | d0998702cd05f22e0e6129e9d582c6efbda023c8 /tests/auto/qml/qjsvalue | |
parent | 63304384c8333c2aead5243c926f4f1b8be4dabf (diff) |
QJSValue: On toVariant() don't try to unwrap function objects
We cannot retrieve anything sensible from those. Therefore, just wrap
the QJSValue into a variant.
Change-Id: I8acd9fb59a8859c8b2c389efb7934b597a2e479f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qjsvalue')
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index 0ae1fb6dfb..7f35282e89 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -1077,6 +1077,21 @@ void tst_QJSValue::toVariant() qInstallMessageHandler(handler); } + + // function + { + QJSValue func = eng.evaluate("(function() { return 5 + 5 })"); + QVERIFY(func.isCallable()); + QCOMPARE(func.call().toInt(), 10); + + QVariant funcVar = func.toVariant(); + QVERIFY(funcVar.isValid()); + QCOMPARE(funcVar.metaType(), QMetaType::fromType<QJSValue>()); + + QJSValue func2 = eng.toScriptValue(funcVar); + QVERIFY(func2.isCallable()); + QCOMPARE(func2.call().toInt(), 10); + } } void tst_QJSValue::toQObject_nonQObject_data() |