summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlxmlhttprequest.cpp30
-rw-r--r--tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp20
2 files changed, 35 insertions, 15 deletions
diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp
index 5fd14e7..f69f254 100644
--- a/src/declarative/qml/qmlxmlhttprequest.cpp
+++ b/src/declarative/qml/qmlxmlhttprequest.cpp
@@ -45,6 +45,7 @@
#include "qmlengine_p.h"
#include "qmlrefcount_p.h"
#include "qmlengine_p.h"
+#include "qmlexpression_p.h"
#include <QtCore/qobject.h>
#include <QtScript/qscriptvalue.h>
@@ -979,6 +980,7 @@ private:
QScriptValue dispatchCallback();
QScriptValue m_callback;
+ void printError(const QScriptValue&);
int m_status;
QString m_statusText;
@@ -1199,8 +1201,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes)
m_state = HeadersReceived;
fillHeadersList ();
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
bool wasEmpty = m_responseEntityBody.isEmpty();
@@ -1208,8 +1209,7 @@ void QmlXMLHttpRequest::downloadProgress(qint64 bytes)
if (wasEmpty && !m_responseEntityBody.isEmpty()) {
m_state = Loading;
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
}
@@ -1233,16 +1233,14 @@ void QmlXMLHttpRequest::error(QNetworkReply::NetworkError error)
error == QNetworkReply::ContentReSendError) {
m_state = Loading;
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
} else {
m_errorFlag = true;
}
m_state = Done;
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
void QmlXMLHttpRequest::finished()
@@ -1258,21 +1256,18 @@ void QmlXMLHttpRequest::finished()
m_state = HeadersReceived;
fillHeadersList ();
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
m_responseEntityBody.append(m_network->readAll());
destroyNetwork();
if (m_state < Loading) {
m_state = Loading;
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
m_state = Done;
QScriptValue cbv = dispatchCallback();
- if (cbv.isError())
- qWarning().nospace() << qPrintable(cbv.toString());
+ if (cbv.isError()) printError(cbv);
}
@@ -1286,6 +1281,13 @@ QScriptValue QmlXMLHttpRequest::dispatchCallback()
return m_callback.call();
}
+void QmlXMLHttpRequest::printError(const QScriptValue& sv)
+{
+ QmlError error;
+ QmlExpressionPrivate::exceptionToError(sv.engine(), error);
+ qWarning().nospace() << qPrintable(error.toString());
+}
+
void QmlXMLHttpRequest::destroyNetwork()
{
if (m_network) {
diff --git a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp
index f952099..6e0d582 100644
--- a/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp
+++ b/tests/auto/declarative/xmlhttprequest/tst_xmlhttprequest.cpp
@@ -65,6 +65,7 @@ private slots:
void domExceptionCodes();
void callbackException();
+ void callbackException_data();
void staticStateValues();
void instanceStateValues();
void constructor();
@@ -167,15 +168,32 @@ void tst_xmlhttprequest::domExceptionCodes()
QVERIFY((expr)); \
} while (false)
+
+void tst_xmlhttprequest::callbackException_data()
+{
+ QTest::addColumn<QString>("which");
+ QTest::addColumn<int>("line");
+
+ QTest::newRow("on-opened") << "1" << 15;
+ QTest::newRow("on-loading") << "3" << 15;
+ QTest::newRow("on-done") << "4" << 15;
+}
+
void tst_xmlhttprequest::callbackException()
{
- QString expect = TEST_FILE("callbackException.qml").toString() + ":16: Error: Exception from Callback";
+ // Test exception reporting for exceptions thrown at various points.
+
+ QFETCH(QString, which);
+ QFETCH(int, line);
+
+ QString expect = TEST_FILE("callbackException.qml").toString() + ":"+QString::number(line)+": Error: Exception from Callback";
QTest::ignoreMessage(QtWarningMsg, expect.toLatin1());
QmlComponent component(&engine, TEST_FILE("callbackException.qml"));
QObject *object = component.beginCreate(engine.rootContext());
QVERIFY(object != 0);
object->setProperty("url", "testdocument.html");
+ object->setProperty("which", which);
component.completeCreate();
TRY_WAIT(object->property("threw").toBool() == true);