Commit fb9cea18 authored by Alessandro Portale's avatar Alessandro Portale Committed by Tobias Hunger
Browse files

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: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 0a294eeb
......@@ -33,7 +33,6 @@
#include <utils/stringutils.h>
#include <QScriptEngine>
#include <QSet>
namespace Core {
......
......@@ -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
......
......@@ -37,7 +37,7 @@
#include <QCoreApplication>
#include <QDebug>
#include <QScriptEngine>
#include <QJSEngine>
namespace Core {
......@@ -45,10 +45,7 @@ namespace Internal {
class JsExpanderPrivate {
public:
~JsExpanderPrivate() { qDeleteAll(m_registeredObjects); }
QScriptEngine m_engine;
QList<QObject *> 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())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment