diff options
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 7067d10e22..c221a99959 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -64,6 +64,10 @@ struct CompilationUnitHolder : Object { QQmlRefPointer<CompiledData::CompilationUnit> unit; }; +struct QmlBindingWrapper : FunctionObject { + QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml); +}; + } struct CompilationUnitHolder : public Object @@ -79,6 +83,12 @@ Heap::CompilationUnitHolder::CompilationUnitHolder(ExecutionEngine *engine, Comp { } +struct QmlBindingWrapper : FunctionObject { + V4_OBJECT2(QmlBindingWrapper, FunctionObject) + + static ReturnedValue call(const Managed *that, CallData *callData); +}; + } QT_END_NAMESPACE @@ -126,42 +136,6 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData) return result->asReturnedValue(); } -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 *QmlBindingWrapper::createQmlCallableForFunction(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(); -} - Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit) : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) , qml(v4, qml), vmFunction(0), parseAsBinding(true) |