From af5adb9e32713edb7196f761bcabd19f35722c57 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 13 Aug 2017 22:34:05 +0200 Subject: 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 --- src/qml/compiler/qv4compilerscanfunctions.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp') 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; -- cgit v1.2.3