diff options
author | Simon Hausmann <[email protected]> | 2014-03-31 16:49:14 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-04-02 14:04:11 +0200 |
commit | 4e012093462f07e7ffd42d4061539c54b4f43ace (patch) | |
tree | 5a90968cf1a57860af3a870d5a0d2c0619629bb6 /src/qml/jsruntime | |
parent | 010e3e4f8d4045d3e807d612289886f3d709773c (diff) |
Avoid recompiling of signal handlers defined in QtQuick state changes and Connection objects
We can re-use the expression we've compiled at QML type compilation time, as
long as we "inject" the signal parameters in the dynamic qml lookup chain.
Change-Id: Icc417531c41dea06ff5d033011179af49b03f542
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 25 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script_p.h | 2 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index e489b99ec5..a25d969059 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -132,11 +132,34 @@ void QmlBindingWrapper::markObjects(Managed *m, ExecutionEngine *e) wrapper->qmlContext->mark(e); } -Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(ExecutionEngine *engine, QQmlContextData *qmlContext, QObject *scopeObject, Function *runtimeFunction) +static ReturnedValue signalParameterGetter(QV4::CallContext *ctx, uint parameterIndex) { + QV4::CallContext *signalEmittingContext = ctx->parent->asCallContext(); + Q_ASSERT(signalEmittingContext); + return signalEmittingContext->argument(parameterIndex); +} + +Returned<FunctionObject> *QmlBindingWrapper::createQmlCallableForFunction(QQmlContextData *qmlContext, QObject *scopeObject, Function *runtimeFunction, const QList<QByteArray> &signalParameters, QString *error) +{ + ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(qmlContext->engine); QV4::Scope valueScope(engine); QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine->v8Engine, qmlContext, scopeObject)); QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, new (engine->memoryManager) QV4::QmlBindingWrapper(engine->rootContext, qmlScopeObject)); + + if (!signalParameters.isEmpty()) { + if (error) + QQmlPropertyCache::signalParameterStringForJS(qmlContext->engine, signalParameters, error); + QV4::ScopedProperty p(valueScope); + QV4::ScopedString s(valueScope); + int index = 0; + foreach (const QByteArray ¶m, signalParameters) { + p->setGetter(new (engine->memoryManager) QV4::IndexedBuiltinFunction(wrapper->context(), index++, signalParameterGetter)); + p->setSetter(0); + s = engine->newString(QString::fromUtf8(param)); + qmlScopeObject->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable); + } + } + QV4::ScopedFunctionObject function(valueScope, QV4::FunctionObject::createScriptFunction(wrapper->context(), runtimeFunction)); return function->asReturned<FunctionObject>(); } diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 0165778f4b..de582f9674 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -67,7 +67,7 @@ struct QmlBindingWrapper : FunctionObject { CallContext *context() const { return qmlContext; } - static Returned<FunctionObject> *createQmlCallableForFunction(QV4::ExecutionEngine *engine, QQmlContextData *qmlContext, QObject *scopeObject, QV4::Function *runtimeFunction); + static Returned<FunctionObject> *createQmlCallableForFunction(QQmlContextData *qmlContext, QObject *scopeObject, QV4::Function *runtimeFunction, const QList<QByteArray> &signalParameters = QList<QByteArray>(), QString *error = 0); private: Object *qml; |