diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-01 16:26:42 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-02 09:27:21 +0100 |
| commit | eeec9f03e9cf57e8cde311897f7e3e62a217da15 (patch) | |
| tree | 50b4067f7c11759a98981ca6d9624ee59458ac9d /src/qml/compiler/qv4codegen.cpp | |
| parent | 9052e09a21fd77c44127f9c75dc8aff8ae60184d (diff) | |
JavaScript: Make "this" available in blocks inside arrow functions
Fixes: QTBUG-98039
Pick-to: 6.2 6.3
Change-Id: I51ff36994fa0f3f3568c8114cb6841f677f64bc4
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
| -rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index fd55ce5562..20685e42f1 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3065,12 +3065,17 @@ bool Codegen::visit(ThisExpression *) if (hasError()) return false; - if (_context->isArrowFunction) { - Reference r = referenceForName(QStringLiteral("this"), false); - r.isReadonly = true; - setExprResult(r); - return false; + for (Context *parentContext = _context; parentContext; parentContext = parentContext->parent) { + if (parentContext->isArrowFunction) { + Reference r = referenceForName(QStringLiteral("this"), false); + r.isReadonly = true; + setExprResult(r); + return false; + } + if (parentContext->contextType != ContextType::Block) + break; } + setExprResult(Reference::fromThis(this)); return false; } |
