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/imports | |
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/imports')
-rw-r--r-- | src/imports/localstorage/plugin.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp index 2b3ef34d4c..3202acc82b 100644 --- a/src/imports/localstorage/plugin.cpp +++ b/src/imports/localstorage/plugin.cpp @@ -68,11 +68,21 @@ using namespace QV4; QV4::Scoped<Object> ex(scope, ctx->engine->newErrorObject(v)); \ ex->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, Primitive::fromInt32(error))); \ ctx->throwError(ex); \ + return Encode::undefined(); \ +} + +#define V4THROW_SQL2(error, desc) { \ + QV4::Scoped<String> v(scope, ctx->engine->newString(desc)); \ + QV4::Scoped<Object> ex(scope, ctx->engine->newErrorObject(v)); \ + ex->put(QV4::ScopedString(scope, ctx->engine->newIdentifier(QStringLiteral("code"))), QV4::ScopedValue(scope, Primitive::fromInt32(error))); \ + args->setReturnValue(ctx->throwError(ex)); \ + return; \ } #define V4THROW_REFERENCE(string) { \ QV4::Scoped<String> v(scope, ctx->engine->newString(string)); \ ctx->throwReferenceError(v); \ + return Encode::undefined(); \ } @@ -168,7 +178,7 @@ static ReturnedValue qmlsqldatabase_rows_setForwardOnly(SimpleCallContext *ctx) if (!r || r->type != QQmlSqlDatabaseWrapper::Rows) V4THROW_REFERENCE("Not a SQLDatabase::Rows object"); if (ctx->callData->argc < 1) - ctx->throwTypeError(); + return ctx->throwTypeError(); r->sqlQuery.setForwardOnly(ctx->callData->args[0].toBoolean()); return Encode::undefined(); @@ -652,7 +662,7 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args) QV4::ExecutionContext *ctx = args->v4engine()->current; QV4::Scope scope(ctx); if (engine->engine()->offlineStoragePath().isEmpty()) - V4THROW_SQL(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("SQL: can't create database, offline storage is disabled.")); + V4THROW_SQL2(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("SQL: can't create database, offline storage is disabled.")); qmlsqldatabase_initDatabasesPath(engine); @@ -680,7 +690,7 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args) database = QSqlDatabase::database(dbid); version = ini.value(QLatin1String("Version")).toString(); if (version != dbversion && !dbversion.isEmpty() && !version.isEmpty()) - V4THROW_SQL(SQLEXCEPTION_VERSION_ERR, QQmlEngine::tr("SQL: database version mismatch")); + V4THROW_SQL2(SQLEXCEPTION_VERSION_ERR, QQmlEngine::tr("SQL: database version mismatch")); } else { created = !QFile::exists(basename+QLatin1String(".sqlite")); database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); @@ -695,7 +705,7 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args) } else { if (!dbversion.isEmpty() && ini.value(QLatin1String("Version")) != dbversion) { // Incompatible - V4THROW_SQL(SQLEXCEPTION_VERSION_ERR,QQmlEngine::tr("SQL: database version mismatch")); + V4THROW_SQL2(SQLEXCEPTION_VERSION_ERR,QQmlEngine::tr("SQL: database version mismatch")); } version = ini.value(QLatin1String("Version")).toString(); } |