From b7964e6c971abc4d3d36c7bcf4c6ab80553e1635 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 28 Apr 2015 17:06:29 +0200 Subject: [PATCH] ProjectExplorer: Replace QScriptEngine with QJSEngine Change-Id: Iccc14c2197a30a7e62b2d388d163d1f89a5d1e87 Reviewed-by: hjk Reviewed-by: Tobias Hunger --- .../customwizard/customwizardparameters.cpp | 6 +++--- .../customwizard/customwizardparameters.h | 4 ++-- .../customwizard/customwizardpreprocessor.cpp | 17 +++++++---------- .../customwizard/customwizardpreprocessor.h | 4 ++-- src/plugins/projectexplorer/projectexplorer.pro | 2 +- src/plugins/projectexplorer/projectexplorer.qbs | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp index 80ce3a40ba8..8169309ca4c 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -177,7 +177,7 @@ bool CustomWizardValidationRule::validateRules(const QListclear(); if (rules.isEmpty()) return true; - QScriptEngine engine; + QJSEngine engine; foreach (const CustomWizardValidationRule &rule, rules) if (!rule.validate(engine, replacementMap)) { *errorMessage = rule.message; @@ -187,7 +187,7 @@ bool CustomWizardValidationRule::validateRules(const QList &replacementMap) const +bool CustomWizardValidationRule::validate(QJSEngine &engine, const QMap &replacementMap) const { // Apply parameters and evaluate using JavaScript QString cond = condition; diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h index 38b9bc6b45f..a7ef449787c 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h +++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h @@ -41,7 +41,7 @@ QT_BEGIN_NAMESPACE class QIODevice; class QDebug; class QTemporaryFile; -class QScriptEngine; +class QJSEngine; QT_END_NAMESPACE namespace ProjectExplorer { @@ -82,7 +82,7 @@ public: static bool validateRules(const QList &rules, const QMap &replacementMap, QString *errorMessage); - bool validate(QScriptEngine &, const QMap &replacementMap) const; + bool validate(QJSEngine &, const QMap &replacementMap) const; QString condition; QString message; }; diff --git a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp index fe793327fa8..e2493707d53 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp +++ b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.cpp @@ -40,9 +40,7 @@ #include #include #include - -#include -#include +#include namespace ProjectExplorer { namespace Internal { @@ -94,7 +92,7 @@ private: mutable QRegExp m_endifPattern; QStack m_sectionStack; - QScriptEngine m_scriptEngine; + QJSEngine m_scriptEngine; }; PreprocessContext::PreprocessContext() : @@ -137,16 +135,15 @@ PreprocessorSection PreprocessContext::preprocessorLine(const QString &in, return OtherSection; } -// Evaluate an expression within an 'if'/'elsif' to a bool via QScript -bool evaluateBooleanJavaScriptExpression(QScriptEngine &engine, const QString &expression, bool *result, QString *errorMessage) +// Evaluate an expression within an 'if'/'elsif' to a bool via QJSEngine +bool evaluateBooleanJavaScriptExpression(QJSEngine &engine, const QString &expression, bool *result, QString *errorMessage) { errorMessage->clear(); *result = false; - engine.clearExceptions(); - const QScriptValue value = engine.evaluate(expression); - if (engine.hasUncaughtException()) { + const QJSValue value = engine.evaluate(expression); + if (value.isError()) { *errorMessage = QString::fromLatin1("Error in \"%1\": %2"). - arg(expression, engine.uncaughtException().toString()); + arg(expression, value.toString()); return false; } // Try to convert to bool, be that an int or whatever. diff --git a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.h b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.h index 4922e5331ef..66af67609fc 100644 --- a/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.h +++ b/src/plugins/projectexplorer/customwizard/customwizardpreprocessor.h @@ -33,14 +33,14 @@ #include -QT_FORWARD_DECLARE_CLASS(QScriptEngine) +QT_FORWARD_DECLARE_CLASS(QJSEngine) namespace ProjectExplorer { namespace Internal { bool customWizardPreprocess(const QString &in, QString *out, QString *errorMessage); /* Helper to evaluate an expression. */ -bool evaluateBooleanJavaScriptExpression(QScriptEngine &engine, const QString &expression, bool *result, QString *errorMessage); +bool evaluateBooleanJavaScriptExpression(QJSEngine &engine, const QString &expression, bool *result, QString *errorMessage); } // namespace Internal } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro index 5ec192639ed..f242579c0bc 100644 --- a/src/plugins/projectexplorer/projectexplorer.pro +++ b/src/plugins/projectexplorer/projectexplorer.pro @@ -1,4 +1,4 @@ -QT += quick script +QT += quick qml include(../../qtcreatorplugin.pri) include(customwizard/customwizard.pri) diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 16af429c429..e319a1de0ad 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -3,7 +3,7 @@ import qbs 1.0 QtcPlugin { name: "ProjectExplorer" - Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "script"] } + Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "qml"] } Depends { name: "Qt.quick" } Depends { name: "Aggregation" } Depends { name: "QtcSsh" }