From 89c6bee139422b17534f79129eea2820d2ce952e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 16 Jan 2017 16:28:31 +0100 Subject: [PATCH] Fix support for QJSValue as C++ signal parameter type, part 2 After commit 0e3380f9c6ab6e3ea7398caccf5aa84f1575f1cd we wouldn't crash anymore, if QJSValue::UndefinedValue was provided as value for a QJSValue C++ signal parameter. However that was not a complete fix for the regression of commit aa869cbb06bcf005e238059a2cb0205947ff0b5f, as other primitive values stored in QJSValue as QVariant were not converted, so for example QJSValue(42). So let's fix this once and for all by using QJSValuePrivate::valueForData, that handles all types of QJSValuePrivate encodings. Task-number: QTBUG-58133 Change-Id: Ib7c0461b18df6260ccd4bce729ae2348281eb7f3 Reviewed-by: Arnaud Vrac Reviewed-by: Lars Knoll --- src/qml/qml/qqmlboundsignal.cpp | 2 +- .../auto/qml/qqmlecmascript/data/signalParameterTypes.qml | 8 +++++++- tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index d207a4908c0..1fdb0d2e25c 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -199,7 +199,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) // for several cases (such as QVariant type and QObject-derived types) //args[ii] = engine->metaTypeToJS(type, a[ii + 1]); if (type == qMetaTypeId()) { - if (QV4::Value *v4Value = QJSValuePrivate::getValue(reinterpret_cast(a[ii + 1]))) + if (QV4::Value *v4Value = QJSValuePrivate::valueForData(reinterpret_cast(a[ii + 1]), &callData->args[ii])) callData->args[ii] = *v4Value; else callData->args[ii] = QV4::Encode::undefined(); diff --git a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml index 676593096cb..54d29dfc945 100644 --- a/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml +++ b/tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml @@ -16,5 +16,11 @@ MyQmlObject onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1), MyQmlObject.EnumValue3, Qt.LeftButton) - onQjsValueEmittingSignal: {} + property bool emittedQjsValueWasUndefined + property int emittedQjsValueAsInt + + onQjsValueEmittingSignal: { + emittedQjsValueWasUndefined = value === undefined; + emittedQjsValueAsInt = value + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index b8f12e772d4..20f7940e9db 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -1410,7 +1410,6 @@ void tst_qqmlecmascript::signalParameterTypes() QVERIFY(object != 0); emit object->basicSignal(); - emit object->qjsValueEmittingSignal(QJSValue()); QCOMPARE(object->property("intProperty").toInt(), 10); QCOMPARE(object->property("realProperty").toReal(), 19.2); @@ -1419,6 +1418,12 @@ void tst_qqmlecmascript::signalParameterTypes() QVERIFY(object->property("enumProperty") == MyQmlObject::EnumValue3); QVERIFY(object->property("qtEnumProperty") == Qt::LeftButton); + emit object->qjsValueEmittingSignal(QJSValue()); + QVERIFY(object->property("emittedQjsValueWasUndefined").toBool()); + emit object->qjsValueEmittingSignal(QJSValue(42)); + QVERIFY(!object->property("emittedQjsValueWasUndefined").toBool()); + QCOMPARE(object->property("emittedQjsValueAsInt").value(), 42); + delete object; }