From ba602c39e2ab7c16dcb212c935dbacdf053c6623 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 22 Oct 2009 18:16:47 +1000 Subject: Fix test failures. Also add a test for script errors within signal handlers. --- src/declarative/qml/qmlbinding.cpp | 6 ++++-- src/declarative/qml/qmlexpression.cpp | 6 ++++-- src/declarative/qml/qmlvme.cpp | 6 +++++- tests/auto/declarative/qmlecmascript/data/scriptErrors.qml | 6 ++++-- tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 6 +++++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 2b4e723..65ff789 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -128,8 +128,10 @@ void QmlBinding::update(QmlMetaProperty::WriteFlags flags) idx, a); } else { - QVariant value = this->value(); - if (data->property.object() && !data->property.write(value, flags)) { + bool undefined = false; + QVariant value = this->value(&undefined); + + if (!undefined && data->property.object() && !data->property.write(value, flags)) { QString fileName = data->fileName; int line = data->line; if (fileName.isEmpty()) fileName = QLatin1String(""); diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index d2bf4a8..7f01f0e 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -319,10 +319,12 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd QScriptValue svalue = data->expressionFunction.call(); if (isUndefined) - *isUndefined = svalue.isUndefined(); + *isUndefined = svalue.isUndefined() || scriptEngine->hasUncaughtException(); - if (scriptEngine->hasUncaughtException()) + if (scriptEngine->hasUncaughtException()) { printException(scriptEngine); + return QVariant(); + } if (secondaryScope) ctxtPriv->defaultObjects.removeAt(ctxtPriv->highPriorityCount); diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index 7f673a2..fc19ebd2 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -540,7 +540,11 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, QMetaMethod signal = target->metaObject()->method(instr.storeSignal.signalIndex); - (void *)new QmlBoundSignal(ctxt, primitives.at(instr.storeSignal.value), target, signal, target); + QmlBoundSignal *bs = new QmlBoundSignal(target, signal, target); + QmlExpression *expr = + new QmlExpression(ctxt, primitives.at(instr.storeSignal.value), target); + expr->setSourceLocation(comp->url, instr.line); + bs->setExpression(expr); } break; diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml index 3fb8ff7..d39b312 100644 --- a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml +++ b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml @@ -1,10 +1,12 @@ -import Qt 4.6 +import Qt.test 1.0 -Object { +MyQmlObject { Script { source: "scriptErrors.js" } Script { function getValue() { a = 10; return 0; } } property int x: a.value property int y: getValue(); + + onBasicSignal: { print(a.value); } } diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index 34b49e6..a7a2ef6 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -760,12 +760,16 @@ 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."; QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData()); QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData()); QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData()); - QObject *object = component.create(); + MyQmlObject *object = qobject_cast(component.create()); QVERIFY(object != 0); + + QTest::ignoreMessage(QtWarningMsg, warning4.toLatin1().constData()); + emit object->basicSignal(); } /* -- cgit v0.12