aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmljavascriptexpression.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-05-23 22:56:38 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2013-05-24 12:39:34 +0200
commit1d62cefbaa23ef96fa4dc36d950cc2d9a2d4b5c3 (patch)
tree114eb77af818b37b05801498f9e4e3e4c482d7e1 /src/qml/qml/qqmljavascriptexpression.cpp
parentfa2d572d5d202b05ed1908ea1119a1995960ce1f (diff)
Add support for direct binding evaluation in QV4Script
This way there is no need to rewrite the binding expressions anymore, instead we can directly compile them into a binding function. Change-Id: I91a0c540d066976e363590fe9ccde6a81ee92b1d Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmljavascriptexpression.cpp')
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index b64035b66d..0e733cb1d2 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -306,7 +306,6 @@ void QQmlJavaScriptExpression::exceptionToError(const QV4::Exception &e, QQmlErr
error.setDescription(e.value().toQString());
}
-// Callee owns the persistent handle
QV4::PersistentValue
QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
const char *code, int codeLength,
@@ -316,7 +315,6 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
return evalFunction(ctxt, scope, QString::fromUtf8(code, codeLength), filename, line, qmlscope);
}
-// Callee owns the persistent handle
QV4::PersistentValue
QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
const QString &code, const QString &filename, quint16 line,
@@ -352,6 +350,41 @@ QQmlJavaScriptExpression::evalFunction(QQmlContextData *ctxt, QObject *scope,
return result;
}
+QV4::PersistentValue QQmlJavaScriptExpression::qmlBinding(QQmlContextData *ctxt, QObject *scope,
+ const QString &code, const QString &filename, quint16 line,
+ QV4::PersistentValue *qmlscope)
+{
+ QQmlEngine *engine = ctxt->engine;
+ QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
+
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine());
+ QV4::ExecutionContext *ctx = v4->current;
+
+ QV4::Value scopeObject = ep->v8engine()->qmlScope(ctxt, scope)->v4Value();
+ QV4::Script script(v4, scopeObject.asObject(), code, filename, line);
+ QV4::Value result;
+ try {
+ script.parse();
+ result = script.qmlBinding();
+ } catch (QV4::Exception &e) {
+ e.accept(ctx);
+ QQmlError error;
+ QQmlExpressionPrivate::exceptionToError(e, error);
+ if (error.description().isEmpty())
+ error.setDescription(QLatin1String("Exception occurred during function evaluation"));
+ if (error.line() == -1)
+ error.setLine(line);
+ if (error.url().isEmpty())
+ error.setUrl(QUrl::fromLocalFile(filename));
+ ep->warning(error);
+ return QV4::PersistentValue();
+ }
+ if (qmlscope)
+ *qmlscope = scopeObject;
+ return result;
+}
+
+
void QQmlJavaScriptExpression::clearGuards()
{
while (Guard *g = activeGuards.takeFirst())