aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlboundsignal.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-12-14 19:01:23 +0100
committerLiang Qi <liang.qi@qt.io>2016-12-14 19:01:23 +0100
commit0e80d28aa5892d6bbb4d0017b1bc9a33489f4176 (patch)
tree0db2e10c8776d172bccaeaa7ee1fab3934b93073 /src/qml/qml/qqmlboundsignal.cpp
parented32558d6280cae40578f735fd326327d571d993 (diff)
parent16c81bb0d493af00bc376784bcb7e03a4a037b04 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
Conflicts: src/plugins/qmltooling/qmldbg_debugger/qv4debugjob.cpp src/plugins/qmltooling/qmldbg_inspector/globalinspector.cpp src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp src/qml/qml/qqmlimport.cpp src/quick/items/context2d/qquickcontext2dtexture_p.h tools/qmleasing/splineeditor.h Change-Id: I8f6630fcac243824350986c8e9f4bd6483bf20b5
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp68
1 files changed, 24 insertions, 44 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index dfb1b98ca0..254d5e1907 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -98,20 +98,20 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
function += parameterString;
function += QLatin1String(") { ") + expression + QLatin1String(" })");
- m_function.set(v4, evalFunction(context(), scopeObject(), function, fileName, line));
-
- if (m_function.isNullOrUndefined())
- return; // could not evaluate function. Not valid.
-
+ QV4::Scope valueScope(v4);
+ QV4::ScopedFunctionObject f(valueScope, evalFunction(context(), scopeObject(), function, fileName, line));
+ QV4::ScopedContext context(valueScope, f->scope());
+ setupFunction(context, f->function());
}
-QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::Value &function)
+QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scopeObject,
+ QV4::Function *function, QV4::ExecutionContext *scope)
: QQmlJavaScriptExpression(),
m_index(index),
m_target(target)
{
- m_function.set(function.as<QV4::Object>()->engine(), function);
- init(ctxt, scope);
+ setupFunction(scope, function);
+ init(ctxt, scopeObject);
}
QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, QV4::Function *runtimeFunction)
@@ -122,14 +122,22 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index,
// It's important to call init first, because m_index gets remapped in case of cloned signals.
init(ctxt, scope);
- QMetaMethod signal = QMetaObjectPrivate::signal(m_target->metaObject(), m_index);
- QString error;
QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine);
- m_function.set(engine, QV4::FunctionObject::createQmlFunction(ctxt, scope, runtimeFunction, signal.parameterNames(), &error));
- if (!error.isEmpty()) {
- qmlInfo(scopeObject()) << error;
- m_function.clear();
+
+ QList<QByteArray> signalParameters = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).parameterNames();
+ if (!signalParameters.isEmpty()) {
+ QString error;
+ QQmlPropertyCache::signalParameterStringForJS(engine, signalParameters, &error);
+ if (!error.isEmpty()) {
+ qmlInfo(scopeObject()) << error;
+ return;
+ }
+ runtimeFunction->updateInternalClass(engine, signalParameters);
}
+
+ QV4::Scope valueScope(engine);
+ QV4::Scoped<QV4::QmlContext> qmlContext(valueScope, QV4::QmlContext::create(engine->rootContext(), ctxt, scope));
+ setupFunction(qmlContext, runtimeFunction);
}
void QQmlBoundSignalExpression::init(QQmlContextData *ctxt, QObject *scope)
@@ -157,41 +165,13 @@ void QQmlBoundSignalExpression::expressionChanged()
// bound signals do not notify on change.
}
-QQmlSourceLocation QQmlBoundSignalExpression::sourceLocation() const
-{
- QV4::Function *f = function();
- if (f) {
- QQmlSourceLocation loc;
- loc.sourceFile = f->sourceFile();
- loc.line = f->compiledFunction->location.line;
- loc.column = f->compiledFunction->location.column;
- return loc;
- }
- return QQmlSourceLocation();
-}
-
QString QQmlBoundSignalExpression::expression() const
{
- if (expressionFunctionValid()) {
- Q_ASSERT (context() && engine());
- QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine());
- QV4::ScopedValue v(scope, m_function.value());
- return v->toQStringNoThrow();
- }
+ if (expressionFunctionValid())
+ return QStringLiteral("function() { [code] }");
return QString();
}
-QV4::Function *QQmlBoundSignalExpression::function() const
-{
- if (expressionFunctionValid()) {
- Q_ASSERT (context() && engine());
- QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine());
- QV4::ScopedFunctionObject v(scope, m_function.value());
- return v ? v->function() : 0;
- }
- return 0;
-}
-
// Parts of this function mirror code in QQmlExpressionPrivate::value() and v8value().
// Changes made here may need to be made there and vice versa.
void QQmlBoundSignalExpression::evaluate(void **a)