diff options
author | Lars Knoll <[email protected]> | 2015-06-11 16:35:11 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2015-06-18 16:42:58 +0000 |
commit | f077bf13efee6d57261f76544e89a10acafb5a9c (patch) | |
tree | 9a438cd2cee32153586a477c22fea62b703199e5 /src/qml/jsruntime/qv4script.cpp | |
parent | fe9b63780da81fa8e3746e519dda320d57436503 (diff) |
Clean up ExecutionContext's for QML
Create a specialized QmlContext instead of re-using
a call context with a QQmlContextWrapper as activation
object.
This saves some memory and opens up the route to getting
rid of the context wrapper in a future commit.
Change-Id: I1591c73932a08564fddf5137ac05bbc6f31dd4d5
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 33efed8e70..c7dd28e795 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -44,6 +44,7 @@ #include <private/qqmljsparser_p.h> #include <private/qqmljsast_p.h> #include <private/qqmlengine_p.h> +#include <private/qv4profiling_p.h> #include <qv4jsir_p.h> #include <qv4codegen_p.h> #include <private/qqmlcontextwrapper_p.h> @@ -101,8 +102,7 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio o->defineReadonlyProperty(scope->d()->engine->id_length(), Primitive::fromInt32(1)); - ScopedContext ctx(s, s.engine->currentContext()); - o->d()->qmlContext = ctx->newQmlContext(o, qml); + o->d()->scope = ScopedContext(s, o->scope())->newQmlContext(qml); s.engine->popContext(); } @@ -117,26 +117,28 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::Ob o->defineReadonlyProperty(scope->d()->engine->id_length(), Primitive::fromInt32(1)); - ScopedContext ctx(s, s.engine->currentContext()); - o->d()->qmlContext = ctx->newQmlContext(o, qml); + o->d()->scope = ScopedContext(s, o->scope())->newQmlContext(qml); s.engine->popContext(); } -ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *) +ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData) { - ExecutionEngine *engine = static_cast<const Object *>(that)->engine(); - CHECK_STACK_LIMITS(engine); + ExecutionEngine *v4 = static_cast<const Object *>(that)->engine(); + if (v4->hasException) + return Encode::undefined(); + CHECK_STACK_LIMITS(v4); - Scope scope(engine); - const QmlBindingWrapper *This = static_cast<const QmlBindingWrapper *>(that); - if (!This->function()) + Scope scope(v4); + Scoped<QmlBindingWrapper> This(scope, static_cast<const QmlBindingWrapper *>(that)); + QV4::Function *f = This->function(); + if (!f) return QV4::Encode::undefined(); - Scoped<CallContext> 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(engine, This->function()->codeData)); - engine->popContext(); + ScopedContext context(scope, v4->currentContext()); + Scoped<CallContext> ctx(scope, context->newCallContext(This, callData)); + + ExecutionContextSaver ctxSaver(scope, context); + ScopedValue result(scope, Q_V4_PROFILE(v4, f)); return result->asReturnedValue(); } @@ -147,8 +149,6 @@ void QmlBindingWrapper::markObjects(Heap::Base *m, ExecutionEngine *e) if (wrapper->qml) wrapper->qml->mark(e); FunctionObject::markObjects(m, e); - if (wrapper->qmlContext) - wrapper->qmlContext->mark(e); } static ReturnedValue signalParameterGetter(QV4::CallContext *ctx, uint parameterIndex) @@ -166,7 +166,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine, qmlContext, scopeObject)); ScopedContext global(valueScope, valueScope.engine->rootContext()); QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, engine->memoryManager->alloc<QV4::QmlBindingWrapper>(global, qmlScopeObject)); - QV4::Scoped<CallContext> wrapperContext(valueScope, wrapper->context()); + QV4::Scoped<QmlContext> wrapperContext(valueScope, wrapper->context()); if (!signalParameters.isEmpty()) { if (error) |