Skip to content

Commit

Permalink
Fix support for QJSValue as C++ signal parameter type, part 2
Browse files Browse the repository at this point in the history
After commit 0e3380f 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 aa869cb, 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 <avrac@freebox.fr>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
  • Loading branch information
tronical committed Jan 18, 2017
1 parent 563b640 commit 89c6bee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qml/qml/qqmlboundsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QJSValue>()) {
if (QV4::Value *v4Value = QJSValuePrivate::getValue(reinterpret_cast<QJSValue *>(a[ii + 1])))
if (QV4::Value *v4Value = QJSValuePrivate::valueForData(reinterpret_cast<QJSValue *>(a[ii + 1]), &callData->args[ii]))
callData->args[ii] = *v4Value;
else
callData->args[ii] = QV4::Encode::undefined();
Expand Down
8 changes: 7 additions & 1 deletion tests/auto/qml/qqmlecmascript/data/signalParameterTypes.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 6 additions & 1 deletion tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<int>(), 42);

delete object;
}

Expand Down

0 comments on commit 89c6bee

Please sign in to comment.