diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-11-17 09:25:48 +0100 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-12-09 03:07:57 +0000 |
| commit | 762e70ea2ec028d0ce1659ed4ae8fc2ec47d950f (patch) | |
| tree | 8c3a650bf7afe99ca86e354a4dbc441db5504bae /src/qml/compiler/qv4codegen.cpp | |
| parent | 6f1bf8deee1c75c6ae4a23866c7cfeb9e7e3c9ac (diff) | |
QML/JS: Reject yield expression not directly in generator functions
If an inner function contains a yield expression, we need to reject the
program even if that function is inside of a generator function.
Fixes: QTBUG-98356
Change-Id: I2e820a1ca5f0da4080e313fd9809aa8bfdc1b681
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit dde1d86baabac1eddd84a11b7d2ed49e26c511bd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
| -rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index f7c4e2c98f..fb24a5c2ff 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3158,6 +3158,17 @@ bool Codegen::visit(YieldExpression *ast) return false; } + auto innerMostCurentFunctionContext = _context; + while (innerMostCurentFunctionContext && innerMostCurentFunctionContext->contextType != ContextType::Function) + innerMostCurentFunctionContext = innerMostCurentFunctionContext->parent; + + Q_ASSERT(innerMostCurentFunctionContext); // yield outside function would have been rejected by parser + + if (!innerMostCurentFunctionContext->isGenerator) { + throwSyntaxError(ast->firstSourceLocation(), u"Yield is only valid in generator functions"_qs); + return false; + } + RegisterScope scope(this); TailCallBlocker blockTailCalls(this); Reference expr = ast->expression ? expression(ast->expression) : Reference::fromConst(this, Encode::undefined()); |
