diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-12-02 14:23:04 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2016-12-09 14:01:42 +0000 |
commit | 1eee98f1c1c59f8c45387684e269629713958bd4 (patch) | |
tree | 786e909d5427e07c08d9a7263d005723cf95c737 /src | |
parent | f1dca03794f8db353655d44e742a2960f1f69070 (diff) |
Limit access to m_function to QQmlJavaScriptExpression
Change-Id: I070f73f106440667fce2c7fe33310369a6aa1376
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/qqmlboundsignal.cpp | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlexpression.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression.cpp | 15 | ||||
-rw-r--r-- | src/qml/qml/qqmljavascriptexpression_p.h | 3 |
5 files changed, 28 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index f21d68b8a9..a8232904fe 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -85,7 +85,9 @@ QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, const QQmlScr QV4::ExecutionEngine *v4 = QQmlEnginePrivate::get(b->context()->engine)->v4engine(); if (runtimeFunction) { - b->m_function.set(v4, QV4::FunctionObject::createQmlFunction(ctxtdata, b->scopeObject(), runtimeFunction)); + QV4::Scope scope(v4); + QV4::ScopedFunctionObject f(scope, QV4::FunctionObject::createQmlFunction(ctxtdata, b->scopeObject(), runtimeFunction)); + b->setFunctionObject(f); } else { QString code = scriptPrivate->script; b->createQmlBinding(b->context(), b->scopeObject(), code, url, scriptPrivate->lineNumber); @@ -116,7 +118,7 @@ QQmlBinding *QQmlBinding::create(const QQmlPropertyData *property, const QV4::Fu b->QQmlJavaScriptExpression::setContext(ctxt); b->setScopeObject(obj); - b->m_function.set(function->engine(), *function); + b->setFunctionObject(function); return b; } diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 91b3f89825..974bd3404a 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -98,7 +98,9 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, function += parameterString; function += QLatin1String(") { ") + expression + QLatin1String(" })"); - m_function.set(v4, evalFunction(context(), scopeObject(), function, fileName, line)); + QV4::Scope valueScope(v4); + QV4::ScopedFunctionObject f(valueScope, evalFunction(context(), scopeObject(), function, fileName, line)); + setFunctionObject(f); } QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::Value &function) @@ -106,7 +108,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, m_index(index), m_target(target) { - m_function.set(function.as<QV4::Object>()->engine(), function); + setFunctionObject(function.as<QV4::FunctionObject>()); init(ctxt, scope); } @@ -121,7 +123,9 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, 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)); + QV4::Scope valueScope(engine); + QV4::ScopedFunctionObject f(valueScope, QV4::FunctionObject::createQmlFunction(ctxt, scope, runtimeFunction, signal.parameterNames(), &error)); + setFunctionObject(f); if (!error.isEmpty()) qmlInfo(scopeObject()) << error; } diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index 6afbd05e3e..2a9d0a7b90 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -75,7 +75,9 @@ void QQmlExpressionPrivate::init(QQmlContextData *ctxt, QV4::Function *runtimeFu { expressionFunctionValid = true; QV4::ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(ctxt->engine); - m_function.set(engine, QV4::FunctionObject::createQmlFunction(ctxt, me, runtimeFunction)); + QV4::Scope scope(engine); + QV4::ScopedFunctionObject f(scope, QV4::FunctionObject::createQmlFunction(ctxt, me, runtimeFunction)); + setFunctionObject(f); QQmlJavaScriptExpression::setContext(ctxt); setScopeObject(me); diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index cb36758f74..9616a088ae 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -160,7 +160,10 @@ void QQmlJavaScriptExpression::setContext(QQmlContextData *context) QV4::Function *QQmlJavaScriptExpression::function() const { - QV4::FunctionObject *f = m_function.valueRef()->as<QV4::FunctionObject>(); + QV4::Value *v = m_function.valueRef(); + if (!v) + return 0; + QV4::FunctionObject *f = v->as<QV4::FunctionObject>(); if (f && f->isBinding()) return static_cast<QV4::QQmlBindingFunction *>(f)->d()->originalFunction->function; return f ? f->function() : 0; @@ -430,7 +433,7 @@ void QQmlJavaScriptExpression::createQmlBinding(QQmlContextData *ctxt, QObject * QV4::Scoped<QV4::QmlContext> qmlContext(scope, QV4::QmlContext::create(v4->rootContext(), ctxt, qmlScope)); QV4::Script script(v4, qmlContext, code, filename, line); - QV4::ScopedValue result(scope); + QV4::ScopedFunctionObject result(scope); script.parse(); if (!v4->hasException) result = script.qmlBinding(); @@ -446,7 +449,13 @@ void QQmlJavaScriptExpression::createQmlBinding(QQmlContextData *ctxt, QObject * ep->warning(error); result = QV4::Encode::undefined(); } - m_function.set(v4, result); + setFunctionObject(result); +} + +void QQmlJavaScriptExpression::setFunctionObject(const QV4::FunctionObject *o) +{ + if (o) + m_function.set(o->engine(), o->d()); } diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index 3e00d6be24..887672b925 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -158,6 +158,8 @@ protected: } } + void setFunctionObject(const QV4::FunctionObject *o); + private: friend class QQmlContextData; friend class QQmlPropertyCapture; @@ -177,7 +179,6 @@ private: QQmlJavaScriptExpression *m_nextExpression; bool m_permanentDependenciesRegistered = false; -protected: QV4::PersistentValue m_function; }; |