summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4compilerscanfunctions.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-08-13 22:34:05 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-08-18 10:05:51 +0000
commitaf5adb9e32713edb7196f761bcabd19f35722c57 (patch)
treef5c1f9d4e70c6bc9f9c7bb77d2d7be60797b668a /src/qml/compiler/qv4compilerscanfunctions.cpp
parent456632225f3173d401c68e301fb6d38f6c42e493 (diff)
downloadqtdeclarative-af5adb9e32713edb7196f761bcabd19f35722c57.tar.gz
Cleanup argument handling in contexts
Fix the compiler to already deal with duplicated argument names. Doing this at runtime was not ideal. Remove the callData member from the context. Instead use the fact that the arguments already followed the locals in the context. Don't copy the thisObject over into the CallContext anymore, it's never used from there anyway. Fix the ordering of names in the internalclass, so that arguments don't require special handling anymore when looking them up by name. Adjust all places that used callData, and related methods. Change-Id: I0bc45e1be3f1fcd38dc3b4f04e91edaf7b9ed103 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index b59beb0315..8c41d89bd4 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -408,11 +408,20 @@ void ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete
for (FormalParameterList *it = formals; it; it = it->next) {
QString arg = it->name.toString();
- if (_context->isStrict) {
- if (_context->arguments.contains(arg)) {
+ int duplicateIndex = _context->arguments.indexOf(arg);
+ if (duplicateIndex != -1) {
+ if (_context->isStrict) {
_cg->throwSyntaxError(it->identifierToken, QStringLiteral("Duplicate parameter name '%1' is not allowed in strict mode").arg(arg));
return;
+ } else {
+ // change the name of the earlier argument to enforce the specified lookup semantics
+ QString modified = arg;
+ while (_context->arguments.contains(modified))
+ modified += QString(0xfffe);
+ _context->arguments[duplicateIndex] = modified;
}
+ }
+ if (_context->isStrict) {
if (arg == QLatin1String("eval") || arg == QLatin1String("arguments")) {
_cg->throwSyntaxError(it->identifierToken, QStringLiteral("'%1' cannot be used as parameter name in strict mode").arg(arg));
return;