From 0b863bca305ad43b3c48287ec4e62e262c8e8849 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 20 Dec 2018 18:58:10 +0100 Subject: QML: Special case null as binding type This gives us the opportunity to map the JavaScript null to QVariant's concept of isNull(). [ChangeLog][QML] Assigning JavaScript null to incompatibly typed properties generates a compile error now, rather than a runtime error. Fixes: QTBUG-72098 Change-Id: I72fd1c30d84128c774230eaaea10455b2a0e064c Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml | 2 +- tests/auto/qml/qqmlecmascript/data/qmlVarNullBinding.qml | 7 +++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 7 +++++++ tests/auto/qml/qqmllanguage/data/objectDeletionNotify.1.qml | 2 +- tests/auto/qml/qqmllanguage/data/objectDeletionNotify.2.qml | 2 +- tests/auto/qml/qqmllanguage/data/objectDeletionNotify.3.qml | 2 +- 6 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/auto/qml/qqmlecmascript/data/qmlVarNullBinding.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml b/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml index 989b295cb5..c5ebed612c 100644 --- a/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml +++ b/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml @@ -18,7 +18,7 @@ Item{ id: b Item{ property bool testBool: false - property int testInt: null + property int testInt: { return null; } property QtObject testObject: null } } diff --git a/tests/auto/qml/qqmlecmascript/data/qmlVarNullBinding.qml b/tests/auto/qml/qqmlecmascript/data/qmlVarNullBinding.qml new file mode 100644 index 0000000000..6666b85ffd --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlVarNullBinding.qml @@ -0,0 +1,7 @@ +import QtQml 2.2 + +QtObject { + property var foo: null + property bool signalSeen: false + onFooChanged: signalSeen = true +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 085cd5ffd0..e247ed4eff 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -5991,6 +5991,13 @@ void tst_qqmlecmascript::nullObjectInitializer() QVERIFY(value.userType() == qMetaTypeId()); QVERIFY(!value.value()); } + + { + QQmlComponent component(&engine, testFileUrl("qmlVarNullBinding.qml")); + QScopedPointer obj(component.create()); + QVERIFY(!obj.isNull()); + QVERIFY(!obj->property("signalSeen").toBool()); + } } // Test that bindings don't evaluate once the engine has been destroyed diff --git a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.1.qml b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.1.qml index acd5463a3c..ac5622f9fb 100644 --- a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.1.qml +++ b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.1.qml @@ -10,7 +10,7 @@ Item { } } - property bool expectNull: null + property bool expectNull: { return null; } function setExpectNull(b) { success = false; diff --git a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.2.qml b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.2.qml index ed0e0d10f0..3c18739c32 100644 --- a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.2.qml +++ b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.2.qml @@ -10,7 +10,7 @@ Item { } } - property bool expectNull: null + property bool expectNull: { return null; } function setExpectNull(b) { success = false; diff --git a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.3.qml b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.3.qml index f5e94ba715..e2e560199f 100644 --- a/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.3.qml +++ b/tests/auto/qml/qqmllanguage/data/objectDeletionNotify.3.qml @@ -10,7 +10,7 @@ Item { } } - property bool expectNull: null + property bool expectNull: { return null; } function setExpectNull(b) { success = false; -- cgit v1.2.3