aboutsummaryrefslogtreecommitdiffstats
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
parentffcdbfa03f8bb36b521f8c1a703ee24085fe25bd (diff)
Fix the remaining try/catch statements in C++
Change-Id: I2421dc48fb271b66bd476fb16a32a88fcc4c5177 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/jsruntime/qv4include.cpp12
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp5
-rw-r--r--src/qml/jsruntime/qv4serialize.cpp8
-rw-r--r--src/qml/jsruntime/qv4value.cpp20
-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
-rw-r--r--src/qml/types/qquickworkerscript.cpp25
9 files changed, 97 insertions, 101 deletions
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp
index 355817ef3e..40f7b865d0 100644
--- a/src/qml/jsruntime/qv4include.cpp
+++ b/src/qml/jsruntime/qv4include.cpp
@@ -109,14 +109,12 @@ void QV4Include::callback(const QV4::ValueRef callback, const QV4::ValueRef stat
return;
QV4::ExecutionContext *ctx = v4->current;
- try {
- QV4::ScopedCallData callData(scope, 1);
- callData->thisObject = v4->globalObject->asReturnedValue();
- callData->args[0] = status;
- f->call(callData);
- } catch (...) {
+ QV4::ScopedCallData callData(scope, 1);
+ callData->thisObject = v4->globalObject->asReturnedValue();
+ callData->args[0] = status;
+ f->call(callData);
+ if (scope.hasException())
ctx->catchException();
- }
}
QV4::ReturnedValue QV4Include::result()
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index acdfc1ba52..a4bfc93c36 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -727,9 +727,8 @@ struct QObjectSlotDispatcher : public QtPrivate::QSlotObjectBase
}
}
- try {
- f->call(callData);
- } catch (...) {
+ f->call(callData);
+ if (scope.hasException()) {
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
if (error.description().isEmpty())
error.setDescription(QString(QLatin1String("Unknown exception occurred during evaluation of connected function: %1")).arg(f->name->toQString()));
diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp
index 53d7e4701a..88e7630055 100644
--- a/src/qml/jsruntime/qv4serialize.cpp
+++ b/src/qml/jsruntime/qv4serialize.cpp
@@ -280,12 +280,10 @@ void Serialize::serialize(QByteArray &data, const QV4::ValueRef v, QV8Engine *en
serialize(data, s, engine);
QV4::ExecutionContext *ctx = v4->current;
- try {
- str = s;
- val = o->get(str);
- } catch (...) {
+ str = s;
+ val = o->get(str);
+ if (scope.hasException())
ctx->catchException();
- }
serialize(data, val, engine);
}
diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp
index ebd1894016..a7413e031c 100644
--- a/src/qml/jsruntime/qv4value.cpp
+++ b/src/qml/jsruntime/qv4value.cpp
@@ -125,22 +125,20 @@ QString Value::toQStringNoThrow() const
Scope scope(ctx);
ScopedValue ex(scope);
bool caughtException = false;
- try {
- ScopedValue prim(scope, __qmljs_to_primitive(ValueRef::fromRawValue(this), STRING_HINT));
- if (prim->isPrimitive())
- return prim->toQStringNoThrow();
- } catch (...) {
+ ScopedValue prim(scope, __qmljs_to_primitive(ValueRef::fromRawValue(this), STRING_HINT));
+ if (scope.hasException()) {
ex = ctx->catchException();
caughtException = true;
+ } else if (prim->isPrimitive()) {
+ return prim->toQStringNoThrow();
}
// Can't nest try/catch due to CXX ABI limitations for foreign exception nesting.
if (caughtException) {
- try {
- ScopedValue prim(scope, __qmljs_to_primitive(ex, STRING_HINT));
- if (prim->isPrimitive())
- return prim->toQStringNoThrow();
- } catch(...) {
- ctx->catchException();
+ ScopedValue prim(scope, __qmljs_to_primitive(ex, STRING_HINT));
+ if (scope.hasException()) {
+ ex = ctx->catchException();
+ } else if (prim->isPrimitive()) {
+ return prim->toQStringNoThrow();
}
}
return QString();
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);
}
diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp
index c0f6c737b2..78dbeb9d4f 100644
--- a/src/qml/types/qquickworkerscript.cpp
+++ b/src/qml/types/qquickworkerscript.cpp
@@ -255,14 +255,12 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(i
QV4::ExecutionContext *ctx = v4->current;
QV4::ScopedValue v(scope);
- try {
- QV4::ScopedCallData callData(scope, 1);
- callData->args[0] = QV4::Primitive::fromInt32(id);
- callData->thisObject = global();
- v = f->call(callData);
- } catch (...) {
+ QV4::ScopedCallData callData(scope, 1);
+ callData->args[0] = QV4::Primitive::fromInt32(id);
+ callData->thisObject = global();
+ v = f->call(callData);
+ if (scope.hasException())
v = ctx->catchException();
- }
return v.asReturnedValue();
}
@@ -362,13 +360,12 @@ void QQuickWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &d
QV4::ScopedValue value(scope, QV4::Serialize::deserialize(data, workerEngine));
- try {
- QV4::ScopedCallData callData(scope, 2);
- callData->thisObject = workerEngine->global();
- callData->args[0] = script->object.value();
- callData->args[1] = value;
- f->call(callData);
- } catch (...) {
+ QV4::ScopedCallData callData(scope, 2);
+ callData->thisObject = workerEngine->global();
+ callData->args[0] = script->object.value();
+ callData->args[1] = value;
+ f->call(callData);
+ if (scope.hasException()) {
QQmlError error = QV4::ExecutionEngine::catchExceptionAsQmlError(ctx);
reportScriptException(script, error);
}