diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-04-01 08:14:52 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-04-01 10:29:28 +0200 |
commit | 4cf0962dc4d8d48aa600c5b56b160c8553782140 (patch) | |
tree | 8ee6066054363c1c44790473efc21bca62329f1c | |
parent | dbc6b9bfc7e6f1c7e212460105b426b8e80db671 (diff) |
Warn if too many parameters are passed to a C++ function
Change-Id: I8ddf55d48d9276be5880e89e7b854f3355891f8e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 4 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 4e387d0380..ea809064a3 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1574,6 +1574,18 @@ static QV4::ReturnedValue CallPrecise(const QQmlObjectOrGadget &object, const QQ return engine->throwError(error); } + if (args[0] < callArgs->argc()) { + Q_ASSERT(!engine->stackTrace().isEmpty()); + + const StackFrame frame = engine->stackTrace().first(); + qWarning().noquote() << frame.function + QLatin1Char('@') + frame.source + + (frame.line > 0 ? (QLatin1Char(':') + QString::number(frame.line)) + : QString()); + + qWarning().noquote() << QStringLiteral("Too many arguments, ignoring %1") + .arg(callArgs->argc() - args[0]); + } + return CallMethod(object, data.coreIndex(), returnType, args[0], args + 1, engine, callArgs, callType); } else { diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index fbb344f9a0..5dfe76c2f2 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2694,6 +2694,8 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->actuals().count(), 0); // Excessive arguments + QTest::ignoreMessage(QtWarningMsg, qPrintable("Too many arguments, ignoring 1")); + o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(10, 11)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); @@ -2701,6 +2703,8 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->actuals().count(), 1); QCOMPARE(o->actuals().at(0), QVariant(10)); + QTest::ignoreMessage(QtWarningMsg, qPrintable("Too many arguments, ignoring 1")); + o->reset(); QVERIFY(EVALUATE_VALUE("object.method_intint(10, 11, 12)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); |