summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlbinding.cpp13
-rw-r--r--tests/auto/declarative/qmlecmascript/data/scriptErrors.qml7
-rw-r--r--tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp20
3 files changed, 36 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp
index b0a4d6e..ef92308 100644
--- a/src/declarative/qml/qmlbinding.cpp
+++ b/src/declarative/qml/qmlbinding.cpp
@@ -175,7 +175,18 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags)
bool isUndefined = false;
QVariant value = this->value(&isUndefined);
- if (!isUndefined && data->property.object() &&
+ if (isUndefined && !data->error.isValid()) {
+
+ QUrl url = data->url;
+ int line = data->line;
+ if (url.isEmpty()) url = QUrl(QLatin1String("<Unknown File>"));
+
+ data->error.setUrl(url);
+ data->error.setLine(line);
+ data->error.setColumn(-1);
+ data->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(data->property.propertyType())));
+
+ } else if (!isUndefined && data->property.object() &&
!data->property.write(value, flags)) {
QUrl url = data->url;
diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml
index d39b312..ff22990 100644
--- a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml
+++ b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml
@@ -4,9 +4,12 @@ MyQmlObject {
Script { source: "scriptErrors.js" }
Script { function getValue() { a = 10; return 0; } }
- property int x: a.value
- property int y: getValue();
+ property int t: a.value
+ property int w: getValue();
+ property int x: undefinedObject
+ property int y: (a.value, undefinedObject)
onBasicSignal: { print(a.value); }
+
}
diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
index 220f589..983ddd0 100644
--- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
+++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp
@@ -480,6 +480,12 @@ void tst_qmlecmascript::enums()
// Non-existant enums
{
QmlComponent component(&engine, TEST_FILE("enums.2.qml"));
+
+ QString warning1 = component.url().toString() + ":5: Unable to assign [undefined] to int";
+ QString warning2 = component.url().toString() + ":6: Unable to assign [undefined] to int";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+
QObject *object = component.create();
QVERIFY(object != 0);
QCOMPARE(object->property("a").toInt(), 0);
@@ -586,6 +592,10 @@ Tests for a regression where this used to crash.
void tst_qmlecmascript::nonExistantAttachedObject()
{
QmlComponent component(&engine, TEST_FILE("nonExistantAttachedObject.qml"));
+
+ QString warning = component.url().toString() + ":4: Unable to assign [undefined] to QString";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+
QObject *object = component.create();
QVERIFY(object != 0);
}
@@ -683,6 +693,10 @@ Tests that only methods of Script {} blocks are exposed.
void tst_qmlecmascript::scriptAccess()
{
QmlComponent component(&engine, TEST_FILE("scriptAccess.qml"));
+
+ QString warning = component.url().toString() + ":16: Unable to assign [undefined] to int";
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
+
QObject *object = component.create();
QVERIFY(object != 0);
@@ -811,11 +825,15 @@ void tst_qmlecmascript::scriptErrors()
QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\"";
QString warning2 = url + ":7: TypeError: Result of expression 'a' [undefined] is not an object.";
QString warning3 = url + ":5: Error: Invalid write to global property \"a\"";
- QString warning4 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning4 = url + ":12: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning5 = url + ":10: TypeError: Result of expression 'a' [undefined] is not an object.";
+ QString warning6 = url + ":9: Unable to assign [undefined] to int";
QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
+ QTest::ignoreMessage(QtWarningMsg, warning5.toLatin1().constData());
+ QTest::ignoreMessage(QtWarningMsg, warning6.toLatin1().constData());
MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
QVERIFY(object != 0);