diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-03 09:31:47 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-05 12:57:41 +0000 |
commit | fa74444ed06e4db21b0e9829a5832b886b39d372 (patch) | |
tree | 0bc352c539e164f15ccfe7fbb1db1dd7226a5bec /src/qml/compiler/qv4compilerscanfunctions.cpp | |
parent | 76f410452dd09489cc48197a0dd4d0bf95699647 (diff) |
fix accesses to this in arrow functions
Change-Id: I4c0cfc3a120fc0b246760886b576e92d3f7623ff
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index e0a745ebb1..dafb1c360d 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -742,6 +742,8 @@ void ScanFunctions::calcEscapingVariables() } Q_ASSERT(c); c->hasDirectEval = true; + if (!c->isStrict) + c->innerFunctionAccessesThis = true; } Context *c = inner; while (c) { @@ -751,17 +753,26 @@ void ScanFunctions::calcEscapingVariables() } if (inner->usesThis) { inner->usesThis = false; - if (!inner->isStrict) { - Context *c = inner; - while (c->contextType == ContextType::Block) { - c = c->parent; - } - Q_ASSERT(c); - c->usesThis = true; + bool innerFunctionAccessesThis = false; + Context *c = inner; + while (c->contextType == ContextType::Block || c->isArrowFunction) { + innerFunctionAccessesThis |= c->isArrowFunction; + c = c->parent; } + Q_ASSERT(c); + if (!inner->isStrict) + c->usesThis = true; + c->innerFunctionAccessesThis |= innerFunctionAccessesThis; } } for (Context *c : qAsConst(m->contextMap)) { + if (c->innerFunctionAccessesThis) { + // add an escaping 'this' variable + c->addLocalVar(QStringLiteral("this"), Context::VariableDefinition, VariableScope::Let); + c->requiresExecutionContext = true; + auto m = c->members.find(QStringLiteral("this")); + m->canEscape = true; + } if (c->allVarsEscape && c->contextType == ContextType::Block && c->members.isEmpty()) c->allVarsEscape = false; if (c->contextType == ContextType::Global || (!c->isStrict && c->contextType == ContextType::Eval) || m->debugMode) @@ -801,6 +812,7 @@ void ScanFunctions::calcEscapingVariables() qDebug() << "==== escaping variables ===="; for (Context *c : qAsConst(m->contextMap)) { qDebug() << "Context" << c << c->name << "requiresExecutionContext" << c->requiresExecutionContext << "isStrict" << c->isStrict; + qDebug() << " isArrowFunction" << c->isArrowFunction << "innerFunctionAccessesThis" << c->innerFunctionAccessesThis; qDebug() << " parent:" << c->parent; if (c->argumentsCanEscape) qDebug() << " Arguments escape"; |