aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/types
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-21 09:57:58 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 10:38:59 +0100
commitaf22149dd8daf593182fec978f15dc1667c9cf8d (patch)
tree17334ae83a3015fd6ca535fb9d2e97b40e1da825 /src/qml/types
parent2b996ca17fbc36029af3900933b6fcc1418afb6a (diff)
Avoid side effects when en exception has been thrown.
We don't want to check for exceptions after every single line on our runtime methods. A better way to handle this is to add the check in all methods that have direct side effects (as e.g. writing to a property of the JS stack). We also need to return whereever we throw an exception. To simplify the code, ExecutionContext::throwXxx methods now return a ReturnedValue (always undefined) for convenience. Change-Id: Ide6c804f819c731a3f14c6c43121d08029c9fb90 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/types')
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 10f957ab40..a1163f0a98 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -76,8 +76,7 @@ struct DelegateModelGroupFunction: QV4::FunctionObject
static QV4::ReturnedValue construct(QV4::Managed *m, QV4::CallData *)
{
- m->engine()->current->throwTypeError();
- return QV4::Primitive::undefinedValue().asReturnedValue();
+ return m->engine()->current->throwTypeError();
}
static QV4::ReturnedValue call(QV4::Managed *that, QV4::CallData *callData)
@@ -87,7 +86,7 @@ struct DelegateModelGroupFunction: QV4::FunctionObject
QV4::Scoped<DelegateModelGroupFunction> f(scope, that, QV4::Scoped<DelegateModelGroupFunction>::Cast);
QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject);
if (!o)
- v4->current->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return v4->current->throwTypeError(QStringLiteral("Not a valid VisualData object"));
QV4::ScopedValue v(scope, callData->argument(0));
return f->code(o->item, f->flag, v);
@@ -1711,7 +1710,7 @@ QV4::ReturnedValue QQmlDelegateModelItem::get_model(QV4::SimpleCallContext *ctx)
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->callData->thisObject.as<QQmlDelegateModelItemObject>());
if (!o)
- ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
if (!o->item->metaType->model)
return QV4::Encode::undefined();
@@ -1723,7 +1722,7 @@ QV4::ReturnedValue QQmlDelegateModelItem::get_groups(QV4::SimpleCallContext *ctx
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->callData->thisObject.as<QQmlDelegateModelItemObject>());
if (!o)
- ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
QStringList groups;
for (int i = 1; i < o->item->metaType->groupCount; ++i) {
@@ -1739,9 +1738,9 @@ QV4::ReturnedValue QQmlDelegateModelItem::set_groups(QV4::SimpleCallContext *ctx
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelItemObject> o(scope, ctx->callData->thisObject.as<QQmlDelegateModelItemObject>());
if (!o)
- ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
+ return ctx->throwTypeError(QStringLiteral("Not a valid VisualData object"));
if (!ctx->callData->argc)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
if (!o->item->metaType->model)
return QV4::Encode::undefined();
@@ -3153,21 +3152,21 @@ struct QQmlDelegateModelGroupChange : QV4::Object
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
return QV4::Encode(that->change.index);
}
static QV4::ReturnedValue method_get_count(QV4::SimpleCallContext *ctx) {
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
return QV4::Encode(that->change.count);
}
static QV4::ReturnedValue method_get_moveId(QV4::SimpleCallContext *ctx) {
QV4::Scope scope(ctx);
QV4::Scoped<QQmlDelegateModelGroupChange> that(scope, ctx->callData->thisObject.as<QQmlDelegateModelGroupChange>());
if (!that)
- ctx->throwTypeError();
+ return ctx->throwTypeError();
if (that->change.moveId < 0)
return QV4::Encode::undefined();
return QV4::Encode(that->change.moveId);
@@ -3199,7 +3198,7 @@ public:
QV4::Scope scope(v4);
QV4::Scoped<QQmlDelegateModelGroupChangeArray> array(scope, m->as<QQmlDelegateModelGroupChangeArray>());
if (!array)
- v4->current->throwTypeError();
+ return v4->current->throwTypeError();
if (index >= array->count()) {
if (hasProperty)
@@ -3223,7 +3222,7 @@ public:
{
QQmlDelegateModelGroupChangeArray *array = m->as<QQmlDelegateModelGroupChangeArray>();
if (!array)
- m->engine()->current->throwTypeError();
+ return m->engine()->current->throwTypeError();
if (name->equals(m->engine()->id_length)) {
if (hasProperty)