diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-11 15:09:53 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-12 12:29:18 +0100 |
| commit | df70d4f76f9c1c7b3de9ae91877df803c18b1264 (patch) | |
| tree | ad6c1149b514841937bf87b48adb8f7363d70f13 /src/qml/compiler/qv4compilercontext.cpp | |
| parent | f3281ca869420df83d618c255aa7d62e63a102d5 (diff) | |
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 <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext.cpp')
| -rw-r--r-- | src/qml/compiler/qv4compilercontext.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp index 94c7f0631e..bce46f59be 100644 --- a/src/qml/compiler/qv4compilercontext.cpp +++ b/src/qml/compiler/qv4compilercontext.cpp @@ -86,8 +86,10 @@ bool Context::Member::requiresTDZCheck(const SourceLocation &accessLocation, boo return accessLocation.begin() < declarationLocation.end(); } -bool Context::addLocalVar(const QString &name, Context::MemberType type, VariableScope scope, FunctionExpression *function, - const QQmlJS::SourceLocation &declarationLocation) +bool Context::addLocalVar( + const QString &name, Context::MemberType type, VariableScope scope, + FunctionExpression *function, const QQmlJS::SourceLocation &declarationLocation, + bool isInjected) { // ### can this happen? if (name.isEmpty()) @@ -119,6 +121,7 @@ bool Context::addLocalVar(const QString &name, Context::MemberType type, Variabl m.function = function; m.scope = scope; m.declarationLocation = declarationLocation; + m.isInjected = isInjected; members.insert(name, m); return true; } @@ -147,9 +150,10 @@ Context::ResolvedName Context::resolveName(const QString &name, const QQmlJS::So if (c->isStrict && (name == QLatin1String("arguments") || name == QLatin1String("eval"))) result.isArgOrEval = true; result.declarationLocation = m.declarationLocation; + result.isInjected = m.isInjected; return result; } - const int argIdx = c->findArgument(name); + const int argIdx = c->findArgument(name, &result.isInjected); if (argIdx != -1) { if (c->argumentsCanEscape) { result.index = argIdx + c->locals.size(); |
