4#ifndef QQMLJAVASCRIPTEXPRESSION_P_H
5#define QQMLJAVASCRIPTEXPRESSION_P_H
18#include <QtCore/qglobal.h>
19#include <QtCore/qtaggedpointer.h>
20#include <QtQml/qqmlerror.h>
21#include <private/qqmlengine_p.h>
22#include <QtQml/private/qbipointer_p.h>
26struct QQmlSourceLocation;
59 mutable QQmlError m_error;
67 Q_DISABLE_COPY_MOVE(QQmlJavaScriptExpression)
69 QQmlJavaScriptExpression();
70 virtual ~QQmlJavaScriptExpression();
77 bool evaluate(
void **a,
const QMetaType *types,
int argc);
94 void setContext(
const QQmlRefPointer<QQmlContextData> &context);
98 m_nextExpression = *listHead;
100 m_nextExpression->m_prevExpression = &m_nextExpression;
101 m_prevExpression = listHead;
115 friend class QQmlJavaScriptExpression;
117 QQmlJavaScriptExpression **_w;
118 QQmlJavaScriptExpression *_s;
130 const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope,
const QString &code,
131 const QString &filename, quint16 line);
140 void createQmlBinding(
const QQmlRefPointer<QQmlContextData> &ctxt, QObject *scope,
141 const QString &code,
const QString &filename, quint16 line);
143 void setupFunction(QV4::ExecutionContext *qmlContext, QV4::Function *f);
144 void setCompilationUnit(
const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit);
166 friend class QQmlContextData;
174 QQmlContextData *m_context;
176 QQmlJavaScriptExpression **m_prevExpression;
177 QQmlJavaScriptExpression *m_nextExpression;
179 QV4::PersistentValue m_qmlScope;
180 QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compilationUnit;
182 QV4::Function *m_v4Function;
185 TriggerList *qpropertyChangeTriggers =
nullptr;
191 QQmlPropertyCapture(QQmlEngine *engine, QQmlJavaScriptExpression *e, QQmlJavaScriptExpression::DeleteWatcher *w)
192 : engine(engine), expression(e), watcher(w), errorString(
nullptr) { }
194 ~QQmlPropertyCapture() {
195 Q_ASSERT(guards.isEmpty());
196 Q_ASSERT(errorString ==
nullptr);
199 void captureProperty(QQmlNotifier *);
200 void captureProperty(QObject *,
int,
int,
bool doNotify =
true);
201 void captureProperty(QObject *,
const QQmlPropertyCache *,
const QQmlPropertyData *,
bool doNotify =
true);
202 void captureTranslation();
205 QQmlJavaScriptExpression *expression;
206 QQmlJavaScriptExpression::DeleteWatcher *watcher;
207 QForwardFieldList<QQmlJavaScriptExpressionGuard, &QQmlJavaScriptExpressionGuard::next> guards;
208 QStringList *errorString;
211 void captureBindableProperty(QObject *o,
const QMetaObject *metaObjectForBindable,
int c);
212 void captureNonBindableProperty(QObject *o,
int n,
int c,
bool doNotify);
215QQmlJavaScriptExpression::DeleteWatcher::DeleteWatcher(QQmlJavaScriptExpression *e)
216: _c(
nullptr), _w(
nullptr), _s(e)
218 if (e->m_scopeObject.isT1()) {
220 _c = e->m_scopeObject.asT1();
221 e->m_scopeObject =
this;
224 _w = &e->m_scopeObject.asT2()->_s;
228QQmlJavaScriptExpression::DeleteWatcher::~DeleteWatcher()
230 Q_ASSERT(*_w ==
nullptr || (*_w == _s && _s->m_scopeObject.isT2()));
231 if (*_w && _s->m_scopeObject.asT2() ==
this)
232 _s->m_scopeObject = _c;
235bool QQmlJavaScriptExpression::DeleteWatcher::wasDeleted()
const
237 return *_w ==
nullptr;
240bool QQmlJavaScriptExpression::notifyOnValueChanged()
const
242 return activeGuards.tag() == NotifyOnValueChanged;
245QObject *QQmlJavaScriptExpression::scopeObject()
const
247 if (m_scopeObject.isT1())
return m_scopeObject.asT1();
248 else return m_scopeObject.asT2()->_c;
251void QQmlJavaScriptExpression::setScopeObject(QObject *v)
253 if (m_scopeObject.isT1()) m_scopeObject = v;
254 else m_scopeObject.asT2()->_c = v;
257bool QQmlJavaScriptExpression::hasError()
const
259 return !m_error.isNull() && m_error->isValid();
262bool QQmlJavaScriptExpression::hasDelayedError()
const
264 return !m_error.isNull();
267inline void QQmlJavaScriptExpression::clearError()
269 delete m_error.data();
273QQmlJavaScriptExpressionGuard::QQmlJavaScriptExpressionGuard(QQmlJavaScriptExpression *e)
274 : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlJavaScriptExpressionGuard),
275 expression(e), next(
nullptr)
279QQmlJavaScriptExpressionGuard *
280QQmlJavaScriptExpressionGuard::New(QQmlJavaScriptExpression *e,
284 return QQmlEnginePrivate::get(engine)->jsExpressionGuardPool.New(e);
287void QQmlJavaScriptExpressionGuard::Delete()
289 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
void QQmlJavaScriptExpressionGuard_callback(QQmlNotifierEndpoint *e, void **)