aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp2
-rw-r--r--src/qml/jsruntime/qv4generatorobject.cpp2
-rw-r--r--src/qml/memory/qv4mm_p.h31
3 files changed, 32 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index f6f4c5211a..adbac53544 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -895,7 +895,7 @@ void ExecutionEngine::setProfiler(Profiling::Profiler *profiler)
void ExecutionEngine::initRootContext()
{
Scope scope(this);
- Scoped<ExecutionContext> r(scope, memoryManager->allocManaged<ExecutionContext>(sizeof(ExecutionContext::Data)));
+ Scoped<ExecutionContext> r(scope, memoryManager->allocManaged<ExecutionContext>());
r->d_unchecked()->init(Heap::ExecutionContext::Type_GlobalContext);
r->d()->activation.set(this, globalObject->d());
jsObjects[RootContext] = r;
diff --git a/src/qml/jsruntime/qv4generatorobject.cpp b/src/qml/jsruntime/qv4generatorobject.cpp
index 9f77d83ac3..cd2d83cff9 100644
--- a/src/qml/jsruntime/qv4generatorobject.cpp
+++ b/src/qml/jsruntime/qv4generatorobject.cpp
@@ -62,7 +62,7 @@ ReturnedValue GeneratorFunction::virtualCall(const FunctionObject *f, const Valu
ExecutionEngine *engine = gf->engine();
Scope scope(gf);
- Scoped<GeneratorObject> g(scope, engine->memoryManager->allocManaged<GeneratorObject>(sizeof(GeneratorObject::Data), engine->classes[EngineBase::Class_GeneratorObject]));
+ Scoped<GeneratorObject> g(scope, engine->memoryManager->allocManaged<GeneratorObject>(engine->classes[EngineBase::Class_GeneratorObject]));
g->setPrototypeOf(ScopedObject(scope, gf->get(scope.engine->id_prototype())));
// We need to set up a separate JSFrame for the generator, as it's being re-entered
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index 378b36369d..3a05bca536 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -117,6 +117,14 @@ public:
constexpr static inline std::size_t align(std::size_t size)
{ return (size + Chunk::SlotSize - 1) & ~(Chunk::SlotSize - 1); }
+ /* NOTE: allocManaged comes in various overloads. If size is not passed explicitly
+ sizeof(ManagedType::Data) is used for size. However, there are quite a few cases
+ where we allocate more than sizeof(ManagedType::Data); that's generally the case
+ when the Object has a ValueArray member.
+ If no internal class pointer is provided, ManagedType::defaultInternalClass(engine)
+ will be used as the internal class.
+ */
+
template<typename ManagedType>
inline typename ManagedType::Data *allocManaged(std::size_t size, Heap::InternalClass *ic)
{
@@ -130,12 +138,24 @@ public:
}
template<typename ManagedType>
+ inline typename ManagedType::Data *allocManaged(Heap::InternalClass *ic)
+ {
+ return allocManaged<ManagedType>(sizeof(typename ManagedType::Data), ic);
+ }
+
+ template<typename ManagedType>
inline typename ManagedType::Data *allocManaged(std::size_t size, InternalClass *ic)
{
return allocManaged<ManagedType>(size, ic->d());
}
template<typename ManagedType>
+ inline typename ManagedType::Data *allocManaged(InternalClass *ic)
+ {
+ return allocManaged<ManagedType>(sizeof(typename ManagedType::Data), ic);
+ }
+
+ template<typename ManagedType>
inline typename ManagedType::Data *allocManaged(std::size_t size)
{
Scope scope(engine);
@@ -143,6 +163,15 @@ public:
return allocManaged<ManagedType>(size, ic);
}
+ template<typename ManagedType>
+ inline typename ManagedType::Data *allocManaged()
+ {
+ auto constexpr size = sizeof(typename ManagedType::Data);
+ Scope scope(engine);
+ Scoped<InternalClass> ic(scope, ManagedType::defaultInternalClass(engine));
+ return allocManaged<ManagedType>(size, ic);
+ }
+
template <typename ObjectType>
typename ObjectType::Data *allocateObject(Heap::InternalClass *ic)
{
@@ -208,7 +237,7 @@ public:
typename ManagedType::Data *alloc(Args&&... args)
{
Scope scope(engine);
- Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data)));
+ Scoped<ManagedType> t(scope, allocManaged<ManagedType>());
t->d_unchecked()->init(std::forward<Args>(args)...);
return t->d();
}