summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlcompileddata.cpp2
-rw-r--r--src/declarative/qml/qmlcompiler.cpp3
-rw-r--r--src/declarative/qml/qmlcompiler_p.h6
-rw-r--r--src/declarative/qml/qmlexpression.cpp21
4 files changed, 28 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlcompileddata.cpp b/src/declarative/qml/qmlcompileddata.cpp
index b2e2d40..a46d893 100644
--- a/src/declarative/qml/qmlcompileddata.cpp
+++ b/src/declarative/qml/qmlcompileddata.cpp
@@ -159,6 +159,8 @@ QmlCompiledData::~QmlCompiledData()
if (types.at(ii).ref)
types.at(ii).ref->release();
}
+
+ qDeleteAll(programs);
}
QObject *QmlCompiledData::TypeReference::createInstance(QmlContext *ctxt, const QBitField &bindings) const
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 02cd813..e67f79a 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -2296,7 +2296,10 @@ bool QmlCompiler::completeComponentBuild()
expression = rewriteBinding(expression);
quint32 length = expression.length();
+ quint32 pc = output->programs.length();
+ output->programs.append(0);
binding.compiledData =
+ QByteArray((const char *)&pc, sizeof(quint32)) +
QByteArray((const char *)&length, sizeof(quint32)) +
QByteArray((const char *)expression.constData(),
expression.length() * sizeof(QChar));
diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h
index 00637e3..447c421 100644
--- a/src/declarative/qml/qmlcompiler_p.h
+++ b/src/declarative/qml/qmlcompiler_p.h
@@ -69,6 +69,7 @@ class QmlEngine;
class QmlComponent;
class QmlContext;
+class QScriptProgram;
class QmlCompiledData : public QmlRefCount
{
public:
@@ -106,6 +107,7 @@ public:
QList<QByteArray> datas;
QList<QmlParser::Location> locations;
QList<QmlInstruction> bytecode;
+ QList<QScriptProgram *> programs;
void dumpInstructions();
private:
@@ -253,12 +255,10 @@ private:
struct ComponentCompileState
{
ComponentCompileState()
- : parserStatusCount(0), savedObjects(0),
- pushedProperties(0), root(0) {}
+ : parserStatusCount(0), pushedProperties(0), root(0) {}
QHash<QString, QmlParser::Object *> ids;
QHash<int, QmlParser::Object *> idIndexes;
int parserStatusCount;
- int savedObjects;
int pushedProperties;
QHash<QmlParser::Value *, BindingReference> bindings;
diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp
index db9d39f..adf5261 100644
--- a/src/declarative/qml/qmlexpression.cpp
+++ b/src/declarative/qml/qmlexpression.cpp
@@ -45,6 +45,7 @@
#include "qmlcontext_p.h"
#include "qmlrewrite_p.h"
#include "QtCore/qdebug.h"
+#include "qmlcompiler_p.h"
Q_DECLARE_METATYPE(QList<QObject *>);
@@ -74,8 +75,26 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc,
if (*data == BasicScriptEngineData) {
sse.load((const char *)(data + 1), rc);
} else {
- expression = QString::fromRawData((QChar *)(data + 2), data[1]);
+ QmlCompiledData *dd = (QmlCompiledData *)rc;
+
expressionRewritten = true;
+ expression = QString::fromRawData((QChar *)(data + 3), data[2]);
+
+ int progIdx = *(data + 1);
+ QmlEngine *engine = ctxt->engine();
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
+ if (!dd->programs.at(progIdx)) {
+ dd->programs[progIdx] = new QScriptProgram(scriptEngine->compile(expression));
+ }
+
+ QmlContextPrivate *ctxtPriv = ctxt->d_func();
+ QScriptContext *scriptContext = scriptEngine->pushContext();
+ for (int i = ctxtPriv->scopeChain.size() - 1; i > -1; --i)
+ scriptContext->pushScope(ctxtPriv->scopeChain.at(i));
+
+ expressionFunction = scriptEngine->evaluate(*dd->programs[progIdx]);
+ expressionFunctionValid = true;
+ scriptEngine->popContext();
}
QmlAbstractExpression::setContext(ctxt);