aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2018-03-20 09:44:30 -0500
committerMichael Brasser <michael.brasser@live.com>2018-03-21 13:07:30 +0000
commit21301c1dbb00f4a2cd991e520423ed039b297ffb (patch)
tree9798bda2358b379212f69ae67c42fbb7a769e18f
parentdc4d6293f9473c0f03c570430d08867d2d01c6e2 (diff)
Simplify handling of function expressions as signal handlers
Change-Id: I4bfa05b4619c248119c78d05e64270e6627f6065 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/imports/statemachine/signaltransition.cpp7
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp12
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp8
-rw-r--r--src/qml/types/qqmlconnections.cpp7
4 files changed, 12 insertions, 22 deletions
diff --git a/src/imports/statemachine/signaltransition.cpp b/src/imports/statemachine/signaltransition.cpp
index 0d35e3064b..ab625788bb 100644
--- a/src/imports/statemachine/signaltransition.cpp
+++ b/src/imports/statemachine/signaltransition.cpp
@@ -177,13 +177,6 @@ void SignalTransition::connectTriggered()
int signalIndex = QMetaObjectPrivate::signalIndex(metaMethod);
auto f = m_compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
-
- // If the function is marked as having a nested function, then the user wrote:
- // onSomeSignal: function() { /*....*/ }
- // So take that nested function:
- if (auto closure = f->nestedFunction())
- f = closure;
-
QQmlBoundSignalExpression *expression =
ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, ctxtdata, this, f)
: nullptr;
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 060706ac50..d5117c8cec 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -110,6 +110,12 @@ 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);
init(ctxt, scopeObject);
}
@@ -122,6 +128,12 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
// It's important to call init first, because m_index gets remapped in case of cloned signals.
init(ctxt, scope);
+ // 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();
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 7c36f59035..7051fb51da 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -879,14 +879,6 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *bindingProper
if (binding->type == QV4::CompiledData::Binding::Type_Script || binding->containsTranslations()) {
if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) {
QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
-
- // When a user writes the following:
- // onSignal: function() { doSomethingUsefull }
- // then do not run the binding that returns the closure, but run the closure
- // instead.
- if (auto closure = runtimeFunction->nestedFunction())
- runtimeFunction = closure;
-
int signalIndex = _propertyCache->methodIndexToSignalIndex(bindingProperty->coreIndex());
QQmlBoundSignal *bs = new QQmlBoundSignal(_bindingTarget, signalIndex, _scopeObject, engine);
QQmlBoundSignalExpression *expr = new QQmlBoundSignalExpression(_bindingTarget, signalIndex,
diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp
index d1a7aa9b6f..2ae3df6ebb 100644
--- a/src/qml/types/qqmlconnections.cpp
+++ b/src/qml/types/qqmlconnections.cpp
@@ -289,13 +289,6 @@ void QQmlConnections::connectSignals()
signal->setEnabled(d->enabled);
auto f = d->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
-
- // If the function is marked as having a nested function, then the user wrote:
- // onSomeSignal: function() { /*....*/ }
- // So take that nested function:
- if (auto closure = f->nestedFunction())
- f = closure;
-
QQmlBoundSignalExpression *expression =
ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, ctxtdata, this, f)
: nullptr;