aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-10-19 15:49:32 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-10-21 09:47:01 +0200
commit9021f46cc0ce1d89d5d62ccb622085437c8350a8 (patch)
tree0f205a21ca3282d62c71ada8babcb83da3e334da /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parente37809ec62927f33de2d6ae07e2610d6382b5466 (diff)
QV4::QObjectWrapper: Improve overload resolution
QQmlV4Function should be used as the last fallback if there are other options available. Also, take QVariantMap into account. Change-Id: I9ebf39f4f860cf3bf44c6cbc80efbac7ea30c70b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 98b08a0e23..47d3aee5da 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -3345,6 +3345,47 @@ void tst_qqmlecmascript::callQtInvokables()
QJSValue callback = qvariant_cast<QJSValue>(o->actuals().at(1));
QVERIFY(!callback.isNull());
QVERIFY(callback.isCallable());
+
+ o->reset();
+ QVERIFY(EVALUATE_VALUE("object.method_overload2('foo', 12, [1, 2, 3])", QV4::Primitive::undefinedValue()));
+ QCOMPARE(o->error(), false);
+ QCOMPARE(o->invoked(), 31);
+ QCOMPARE(o->actuals().count(), 3);
+ QCOMPARE(qvariant_cast<QString>(o->actuals().at(0)), QStringLiteral("foo"));
+ QCOMPARE(qvariant_cast<int>(o->actuals().at(1)), 12);
+ QCOMPARE(qvariant_cast<QVariantList>(o->actuals().at(2)), (QVariantList {1.0, 2.0, 3.0}));
+
+ o->reset();
+ QVERIFY(EVALUATE_VALUE("object.method_overload2(11, 12, {a: 1, b: 2})", QV4::Primitive::undefinedValue()));
+ QCOMPARE(o->error(), false);
+ QCOMPARE(o->invoked(), 31);
+ QCOMPARE(o->actuals().count(), 3);
+ QCOMPARE(qvariant_cast<int>(o->actuals().at(0)), 11);
+ QCOMPARE(qvariant_cast<int>(o->actuals().at(1)), 12);
+ QCOMPARE(qvariant_cast<QVariantMap>(o->actuals().at(2)),
+ (QVariantMap { {QStringLiteral("a"), 1.0}, {QStringLiteral("b"), 2.0}, }));
+
+ o->reset();
+ QVERIFY(EVALUATE_VALUE("object.method_overload2([1, 'bar', 0.2])",
+ QV4::Primitive::undefinedValue()));
+ QCOMPARE(o->error(), false);
+ QCOMPARE(o->invoked(), 32);
+ QCOMPARE(o->actuals().count(), 1);
+ QCOMPARE(qvariant_cast<QVariantList>(o->actuals().at(0)),
+ (QVariantList {1.0, QStringLiteral("bar"), 0.2}));
+
+ o->reset();
+ QVERIFY(EVALUATE_VALUE("object.method_overload2({one: 1, two: 'bar', three: 0.2})",
+ QV4::Primitive::undefinedValue()));
+ QCOMPARE(o->error(), false);
+ QCOMPARE(o->invoked(), 33);
+ QCOMPARE(o->actuals().count(), 1);
+ QCOMPARE(qvariant_cast<QVariantMap>(o->actuals().at(0)),
+ (QVariantMap {
+ {QStringLiteral("one"), 1.0},
+ {QStringLiteral("two"), QStringLiteral("bar")},
+ {QStringLiteral("three"), 0.2}
+ }));
}
void tst_qqmlecmascript::resolveClashingProperties()