From fb9cea18a8bb363b958e74981e264962c77d3b7c Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Tue, 31 Mar 2015 17:39:09 +0200 Subject: [PATCH] Core: Replace usage of QScriptEngine with QJSEngine This replaces the dependency of Core on QtScript with the dependency on QtQml. Changes: QJSEngine manages the onwership of injected QObjects. The Exception information is part of QJSValue instead of the engine. Change-Id: I54e40a7f2f7795424c4f3e37d962ac59fc2b1a09 Reviewed-by: Tobias Hunger --- src/plugins/coreplugin/corejsextensions.h | 1 - src/plugins/coreplugin/coreplugin.pro | 2 +- src/plugins/coreplugin/jsexpander.cpp | 20 +++++++------------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/plugins/coreplugin/corejsextensions.h b/src/plugins/coreplugin/corejsextensions.h index 7e88589bf52..4a061b5dcb1 100644 --- a/src/plugins/coreplugin/corejsextensions.h +++ b/src/plugins/coreplugin/corejsextensions.h @@ -33,7 +33,6 @@ #include -#include #include namespace Core { diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index a868a4c2cc0..01078d3c748 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -2,7 +2,7 @@ DEFINES += CORE_LIBRARY QT += help \ network \ printsupport \ - script \ + qml \ sql # embedding build time information prevents repeatedly binary exact versions from same source code diff --git a/src/plugins/coreplugin/jsexpander.cpp b/src/plugins/coreplugin/jsexpander.cpp index a1d733df772..10db6a8c8b7 100644 --- a/src/plugins/coreplugin/jsexpander.cpp +++ b/src/plugins/coreplugin/jsexpander.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include namespace Core { @@ -45,10 +45,7 @@ namespace Internal { class JsExpanderPrivate { public: - ~JsExpanderPrivate() { qDeleteAll(m_registeredObjects); } - - QScriptEngine m_engine; - QList m_registeredObjects; + QJSEngine m_engine; }; } // namespace Internal @@ -57,26 +54,23 @@ static Internal::JsExpanderPrivate *d; void JsExpander::registerQObjectForJs(const QString &name, QObject *obj) { - obj->setParent(0); // take ownership! - d->m_registeredObjects.append(obj); - QScriptValue jsObj = d->m_engine.newQObject(obj, QScriptEngine::QtOwnership); + QJSValue jsObj = d->m_engine.newQObject(obj); d->m_engine.globalObject().setProperty(name, jsObj); } QString JsExpander::evaluate(const QString &expression, QString *errorMessage) { - d->m_engine.clearExceptions(); - QScriptValue value = d->m_engine.evaluate(expression); - if (d->m_engine.hasUncaughtException()) { + QJSValue value = d->m_engine.evaluate(expression); + if (value.isError()) { const QString msg = QCoreApplication::translate("Core::JsExpander", "Error in \"%1\": %2") - .arg(expression, d->m_engine.uncaughtException().toString()); + .arg(expression, value.toString()); if (errorMessage) *errorMessage = msg; return QString(); } // Try to convert to bool, be that an int or whatever. if (value.isBool()) - return value.toBool() ? QStringLiteral("true") : QStringLiteral("false"); + return value.toString(); if (value.isNumber()) return QString::number(value.toNumber()); if (value.isString())