aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4codegen.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-06-21 11:43:00 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-06-21 10:33:55 +0000
commitd2a0ec44567cfee2999d2e37ed06fa75b73c01ab (patch)
treeb0618e977956d73868a701912dc8832ff5e491d0 /src/qml/compiler/qv4codegen.cpp
parent48d77ce4c83c2c1d2f3ee3d01c69550e115c3226 (diff)
Throw syntax error if arguments or eval are used as lvalues in strict mode
Change-Id: I4c46537e3a4f3c2c22efea323dc8a95c1078c75f Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r--src/qml/compiler/qv4codegen.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 56d28d2147..e07a2e67ce 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -1916,11 +1916,14 @@ Codegen::Reference Codegen::referenceForName(const QString &name, bool isLhs)
int index = e->findMember(name);
Q_ASSERT (index < e->members.size());
if (index != -1) {
- if (isLhs && f->isStrict && (name == QLatin1String("arguments") || name == QLatin1String("eval"))) {
- // ### add correct source location
- throwSyntaxError(SourceLocation(), QStringLiteral("Variable name may not be eval or arguments in strict mode"));
+ Reference r = Reference::fromLocal(this, index, scope);
+ if (name == QLatin1String("arguments") || name == QLatin1String("eval")) {
+ r.isArgOrEval = true;
+ if (isLhs && f->isStrict)
+ // ### add correct source location
+ throwSyntaxError(SourceLocation(), QStringLiteral("Variable name may not be eval or arguments in strict mode"));
}
- return Reference::fromLocal(this, index, scope);
+ return r;
}
const int argIdx = f->indexOfArgument(QStringRef(&name));
if (argIdx != -1)
@@ -3137,14 +3140,18 @@ bool Codegen::throwSyntaxErrorOnEvalOrArgumentsInStrictMode(const Reference &r,
{
if (!_variableEnvironment->isStrict)
return false;
+ bool isArgOrEval = false;
if (r.type == Reference::Name) {
QString str = jsUnitGenerator->stringForIndex(r.nameIndex);
if (str == QLatin1String("eval") || str == QLatin1String("arguments")) {
- throwSyntaxError(loc, QStringLiteral("Variable name may not be eval or arguments in strict mode"));
- return true;
+ isArgOrEval = true;
}
+ } else if (r.type == Reference::Local) {
+ isArgOrEval = r.isArgOrEval;
}
- return false;
+ if (isArgOrEval)
+ throwSyntaxError(loc, QStringLiteral("Variable name may not be eval or arguments in strict mode"));
+ return isArgOrEval;
}
void Codegen::throwSyntaxError(const SourceLocation &loc, const QString &detail)
@@ -3261,6 +3268,7 @@ Codegen::Reference &Codegen::Reference::operator =(const Reference &other)
// keep loaded reference
tempIndex = other.tempIndex;
needsWriteBack = false;
+ isArgOrEval = other.isArgOrEval;
codegen = other.codegen;
return *this;
}