From 3e84f76bbc7a3fe0a8428be3cd6340401065ad23 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Nov 2014 16:06:43 +0100 Subject: Store Heap objects in the qml binding wrapper Change-Id: I7fae0710d148a2b07ec5f36a7fb96c2b645e564e Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4script.cpp | 15 ++++++++------- src/qml/jsruntime/qv4script_p.h | 6 +++--- src/qml/qml/qqmlobjectcreator.cpp | 6 ++++-- 3 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index e262eaa8ca..71a8284ec1 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -94,7 +94,7 @@ DEFINE_OBJECT_VTABLE(CompilationUnitHolder); Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false) - , qml(qml) + , qml(qml->d()) { Q_ASSERT(scope->inUse()); @@ -109,13 +109,13 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1)); - o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml)->getPointer(); + o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml)->getPointer()->d(); s.engine->popContext(); } Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Object *qml) : Heap::FunctionObject(scope, scope->d()->engine->id_eval, /*createProto = */ false) - , qml(qml) + , qml(qml->d()) { Q_ASSERT(scope->inUse()); @@ -127,7 +127,7 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Ob o->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(1)); - o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml)->getPointer(); + o->d()->qmlContext = s.engine->currentContext()->newQmlContext(o, qml)->getPointer()->d(); s.engine->popContext(); } @@ -141,7 +141,7 @@ ReturnedValue QmlBindingWrapper::call(Managed *that, CallData *) if (!This->function()) return QV4::Encode::undefined(); - CallContext *ctx = This->d()->qmlContext; + Scoped ctx(scope, This->d()->qmlContext); std::fill(ctx->d()->locals, ctx->d()->locals + ctx->d()->function->varCount(), Primitive::undefinedValue()); engine->pushContext(ctx); ScopedValue result(scope, This->function()->code(ctx, This->function()->codeData)); @@ -174,6 +174,7 @@ Returned *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo QV4::Scope valueScope(engine); QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine->v8Engine, qmlContext, scopeObject)); QV4::Scoped wrapper(valueScope, engine->memoryManager->alloc(engine->rootContext, qmlScopeObject)); + QV4::Scoped wrapperContext(valueScope, wrapper->context()); if (!signalParameters.isEmpty()) { if (error) @@ -182,7 +183,7 @@ Returned *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo QV4::ScopedString s(valueScope); int index = 0; foreach (const QByteArray ¶m, signalParameters) { - QV4::ScopedFunctionObject g(valueScope, engine->memoryManager->alloc(wrapper->context(), index++, signalParameterGetter)); + QV4::ScopedFunctionObject g(valueScope, engine->memoryManager->alloc(wrapperContext, index++, signalParameterGetter)); p->setGetter(g); p->setSetter(0); s = engine->newString(QString::fromUtf8(param)); @@ -190,7 +191,7 @@ Returned *QmlBindingWrapper::createQmlCallableForFunction(QQmlCo } } - QV4::ScopedFunctionObject function(valueScope, QV4::FunctionObject::createScriptFunction(wrapper->context(), runtimeFunction)); + QV4::ScopedFunctionObject function(valueScope, QV4::FunctionObject::createScriptFunction(wrapperContext, runtimeFunction)); return function->asReturned(); } diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 3379e204e1..3da8cf0269 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -76,8 +76,8 @@ struct QmlBindingWrapper : Heap::FunctionObject { QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::Object *qml); // Constructor for QML functions and signal handlers, resulting binding wrapper is not callable! QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Object *qml); - QV4::Object *qml; - QV4::CallContext *qmlContext; + Object *qml; + CallContext *qmlContext; }; } @@ -88,7 +88,7 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject { static ReturnedValue call(Managed *that, CallData *); static void markObjects(Heap::Base *m, ExecutionEngine *e); - CallContext *context() const { return d()->qmlContext; } + Heap::CallContext *context() const { return d()->qmlContext; } static Returned *createQmlCallableForFunction(QQmlContextData *qmlContext, QObject *scopeObject, QV4::Function *runtimeFunction, const QList &signalParameters = QList(), QString *error = 0); diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 42cac66fbd..dcf5f0cee4 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -267,7 +267,8 @@ bool QQmlObjectCreator::populateDeferredProperties(QObject *instance) QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _scopeObject)); QV4::Scoped qmlBindingWrapper(valueScope, v4->memoryManager->alloc(v4->rootContext, qmlScope)); - QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context(); + // ### GC + QV4::ExecutionContext *qmlContext = QV4::ScopedContext(valueScope, qmlBindingWrapper->context()).getPointer(); qSwap(_qmlContext, qmlContext); @@ -1177,7 +1178,8 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo QV4::Scope valueScope(v4); QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _scopeObject)); QV4::Scoped qmlBindingWrapper(valueScope, v4->memoryManager->alloc(v4->rootContext, qmlScope)); - QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context(); + // ### GC + QV4::ExecutionContext *qmlContext = QV4::ScopedContext(valueScope, qmlBindingWrapper->context()).getPointer(); qSwap(_qmlContext, qmlContext); -- cgit v1.2.3