From df70d4f76f9c1c7b3de9ae91877df803c18b1264 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 11 Feb 2021 15:09:53 +0100 Subject: QML: Warn about usage of injected signal parameters You should declare functions with formal parameters if you want to use parameters passed by the signal. We need to generate two different warnings because there are two code paths by which such parameters are injected. If we compile with qmlcachegen, it simply inserts a lookup instruction in to the byte code. This lookup then triggers our special hack expressly made for signal parameters. If we don't compile using qmlcachegen, a function declaration with formal parameters is synthesized. We mark those formal parameters as injected and warn if we see one of them used. [ChangeLog][QML][Important Behavior Changes] The automatic injection of signal parameters into signal handlers is deprecated. This is because we cannot determine the names of the signal parameters at compile time. Furthermore, also for human readers it is difficult to discern between arguments, context properties, properties of the current object, and properties of the root object of the component. Requiring the signal parameters to be explicitly named resolves some of this confusion. You can turn the deprecation warning off using the "qt.qml.compiler" and "qt.qml.context" logging categories. Task-number: QTBUG-89943 Pick-to: 6.1 Change-Id: If0a5082adb735a73efd793868b3a55bc7d694cbe Reviewed-by: Mitch Curtis Reviewed-by: Fabian Kosmale Reviewed-by: Andrei Golubev --- src/qml/compiler/qv4compilerscanfunctions.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp') diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index c4f46ecf05..ebc9a86a16 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -703,22 +703,24 @@ bool ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete const BoundNames boundNames = formals ? formals->boundNames() : BoundNames(); for (int i = 0; i < boundNames.size(); ++i) { - const QString &arg = boundNames.at(i).id; + const auto &arg = boundNames.at(i); if (_context->isStrict || !isSimpleParameterList) { - bool duplicate = (boundNames.indexOf(arg, i + 1) != -1); + bool duplicate = (boundNames.indexOf(arg.id, i + 1) != -1); if (duplicate) { - _cg->throwSyntaxError(formals->firstSourceLocation(), QStringLiteral("Duplicate parameter name '%1' is not allowed.").arg(arg)); + _cg->throwSyntaxError(formals->firstSourceLocation(), QStringLiteral("Duplicate parameter name '%1' is not allowed.").arg(arg.id)); return false; } } if (_context->isStrict) { - if (arg == QLatin1String("eval") || arg == QLatin1String("arguments")) { - _cg->throwSyntaxError(formals->firstSourceLocation(), QStringLiteral("'%1' cannot be used as parameter name in strict mode").arg(arg)); + if (arg.id == QLatin1String("eval") || arg.id == QLatin1String("arguments")) { + _cg->throwSyntaxError(formals->firstSourceLocation(), QStringLiteral("'%1' cannot be used as parameter name in strict mode").arg(arg.id)); return false; } } - if (!_context->arguments.contains(arg)) - _context->addLocalVar(arg, Context::VariableDefinition, VariableScope::Var); + if (!_context->arguments.contains(arg.id)) { + _context->addLocalVar(arg.id, Context::VariableDefinition, VariableScope::Var, nullptr, + QQmlJS::SourceLocation(), arg.isInjected()); + } } return true; @@ -787,7 +789,7 @@ void ScanFunctions::calcEscapingVariables() } break; } - if (c->findArgument(var) != -1) { + if (c->hasArgument(var)) { c->argumentsCanEscape = true; c->requiresExecutionContext = true; break; -- cgit v1.2.1