Fix crash when C++ QJSValue parameterized signal interacts with JS
When converting the parameters of a C++ signal to JS values to provide
to a signal handler written in JS, the conversion of a QJSValue to a
QV4::Value* may yield a null pointer in case of a default constructed
QJSValue for example. This is a regression from commit
aa869cbb06
and we must check for this.
Task-number: QTBUG-58133
Change-Id: I528b606b2851dfb3072e54902bd8843d31571a55
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
6e568c6ef5
commit
0e3380f9c6
|
@ -199,7 +199,10 @@ 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>()) {
|
||||
callData->args[ii] = *QJSValuePrivate::getValue(reinterpret_cast<QJSValue *>(a[ii + 1]));
|
||||
if (QV4::Value *v4Value = QJSValuePrivate::getValue(reinterpret_cast<QJSValue *>(a[ii + 1])))
|
||||
callData->args[ii] = *v4Value;
|
||||
else
|
||||
callData->args[ii] = QV4::Encode::undefined();
|
||||
} else if (type == QMetaType::QVariant) {
|
||||
callData->args[ii] = scope.engine->fromVariant(*((QVariant *)a[ii + 1]));
|
||||
} else if (type == QMetaType::Int) {
|
||||
|
|
|
@ -15,4 +15,6 @@ MyQmlObject
|
|||
onMySignal: { intProperty = a; realProperty = b; colorProperty = c; variantProperty = d; enumProperty = e; qtEnumProperty = f; }
|
||||
|
||||
onBasicSignal: root.mySignal(10, 19.2, Qt.rgba(1, 1, 0, 1), Qt.rgba(1, 0, 1, 1), MyQmlObject.EnumValue3, Qt.LeftButton)
|
||||
|
||||
onQjsValueEmittingSignal: {}
|
||||
}
|
||||
|
|
|
@ -244,6 +244,7 @@ signals:
|
|||
void signalWithGlobalName(int parseInt);
|
||||
void intChanged();
|
||||
void qjsvalueChanged();
|
||||
void qjsValueEmittingSignal(QJSValue value);
|
||||
|
||||
public slots:
|
||||
void deleteMe() { delete this; }
|
||||
|
|
|
@ -1410,6 +1410,7 @@ 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);
|
||||
|
|
Loading…
Reference in New Issue