diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-14 09:36:41 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-08 18:33:59 +0000 |
commit | 948bcdbc01a2c4a2df3eed187908b006f199ecc9 (patch) | |
tree | 8c5c7c23c27b3d2cd2e8ef74a3ce60cd6a365e89 /src/qml/jsruntime/qv4functionobject.cpp | |
parent | 4d2e92b6214ac49a86685ae4f5f8ea0a78f2a7a0 (diff) |
Move createQmlCallableForFunction out of the binding wrapper
It's now QV4::FunctionObject::createQmlFunction, which I
believe is a better place and name for the method, esp.
as it has no real connnection to the binding wrapper anymore.
Change-Id: I59e20e120db72e53735b3a986e0b91bc7c3347d7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 6412e65fa9..329ecd70fc 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -206,6 +206,43 @@ Heap::FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *sco return scope->d()->engine->memoryManager->alloc<SimpleScriptFunction>(scope, function, createProto); } +static ReturnedValue signalParameterGetter(QV4::CallContext *ctx, uint parameterIndex) +{ + QV4::Scope scope(ctx); + QV4::Scoped<CallContext> signalEmittingContext(scope, ctx->d()->parent.cast<Heap::CallContext>()); + Q_ASSERT(signalEmittingContext && signalEmittingContext->d()->type >= QV4::Heap::ExecutionContext::Type_SimpleCallContext); + return signalEmittingContext->argument(parameterIndex); +} + +Heap::FunctionObject *FunctionObject::createQmlFunction(QQmlContextData *qmlContext, QObject *scopeObject, Function *runtimeFunction, const QList<QByteArray> &signalParameters, QString *error) +{ + ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(qmlContext->engine); + QV4::Scope valueScope(engine); + QV4::Scoped<QmlContextWrapper> qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine, qmlContext, scopeObject)); + ScopedContext global(valueScope, valueScope.engine->rootContext()); + QV4::Scoped<QmlContext> wrapperContext(valueScope, global->newQmlContext(qmlScopeObject)); + engine->popContext(); + + if (!signalParameters.isEmpty()) { + if (error) + QQmlPropertyCache::signalParameterStringForJS(engine, signalParameters, error); + QV4::ScopedProperty p(valueScope); + QV4::ScopedString s(valueScope); + int index = 0; + foreach (const QByteArray ¶m, signalParameters) { + QV4::ScopedFunctionObject g(valueScope, engine->memoryManager->alloc<QV4::IndexedBuiltinFunction>(wrapperContext, index++, signalParameterGetter)); + p->setGetter(g); + p->setSetter(0); + s = engine->newString(QString::fromUtf8(param)); + qmlScopeObject->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable); + } + } + + QV4::ScopedFunctionObject function(valueScope, QV4::FunctionObject::createScriptFunction(wrapperContext, runtimeFunction)); + return function->d(); +} + + bool FunctionObject::isBinding() const { return d()->vtable() == QQmlBindingFunction::staticVTable(); |