diff options
author | Tim Jenssen <tim.jenssen@digia.com> | 2013-05-29 15:21:59 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@digia.com> | 2013-06-03 16:35:28 +0200 |
commit | dfbb731676e59b42f548dfca15e60f08cfcdc2f5 (patch) | |
tree | 99f790422f6e1fe6af404dfe78c082fa5656eb70 /src | |
parent | c2cfa6dd833f60d75cc7aafe7282d052cdae5257 (diff) |
add exceptionhandler code for connected signals/JS methods
- there wasn't any error information if a C++ triggered signal resulted
in a JS method which has an error, now it will create an exception for it
- creating messagebox inside the lib is something what we want to avoid,
so the developer itself is responsible to catch these exceptions
- most cases of the installer code does that already
Change-Id: I07486f73be9de13a486de235f14e3a7d7b54f5b1
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 8 | ||||
-rw-r--r-- | src/libs/installer/scriptengine.h | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 6178f467f..9ff8ae75e 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -209,6 +209,8 @@ ScriptEngine::ScriptEngine(PackageManagerCore *core) globalObject().property(QLatin1String("installer")) .setProperty(QLatin1String("components"), scriptComponentsObject); + + connect(this, SIGNAL(signalHandlerException(QScriptValue)), SLOT(handleException(QScriptValue))); } ScriptEngine::~ScriptEngine() @@ -279,6 +281,12 @@ QScriptValue ScriptEngine::loadInConext(const QString &context, const QString &f return scriptContext; } +void ScriptEngine::handleException(const QScriptValue &value) +{ + if (!value.engine()) + return; + throw Error(uncaughtExceptionString(this, tr("Fatal error while evaluating a script."))); +} /*! Tries to call the method with \a name within the script and returns the result. If the method diff --git a/src/libs/installer/scriptengine.h b/src/libs/installer/scriptengine.h index 9c7d84fcf..50c50539b 100644 --- a/src/libs/installer/scriptengine.h +++ b/src/libs/installer/scriptengine.h @@ -71,11 +71,12 @@ public: explicit ScriptEngine(PackageManagerCore *core); ~ScriptEngine(); void setGuiQObject(QObject *guiQObject); - QScriptValue callScriptMethod(const QScriptValue &scriptContext, const QString &name, - const QScriptValueList ¶meters = QScriptValueList()) const; + QScriptValue callScriptMethod(const QScriptValue &scriptContext, const QString &methodName, + const QScriptValueList &arguments = QScriptValueList()) const; QScriptValue loadInConext(const QString &context, const QString &fileName, const QString &scriptInjection = QString()); - +private slots: + void handleException(const QScriptValue &value); private: QScriptValue generateMessageBoxObject(); QScriptValue generateDesktopServicesObject(); |