From fe6ec7bcc17f88ab1aca5a7934d047456354c942 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 3 Jul 2013 16:44:55 +0200 Subject: 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 --- src/qml/qml/qqmlboundsignal.cpp | 53 ++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) (limited to 'src/qml/qml/qqmlboundsignal.cpp') 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 ¶meterString) : 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 &illegalNames = ep->v8engine()->illegalNames(); - - const QList parameters = signal.parameterNames(); - for (int i = 0; i < parameters.count(); ++i) { - if (i > 0) - expression += QLatin1Char(','); - const QByteArray ¶m = 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); -- cgit v1.2.3