diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-08-07 09:33:52 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-08-07 14:47:06 +0200 |
| commit | 8e33e3122f9169df2ece67343db8e899666c5c2d (patch) | |
| tree | 272fd2ec9af3b4c8ddb907db7c718d4108d83297 /src/qml/jsruntime/qv4globalobject.cpp | |
| parent | 12f783da0d04e6e5d113e381bbfd8b94f2f895a2 (diff) | |
QtQml: Assert on currentStackFrame in direct eval call
If we're called directly from a CallPossiblyDirectEval instruction, that
instruction must live in a function which must have created a stack
frame.
Coverity-Id: 486651
Change-Id: I8136f40a8b6058ad499a7fdaaed99bf85485b11c
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4globalobject.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4globalobject.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index a82751ae99..dffa76aabb 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -298,6 +298,17 @@ void Heap::EvalFunction::init(QV4::ExecutionEngine *engine) f->defineReadonlyConfigurableProperty(s.engine->id_length(), Value::fromInt32(1)); } +static ExecutionContext *evalContext(QV4::ExecutionEngine *v4, bool directCall) +{ + // In case of !directCall, the context for eval should be the global scope + if (!directCall) + return v4->scriptContext(); + + // Otherwise there has to be a current stack frame. We need to be called from somewhere. + Q_ASSERT(v4->currentStackFrame); + return v4->currentContext(); +} + ReturnedValue EvalFunction::evalCall(const Value *, const Value *argv, int argc, bool directCall) const { if (argc < 1) @@ -311,8 +322,7 @@ ReturnedValue EvalFunction::evalCall(const Value *, const Value *argv, int argc, Scope scope(v4); - // In case of !directCall, the context for eval should be the global scope - ScopedContext ctx(scope, directCall ? v4->currentContext() : v4->scriptContext()); + ScopedContext ctx(scope, evalContext(v4, directCall)); String *scode = argv[0].stringValue(); if (!scode) |
