From 39088b5cd4ee7f6d81d969f0f9d215e05ca43177 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 9 Mar 2010 22:18:45 +0000 Subject: [PATCH] make it possible to check for errors externally svn path=/trunk/KDE/kdebase/runtime/; revision=1101327 --- scriptengines/javascript/scriptenv.cpp | 20 +++++++++++--------- scriptengines/javascript/scriptenv.h | 4 +++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/scriptengines/javascript/scriptenv.cpp b/scriptengines/javascript/scriptenv.cpp index a5a759e71..1cc3d87e2 100644 --- a/scriptengines/javascript/scriptenv.cpp +++ b/scriptengines/javascript/scriptenv.cpp @@ -65,7 +65,7 @@ QScriptEngine *ScriptEnv::engine() const return m_engine; } -ScriptEnv *ScriptEnv::findScriptEnv( QScriptEngine *engine ) +ScriptEnv *ScriptEnv::findScriptEnv(QScriptEngine *engine) { QScriptValue global = engine->globalObject(); return qscriptvalue_cast(global.property("__plasma_scriptenv")); @@ -106,12 +106,17 @@ bool ScriptEnv::include(const QString &path) m_engine->evaluate(script, path); + return !checkForErrors(true); +} + +bool ScriptEnv::checkForErrors(bool fatal) +{ if (m_engine->hasUncaughtException()) { - emit reportError(this, true); - return false; + emit reportError(this, fatal); + return true; } - return true; + return false; } QScriptValue ScriptEnv::runApplication(QScriptContext *context, QScriptEngine *engine) @@ -272,8 +277,7 @@ bool ScriptEnv::importExtensions(const KPluginInfo &info, QScriptValue &obj, Aut } } - if (m_engine->hasUncaughtException()) { - emit reportError(this, true); + if (checkForErrors(true)) { return false; } else { m_extensions << extension; @@ -299,9 +303,7 @@ bool ScriptEnv::importExtensions(const KPluginInfo &info, QScriptValue &obj, Aut } } - if (m_engine->hasUncaughtException()) { - emit reportError(this, false); - } else { + if (!checkForErrors(false)) { m_extensions << extension; } } diff --git a/scriptengines/javascript/scriptenv.h b/scriptengines/javascript/scriptenv.h index 44fb39c8b..b52727986 100644 --- a/scriptengines/javascript/scriptenv.h +++ b/scriptengines/javascript/scriptenv.h @@ -44,7 +44,7 @@ public: QScriptEngine *engine() const; /** Returns the ScriptEnv in use for a given QScriptEngine or 0. */ - static ScriptEnv *findScriptEnv( QScriptEngine *engine ); + static ScriptEnv *findScriptEnv(QScriptEngine *engine); void registerEnums(QScriptValue &scriptValue, const QMetaObject &meta); bool include(const QString &path); @@ -52,6 +52,8 @@ public: bool importExtensions(const KPluginInfo &info, QScriptValue &obj, Authorization &authorizer); QSet loadedExtensions() const; + bool checkForErrors(bool fatal); + Q_SIGNALS: void reportError(ScriptEnv *engine, bool fatal);