aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
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
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')
-rw-r--r--tests/auto/qml/qqmlecmascript/testtypes.h20
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp41
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h
index 59e0a9cb65..99fc6c96ab 100644
--- a/tests/auto/qml/qqmlecmascript/testtypes.h
+++ b/tests/auto/qml/qqmlecmascript/testtypes.h
@@ -891,6 +891,26 @@ public:
Q_INVOKABLE void method_unknown(NonRegisteredType) { invoke(28); }
+ Q_INVOKABLE void method_overload2(QQmlV4Function *v)
+ {
+ invoke(31);
+ QV4::Scope scope(v->v4engine());
+ for (int i = 0, end = v->length(); i != end; ++i) {
+ QV4::ScopedValue v4Value(scope, (*v)[i]);
+ m_actuals.append(v->v4engine()->toVariant(v4Value, QMetaType()));
+ }
+ }
+ Q_INVOKABLE void method_overload2(const QVariantList &list)
+ {
+ invoke(32);
+ m_actuals << QVariant(list);
+ }
+ Q_INVOKABLE void method_overload2(const QVariantMap &map) { invoke(33); m_actuals << map; }
+ Q_INVOKABLE void method_overload2(int a) { invoke(34); m_actuals << a; }
+ Q_INVOKABLE void method_overload2(int a, int b) { invoke(35); m_actuals << a << b; }
+ Q_INVOKABLE void method_overload2(QString a) { invoke(36); m_actuals << a; }
+ Q_INVOKABLE void method_overload2() { invoke(37); }
+
private:
friend class MyInvokableBaseObject;
void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;}
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()