aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-09-30 16:37:55 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-10-01 04:36:11 +0000
commiteca744c9f0ab5c12d291d452fe17015fa3dc9188 (patch)
tree61a3b3deed99631b68dcecc91c626b2ad347f4d6
parent1faa471507238f0e6dc35f170ddf9766f36037d5 (diff)
InternalClass: Use scope for local internal classes
In most cases, the usage of scope is only to guard against future changes which could introduce allocations. However, in a few places we end calling functions that can allocate: Both addDummyEntry and cleanInternalClass can allocate memory, and there is nothing protecting the newly allocated internal class. Change-Id: I727a91380c49fb95cbd6f5cba39bdd5f9a9b0e5e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 39c5a4110f5465759531df0278753b3a67c2a32b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 4af0b1f637150228548a367470e8ab34a2b6cf70)
-rw-r--r--src/qml/jsruntime/qv4internalclass.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp
index 228a6bcd36..ff29b5c4dd 100644
--- a/src/qml/jsruntime/qv4internalclass.cpp
+++ b/src/qml/jsruntime/qv4internalclass.cpp
@@ -448,7 +448,9 @@ Heap::InternalClass *InternalClass::changeMember(
return t.lookup;
// create a new class and add it to the tree
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scope scope(engine);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
if (data.isAccessor() && e->setterIndex == UINT_MAX) {
Q_ASSERT(!propertyData.at(idx).isAccessor());
@@ -484,7 +486,8 @@ Heap::InternalClass *InternalClass::changePrototypeImpl(Heap::Object *proto)
return t.lookup;
// create a new class and add it to the tree
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
QV4::WriteBarrier::markCustom(engine, [&](QV4::MarkStack *stack) {
if (proto && QV4::WriteBarrier::isInsertionBarrier)
proto->mark(stack);
@@ -507,7 +510,9 @@ Heap::InternalClass *InternalClass::changeVTableImpl(const VTable *vt)
return t.lookup;
// create a new class and add it to the tree
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scope scope(engine);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
newClass->vtable = vt;
t.lookup = newClass;
@@ -528,7 +533,9 @@ Heap::InternalClass *InternalClass::nonExtensible()
if (t.lookup)
return t.lookup;
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scope scope(engine);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
newClass->flags |= NotExtensible;
t.lookup = newClass;
@@ -546,7 +553,9 @@ InternalClass *InternalClass::locked()
if (t.lookup)
return t.lookup;
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scope scope(engine);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
newClass->flags |= Locked;
t.lookup = newClass;
@@ -750,7 +759,9 @@ Heap::InternalClass *InternalClass::asProtoClass()
if (t.lookup)
return t.lookup;
- Heap::InternalClass *newClass = engine->newClass(this);
+ Scope scope(engine);
+ Scoped<QV4::InternalClass> scopedNewClass(scope, engine->newClass(this));
+ auto newClass = scopedNewClass->d();
newClass->flags |= UsedAsProto;
t.lookup = newClass;