diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-10-21 09:57:58 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-29 10:38:59 +0100 |
commit | af22149dd8daf593182fec978f15dc1667c9cf8d (patch) | |
tree | 17334ae83a3015fd6ca535fb9d2e97b40e1da825 /src/qml/qml/v8 | |
parent | 2b996ca17fbc36029af3900933b6fcc1418afb6a (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/qml/v8')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 24 | ||||
-rw-r--r-- | src/qml/qml/v8/qv4domerrors_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 4 |
3 files changed, 14 insertions, 16 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index f9aca08d5a..047faabd1a 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1012,8 +1012,7 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx) if (component.isError()) { ScopedValue v(scope, Error::create(ctx->engine, component.errors())); - ctx->throwError(v); - return QV4::Encode::undefined(); + return ctx->throwError(v); } if (!component.isReady()) @@ -1037,8 +1036,7 @@ ReturnedValue QtObject::method_createQmlObject(SimpleCallContext *ctx) if (component.isError()) { ScopedValue v(scope, Error::create(ctx->engine, component.errors())); - ctx->throwError(v); - return QV4::Encode::undefined(); + return ctx->throwError(v); } Q_ASSERT(obj); @@ -1080,7 +1078,7 @@ use \l{QtQml::Qt::createQmlObject()}{Qt.createQmlObject()}. ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) { if (ctx->callData->argc < 1 || ctx->callData->argc > 3) - ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); + return ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); Scope scope(ctx); @@ -1108,13 +1106,13 @@ ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) if (ctx->callData->args[1].isInteger()) { int mode = ctx->callData->args[1].integerValue(); if (mode != int(QQmlComponent::PreferSynchronous) && mode != int(QQmlComponent::Asynchronous)) - ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); + return ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); compileMode = QQmlComponent::CompilationMode(mode); consumedCount += 1; } else { // The second argument could be the parent only if there are exactly two args if ((ctx->callData->argc != 2) || !(lastArg->isObject() || lastArg->isNull())) - ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); + return ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid arguments")); } if (consumedCount < ctx->callData->argc) { @@ -1123,11 +1121,11 @@ ReturnedValue QtObject::method_createComponent(SimpleCallContext *ctx) if (qobjectWrapper) parentArg = qobjectWrapper->object(); if (!parentArg) - ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); + return ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); } else if (lastArg->isNull()) { parentArg = 0; } else { - ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); + return ctx->throwError(QStringLiteral("Qt.createComponent(): Invalid parent object")); } } } @@ -1272,10 +1270,10 @@ ReturnedValue QtObject::method_get_platform(SimpleCallContext *ctx) // ### inefficient. Should be just a value based getter Object *o = ctx->callData->thisObject.asObject(); if (!o) - ctx->throwTypeError(); + return ctx->throwTypeError(); QtObject *qt = o->as<QtObject>(); if (!qt) - ctx->throwTypeError(); + return ctx->throwTypeError(); if (!qt->m_platform) // Only allocate a platform object once @@ -1289,10 +1287,10 @@ ReturnedValue QtObject::method_get_application(SimpleCallContext *ctx) // ### inefficient. Should be just a value based getter Object *o = ctx->callData->thisObject.asObject(); if (!o) - ctx->throwTypeError(); + return ctx->throwTypeError(); QtObject *qt = o->as<QtObject>(); if (!qt) - ctx->throwTypeError(); + return ctx->throwTypeError(); if (!qt->m_application) // Only allocate an application object once diff --git a/src/qml/qml/v8/qv4domerrors_p.h b/src/qml/qml/v8/qv4domerrors_p.h index 44662e8cba..faf52ce1ad 100644 --- a/src/qml/qml/v8/qv4domerrors_p.h +++ b/src/qml/qml/v8/qv4domerrors_p.h @@ -80,7 +80,7 @@ QT_BEGIN_NAMESPACE QV4::ScopedValue v(scope, ctx->engine->newString(QStringLiteral(string))); \ QV4::Scoped<Object> ex(scope, ctx->engine->newErrorObject(v)); \ ex->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, QV4::Primitive::fromInt32(error))); \ - ctx->throwError(ex); \ + return ctx->throwError(ex); \ } namespace QV4 { diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index a92d03ac50..e37b0d4920 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -86,10 +86,10 @@ namespace QV4 { // #define QML_GLOBAL_HANDLE_DEBUGGING #define V4THROW_ERROR(string) \ - ctx->throwError(QString::fromUtf8(string)); + return ctx->throwError(QString::fromUtf8(string)); #define V4THROW_TYPE(string) \ - ctx->throwTypeError(QStringLiteral(string)); + return ctx->throwTypeError(QStringLiteral(string)); #define V8_DEFINE_EXTENSION(dataclass, datafunction) \ static inline dataclass *datafunction(QV8Engine *engine) \ |