diff options
author | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-04-12 09:55:37 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2016-04-12 11:52:49 +0000 |
commit | 8ca22ca7eb5216513410651411fd2e0f07e50f34 (patch) | |
tree | c05967fe2204ef209fbaabe48c98cb36c7d6dd53 | |
parent | 826b628f79e231762df6ad95195e35e51e934966 (diff) |
Fix invocations of methods taking a QByteArray
Since commit 3b7e2a69f7eb8597c807de39b4de39721e9e2bd2 when calling a slot that
takes a QByteArray with a parameter that is not a QByteArray, we would end up
passing an empty QByteArray. This is a regression as previously we supported
the conversion code path, i.e. when passing a QString it would be converted to
utf-8, through QVariant's conversion code path. This code path needs to be
re-activated by removing this "shortcut". The shortcut is not necessary as the
execution engine's toVariant() function also knows how to apply the conversion.
Change-Id: I0600d195c94fa4e1e0b7ab807f045f0da42f595b
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 7 |
3 files changed, 8 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 470791fb00..fca218d9d0 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1591,12 +1591,6 @@ void CallArgument::fromValue(int callType, QV4::ExecutionEngine *engine, const Q else qstringPtr = new (&allocData) QString(value.toQStringNoThrow()); type = callType; - } else if (callType == QMetaType::QByteArray) { - if (const ArrayBuffer *ab = value.as<ArrayBuffer>()) - qbyteArrayPtr = new (&allocData) QByteArray(ab->asByteArray()); - else - qbyteArrayPtr = new (&allocData) QByteArray(); - type = callType; } else if (callType == QMetaType::QObjectStar) { qobjectPtr = 0; if (const QV4::QObjectWrapper *qobjectWrapper = value.as<QV4::QObjectWrapper>()) diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index e0d75e7baa..81b9b8d7bf 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -790,6 +790,7 @@ public: Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); } Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); } Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); } + Q_INVOKABLE void method_QByteArray(QByteArray value) { invoke(29); m_actuals << value; } Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; } Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index fa1a631a3d..f71d7efe3a 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2937,6 +2937,13 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); QCOMPARE(o->actuals().count(), 0); + + o->reset(); + QVERIFY(EVALUATE_VALUE("object.method_QByteArray(\"Hello\")", QV4::Primitive::undefinedValue())); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 29); + QCOMPARE(o->actuals().count(), 1); + QCOMPARE(qvariant_cast<QByteArray>(o->actuals().at(0)), QByteArray("Hello")); } // QTBUG-13047 (check that you can pass registered object types as args) |