summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/scriptengine.cpp
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-04-03 15:02:00 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-04-04 11:09:07 +0200
commitea25dca5eae415c2a555865efe7176b07f7bf109 (patch)
tree36aa9a7cdd58bcc1564184d1ca101c0d25934224 /src/libs/installer/scriptengine.cpp
parent09c3bf53a53368642780b63de64cb8cfe73f0e17 (diff)
Fix strange error message.
Task-number: QTIFW-309 If a component script file is empty or misses the component class constructor, bail out during binary create or installer execution. Change-Id: I422c64186652a52122d54b5b042139803c24ba10 Reviewed-by: Niels Weber <niels.weber@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/libs/installer/scriptengine.cpp')
-rw-r--r--src/libs/installer/scriptengine.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp
index 87faa2cee..d46805ade 100644
--- a/src/libs/installer/scriptengine.cpp
+++ b/src/libs/installer/scriptengine.cpp
@@ -41,6 +41,7 @@
#include "scriptengine.h"
#include "component.h"
+#include "globals.h"
#include "packagemanagercore.h"
#include "messageboxhandler.h"
#include "errors.h"
@@ -248,16 +249,17 @@ QScriptValue ScriptEngine::loadInConext(const QString &context, const QString &f
fileName, file.errorString()));
}
- // create inside closure in one line to keep linenumber in the right order
- // which is used as a debug output in an exception case
- // scriptContent will be added as the last arg command to prevent wrong
- // replacements of %1, %2 or %3 inside the scriptContent
+ // Create a closure. Put the content in the first line to keep line number order in case of an
+ // exception. Script content will be added as the last argument to the command to prevent wrong
+ // replacements of %1, %2 or %3 inside the javascript code.
QString scriptContent = QString::fromLatin1(
- "(function() { %1 %3 ; return new %2; })();");
-
- // merging everything together and as last we are adding the file content to prevent wrong
- // replacements of %1 %2 or %3 inside the javascript code
- scriptContent = scriptContent.arg(scriptInjection, context, QLatin1String(file.readAll()));
+ "(function() {"
+ " %1 %3 ;"
+ " if (typeof %2 != \"undefined\")"
+ " return new %2;"
+ " else"
+ " throw \"Missing Component constructor. Please check your script.\";"
+ "})();").arg(scriptInjection, context, QLatin1String(file.readAll()));
QScriptValue scriptContext = evaluate(scriptContent, fileName);
if (hasUncaughtException()) {