aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlboundsignal.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-25 11:40:18 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-31 17:08:19 +0000
commita05d1796b88e628655afdba6063a186d3a0803bf (patch)
treef264bc7c52c1f1d62563ac3cb6444fecc537a4d7 /src/qml/qml/qqmlboundsignal.cpp
parentc8f118d3a4ba53761d3dbc6e08b3454a2dae0a0a (diff)
Simplify signal handler parameter handling
Unify the two QQmlBoundSignalExpression constructors and always call updateInternalClass on the run-time function to set up the parameter name -> argument mapping. This streamlines the code, shares the error handling for unnamed parameter clashes and allows getting rid of the code to extend the formals of functions that become signal handlers in AOT generated cache files. Either onThatSignal: function(param1, param2) { ... } syntax is used and the mapping is fixed and known at AOT/compile time. Or alternatively the dynamic variant is used where the formals are determined at signal handler installation time. Saves a whopping KB of RAM on the QQC1 gallery. Change-Id: I33a9afc06474143d7893f42366cb6553a07ce937 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp48
1 files changed, 18 insertions, 30 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index d5117c8cec..3d67b45fe8 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -110,46 +110,34 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
m_index(index),
m_target(target)
{
- // If the function is marked as having a nested function, then the user wrote:
- // onSomeSignal: function() { /*....*/ }
- // So take that nested function:
- if (auto closure = function->nestedFunction())
- function = closure;
-
- setupFunction(scope, function);
+ // It's important to call init first, because m_index gets remapped in case of cloned signals.
init(ctxt, scopeObject);
-}
-QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, QV4::Function *runtimeFunction)
- : QQmlJavaScriptExpression(),
- m_index(index),
- m_target(target)
-{
- // It's important to call init first, because m_index gets remapped in case of cloned signals.
- init(ctxt, scope);
+ QV4::ExecutionEngine *engine = ctxt->engine->handle();
// If the function is marked as having a nested function, then the user wrote:
// onSomeSignal: function() { /*....*/ }
// So take that nested function:
- if (auto closure = runtimeFunction->nestedFunction())
- runtimeFunction = closure;
-
- QV4::ExecutionEngine *engine = ctxt->engine->handle();
-
- QList<QByteArray> signalParameters = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).parameterNames();
- if (!signalParameters.isEmpty()) {
- QString error;
- QQmlPropertyCache::signalParameterStringForJS(engine, signalParameters, &error);
- if (!error.isEmpty()) {
- qmlWarning(scopeObject()) << error;
- return;
+ if (auto closure = function->nestedFunction()) {
+ function = closure;
+ } else {
+ QList<QByteArray> signalParameters = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).parameterNames();
+ if (!signalParameters.isEmpty()) {
+ QString error;
+ QQmlPropertyCache::signalParameterStringForJS(engine, signalParameters, &error);
+ if (!error.isEmpty()) {
+ qmlWarning(scopeObject) << error;
+ return;
+ }
+ function->updateInternalClass(engine, signalParameters);
}
- runtimeFunction->updateInternalClass(engine, signalParameters);
}
QV4::Scope valueScope(engine);
- QV4::Scoped<QV4::QmlContext> qmlContext(valueScope, QV4::QmlContext::create(engine->rootContext(), ctxt, scope));
- setupFunction(qmlContext, runtimeFunction);
+ QV4::Scoped<QV4::QmlContext> qmlContext(valueScope, scope);
+ if (!qmlContext)
+ qmlContext = QV4::QmlContext::create(engine->rootContext(), ctxt, scopeObject);
+ setupFunction(qmlContext, function);
}
void QQmlBoundSignalExpression::init(QQmlContextData *ctxt, QObject *scope)