aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlboundsignal.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-07-03 16:44:55 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-07-05 09:47:01 +0200
commitfe6ec7bcc17f88ab1aca5a7934d047456354c942 (patch)
tree61e722685a2bb6596a3eaa9f00526a5271f9cc68 /src/qml/qml/qqmlboundsignal.cpp
parenta083ea8a34cad4feebcdadea33775ef6501ab884 (diff)
Fix regression in tst_qqmlecmascript::signalAssignment
Detect errors in the signal declaration already at compile time, re-introducing the earlier code in qqmlcompiler.cpp that checked that. This also means that the parameter string construction can be done once for each signal and not for each handler. Change-Id: Icf6242a793939466bbc44d43bf041281164ad1b6 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 80a06e9761..0c922294b4 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -69,7 +69,8 @@ static QQmlJavaScriptExpression::VTable QQmlBoundSignalExpression_jsvtable = {
QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
QQmlContextData *ctxt, QObject *scope, const QString &expression,
const QString &fileName, quint16 line, quint16 column,
- const QString &handlerName)
+ const QString &handlerName,
+ const QString &parameterString)
: QQmlJavaScriptExpression(&QQmlBoundSignalExpression_jsvtable),
m_fileName(fileName),
m_line(line),
@@ -81,6 +82,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
{
init(ctxt, scope);
m_handlerName = handlerName;
+ m_parameterString = parameterString;
m_expression = expression;
}
@@ -133,50 +135,35 @@ void QQmlBoundSignalExpression::evaluate(void **a)
ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation.
{
if (!m_expressionFunctionValid) {
-
- //TODO: look at using the property cache here (as in the compiler)
- // for further optimization
- QMetaMethod signal = QMetaObjectPrivate::signal(m_target->metaObject(), m_index);
-
QString expression;
expression = QStringLiteral("(function ");
expression += m_handlerName;
expression += QLatin1Char('(');
- QString error;
-
- bool unnamedParameter = false;
- const QV4::IdentifierHash<bool> &illegalNames = ep->v8engine()->illegalNames();
-
- const QList<QByteArray> parameters = signal.parameterNames();
- for (int i = 0; i < parameters.count(); ++i) {
- if (i > 0)
- expression += QLatin1Char(',');
- const QByteArray &param = parameters.at(i);
- if (param.isEmpty())
- unnamedParameter = true;
- else if (unnamedParameter) {
- error = QCoreApplication::translate("QQmlRewrite", "Signal uses unnamed parameter followed by named parameter.");
- break;
- } else if (illegalNames.contains(param)) {
- error = QCoreApplication::translate("QQmlRewrite", "Signal parameter \"%1\" hides global variable.").arg(QString::fromUtf8(param));
- break;
+ if (m_parameterString.isEmpty()) {
+ QString error;
+ //TODO: look at using the property cache here (as in the compiler)
+ // for further optimization
+ QMetaMethod signal = QMetaObjectPrivate::signal(m_target->metaObject(), m_index);
+ expression += QQmlPropertyCache::signalParameterStringForJS(engine(), signal.parameterNames(), &error);
+
+ if (!error.isEmpty()) {
+ qmlInfo(scopeObject()) << error;
+ m_invalidParameterName = true;
+ ep->dereferenceScarceResources();
+ return;
}
- expression += QString::fromUtf8(param);
- }
-
- if (!error.isEmpty()) {
- qmlInfo(scopeObject()) << error;
- m_invalidParameterName = true;
- ep->dereferenceScarceResources();
- return;
- }
+ } else
+ expression += m_parameterString;
expression += QStringLiteral(") { ");
expression += m_expression;
expression += QStringLiteral(" })");
+
m_expression.clear();
+ m_handlerName.clear();
+ m_parameterString.clear();
m_v8function = evalFunction(context(), scopeObject(), expression,
m_fileName, m_line, &m_v8qmlscope);