aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-22 14:32:03 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 10:39:04 +0100
commit25fbdfc66fa995bfe633b3c31d635045f7cf66dd (patch)
tree3264a851680476ebb7f161d5a38dcff3182a0e8a /src/qml/qml
parentffcdbfa03f8bb36b521f8c1a703ee24085fe25bd (diff)
Fix the remaining try/catch statements in C++
Change-Id: I2421dc48fb271b66bd476fb16a32a88fcc4c5177 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmlcomponent.cpp12
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp29
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp8
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp79
4 files changed, 67 insertions, 61 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index 01e87537f5..883237130b 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -1567,12 +1567,12 @@ void QmlIncubatorObject::statusChanged(QQmlIncubator::Status s)
QV4::ScopedFunctionObject f(scope, m_statusChanged);
if (f) {
QV4::ExecutionContext *ctx = scope.engine->current;
- try {
- QV4::ScopedCallData callData(scope, 1);
- callData->thisObject = this;
- callData->args[0] = QV4::Primitive::fromUInt32(s);
- f->call(callData);
- } catch (...) {
+ QV4::ScopedCallData callData(scope, 1);
+ callData->thisObject = this;
+ callData->args[0] = QV4::Primitive::fromUInt32(s);
+ f->call(callData);
+ if (scope.hasException()) {
+ ctx->catchException();
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
QQmlEnginePrivate::warning(QQmlEnginePrivate::get(v8->engine()), error);
}
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index d115268ab0..79b7aa2e7a 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -159,28 +159,27 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
QV4::Scope scope(v4);
QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue());
QV4::ExecutionContext *ctx = v4->current;
- try {
- callData->thisObject = ep->v8engine()->global();
- if (scopeObject() && requiresThisObject()) {
- QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->engine, scopeObject()));
- if (value->isObject())
- callData->thisObject = value;
- }
-
- result = function->asFunctionObject()->call(callData);
-
- if (isUndefined)
- *isUndefined = result->isUndefined();
+ callData->thisObject = ep->v8engine()->global();
+ if (scopeObject() && requiresThisObject()) {
+ QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->engine, scopeObject()));
+ if (value->isObject())
+ callData->thisObject = value;
+ }
- if (!watcher.wasDeleted() && hasDelayedError())
- delayedError()->clearError();
- } catch (...) {
+ result = function->asFunctionObject()->call(callData);
+ if (scope.hasException()) {
if (watcher.wasDeleted())
ctx->catchException(); // ignore exception
else
delayedError()->catchJavaScriptException(ctx);
if (isUndefined)
*isUndefined = true;
+ } else {
+ if (isUndefined)
+ *isUndefined = result->isUndefined();
+
+ if (!watcher.wasDeleted() && hasDelayedError())
+ delayedError()->clearError();
}
if (capture.errorString) {
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index 4b141b5594..44b3b7d276 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -956,14 +956,14 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
QV4::ScopedValue result(scope);
QV4::ExecutionContext *ctx = function->engine()->current;
- try {
- result = function->call(callData);
- if (a[0]) *(QVariant *)a[0] = ep->v8engine()->toVariant(result, 0);
- } catch (...) {
+ result = function->call(callData);
+ if (scope.hasException()) {
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
if (error.isValid())
ep->warning(error);
if (a[0]) *(QVariant *)a[0] = QVariant();
+ } else {
+ if (a[0]) *(QVariant *)a[0] = ep->v8engine()->toVariant(result, 0);
}
ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete.
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index e0666a1a57..541c188d13 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -1108,6 +1108,7 @@ private:
void setMe(const ValueRef me);
PersistentValue m_me;
+ void dispatchCallbackImpl(const ValueRef me);
void dispatchCallback(const ValueRef me);
int m_status;
@@ -1534,50 +1535,56 @@ const QByteArray &QQmlXMLHttpRequest::rawResponseBody() const
return m_responseEntityBody;
}
-void QQmlXMLHttpRequest::dispatchCallback(const ValueRef me)
+void QQmlXMLHttpRequest::dispatchCallbackImpl(const ValueRef me)
{
ExecutionContext *ctx = v4->current;
QV4::Scope scope(v4);
- try {
- Scoped<Object> o(scope, me);
- if (!o) {
- ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
- return;
- }
+ Scoped<Object> o(scope, me);
+ if (!o) {
+ ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
+ return;
+ }
- ScopedString s(scope, v4->newString(QStringLiteral("ThisObject")));
- Scoped<Object> thisObj(scope, o->get(s));
- if (!thisObj) {
- ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
- return;
- }
+ ScopedString s(scope, v4->newString(QStringLiteral("ThisObject")));
+ Scoped<Object> thisObj(scope, o->get(s));
+ if (!thisObj) {
+ ctx->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
+ return;
+ }
- s = v4->newString(QStringLiteral("onreadystatechange"));
- Scoped<FunctionObject> callback(scope, thisObj->get(s));
- if (!callback) {
- // not an error, but no onreadystatechange function to call.
- return;
- }
+ s = v4->newString(QStringLiteral("onreadystatechange"));
+ Scoped<FunctionObject> callback(scope, thisObj->get(s));
+ if (!callback) {
+ // not an error, but no onreadystatechange function to call.
+ return;
+ }
- s = v4->newString(QStringLiteral("ActivationObject"));
- Scoped<Object> activationObject(scope, o->get(s));
- if (!activationObject) {
- v4->current->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject"));
- return;
- }
+ s = v4->newString(QStringLiteral("ActivationObject"));
+ Scoped<Object> activationObject(scope, o->get(s));
+ if (!activationObject) {
+ v4->current->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject"));
+ return;
+ }
- QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject);
- if (callingContext) {
- QV4::ScopedCallData callData(scope, 0);
- callData->thisObject = activationObject.asReturnedValue();
- callback->call(callData);
- }
+ QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject);
+ if (callingContext) {
+ QV4::ScopedCallData callData(scope, 0);
+ callData->thisObject = activationObject.asReturnedValue();
+ callback->call(callData);
+ }
+
+ // if the callingContext object is no longer valid, then it has been
+ // deleted explicitly (e.g., by a Loader deleting the itemContext when
+ // the source is changed). We do nothing in this case, as the evaluation
+ // cannot succeed.
+
+}
- // if the callingContext object is no longer valid, then it has been
- // deleted explicitly (e.g., by a Loader deleting the itemContext when
- // the source is changed). We do nothing in this case, as the evaluation
- // cannot succeed.
- } catch (...) {
+void QQmlXMLHttpRequest::dispatchCallback(const ValueRef me)
+{
+ ExecutionContext *ctx = v4->current;
+ dispatchCallbackImpl(me);
+ if (v4->hasException) {
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
QQmlEnginePrivate::warning(QQmlEnginePrivate::get(v4->v8Engine->engine()), error);
}