5#ifndef QQMLJAVASCRIPTEXPRESSION_P_H
6#define QQMLJAVASCRIPTEXPRESSION_P_H
19#include <QtCore/qglobal.h>
20#include <QtCore/qtaggedpointer.h>
21#include <QtQml/qqmlerror.h>
22#include <private/qqmlengine_p.h>
23#include <QtQml/private/qbipointer_p.h>
27struct QQmlSourceLocation;
60 mutable QQmlError m_error;
68 Q_DISABLE_COPY_MOVE(QQmlJavaScriptExpression)
70 QQmlJavaScriptExpression();
71 virtual ~QQmlJavaScriptExpression();
78 bool evaluate(
void **a,
const QMetaType *types,
int argc);
95 void setContext(
const QQmlRefPointer<QQmlContextData> &context);
99 m_nextExpression = *listHead;
100 if (m_nextExpression)
101 m_nextExpression->m_prevExpression = &m_nextExpression;
102 m_prevExpression = listHead;
116 friend class QQmlJavaScriptExpression;
118 QQmlJavaScriptExpression **_w;
119 QQmlJavaScriptExpression *_s;
131 const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope,
const QString &code,
132 const QString &filename, quint16 line);
141 void createQmlBinding(
const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope,
142 const QString &code,
const QString &filename, quint16 line);
144 void setupFunction(QV4::ExecutionContext *qmlContext, QV4::Function *f);
145 void setCompilationUnit(
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit);
167 friend class QQmlContextData;
175 QQmlContextData *m_context;
177 QQmlJavaScriptExpression **m_prevExpression;
178 QQmlJavaScriptExpression *m_nextExpression;
180 QV4::PersistentValue m_qmlScope;
181 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
183 QV4::Function *m_v4Function;
186 TriggerList *qpropertyChangeTriggers =
nullptr;
192 QQmlPropertyCapture(QQmlEngine *engine, QQmlJavaScriptExpression *e, QQmlJavaScriptExpression::DeleteWatcher *w)
193 : engine(engine), expression(e), watcher(w), errorString(
nullptr) { }
195 ~QQmlPropertyCapture() {
196 Q_ASSERT(guards.isEmpty());
197 Q_ASSERT(errorString ==
nullptr);
200 void captureProperty(QQmlNotifier *);
201 void captureProperty(QObject *,
int,
int,
bool doNotify =
true);
202 void captureProperty(QObject *,
const QQmlPropertyCache *,
const QQmlPropertyData *,
bool doNotify =
true);
203 void captureTranslation();
206 QQmlJavaScriptExpression *expression;
207 QQmlJavaScriptExpression::DeleteWatcher *watcher;
208 QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> guards;
209 QStringList *errorString;
212 void captureBindableProperty(QObject *o,
const QMetaObject *metaObjectForBindable,
int c);
213 void captureNonBindableProperty(QObject *o,
int n,
int c,
bool doNotify);
216QQmlJavaScriptExpression::DeleteWatcher::DeleteWatcher(QQmlJavaScriptExpression *e)
217: _c(
nullptr), _w(
nullptr), _s(e)
219 if (e->m_scopeObject.isT1()) {
221 _c = e->m_scopeObject.asT1();
222 e->m_scopeObject =
this;
225 _w = &e->m_scopeObject.asT2()->_s;
229QQmlJavaScriptExpression::DeleteWatcher::~DeleteWatcher()
231 Q_ASSERT(*_w ==
nullptr || (*_w == _s && _s->m_scopeObject.isT2()));
232 if (*_w && _s->m_scopeObject.asT2() ==
this)
233 _s->m_scopeObject = _c;
236bool QQmlJavaScriptExpression::DeleteWatcher::wasDeleted()
const
238 return *_w ==
nullptr;
241bool QQmlJavaScriptExpression::notifyOnValueChanged()
const
243 return activeGuards.tag() == NotifyOnValueChanged;
246QObject *QQmlJavaScriptExpression::scopeObject()
const
248 if (m_scopeObject.isT1())
return m_scopeObject.asT1();
249 else return m_scopeObject.asT2()->_c;
252void QQmlJavaScriptExpression::setScopeObject(QObject *v)
254 if (m_scopeObject.isT1()) m_scopeObject = v;
255 else m_scopeObject.asT2()->_c = v;
258bool QQmlJavaScriptExpression::hasError()
const
260 return !m_error.isNull() && m_error->isValid();
263bool QQmlJavaScriptExpression::hasDelayedError()
const
265 return !m_error.isNull();
268inline void QQmlJavaScriptExpression::clearError()
270 delete m_error.data();
274QQmlJavaScriptExpressionGuard::QQmlJavaScriptExpressionGuard(QQmlJavaScriptExpression *e)
275 : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlJavaScriptExpressionGuard),
276 expression(e), next(
nullptr)
280QQmlJavaScriptExpressionGuard *
281QQmlJavaScriptExpressionGuard::New(QQmlJavaScriptExpression *e,
285 return QQmlEnginePrivate::get(engine)->jsExpressionGuardPool.New(e);
288void QQmlJavaScriptExpressionGuard::Delete()
290 QRecyclePool<QQmlJavaScriptExpressionGuard>::Delete(
this);
QOpenGLContext * context() const
bool addError(QQmlEnginePrivate *)
void setErrorObject(QObject *object)
void catchJavaScriptException(QV4::ExecutionEngine *engine)
void setErrorDescription(const QString &description)
QQmlEngine * engine() const
Return the QQmlEngine this incubation controller is set on, or 0 if it has not been set on any engine...
DeleteWatcher(QQmlJavaScriptExpression *)
void insertIntoList(QQmlJavaScriptExpression **listHead)
void setNotifyOnValueChanged(bool v)
void setupFunction(QV4::ExecutionContext *qmlContext, QV4::Function *f)
QV4::Function * function() const
void setCompilationUnit(const QQmlRefPointer< QV4::ExecutableCompilationUnit > &compilationUnit)
bool evaluate(void **a, const QMetaType *types, int argc)
QQmlDelayedError * delayedError()
QObject * scopeObject() const
bool needsPropertyChangeTrigger(QObject *target, int propertyIndex)
QV4::ReturnedValue evaluate(bool *isUndefined)
virtual QString expressionIdentifier() const
bool hasUnresolvedNames() const
QForwardFieldList< QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next, GuardTag > activeGuards
void setContext(const QQmlRefPointer< QQmlContextData > &context)
bool hasDelayedError() const
friend class QQmlPropertyCapture
bool hasValidContext() const
static QV4::ReturnedValue evalFunction(const QQmlRefPointer< QQmlContextData > &ctxt, QObject *scope, const QString &code, const QString &filename, quint16 line)
QQmlError error(QQmlEngine *) const
void resetNotifyOnValueChanged()
QV4::ReturnedValue evaluate(QV4::CallData *callData, bool *isUndefined)
virtual QQmlSourceLocation sourceLocation() const
void setScopeObject(QObject *v)
QBiPointer< QObject, DeleteWatcher > m_scopeObject
virtual void expressionChanged()=0
QQmlContext * publicContext() const
QPropertyChangeTrigger * allocatePropertyChangeTrigger(QObject *target, int propertyIndex)
bool notifyOnValueChanged() const
virtual bool mustCaptureBindableProperty() const
QTaggedPointer< QQmlDelayedError, Tag > m_error
Combined button and popup list for selecting options.
void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *e, void **)