diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-16 15:38:40 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-06-16 15:38:40 +1000 |
commit | 7ad493f4c217c7876d6ab51f5a679536b3a6e8b4 (patch) | |
tree | 61efc6ff096ca8ea2048c47ab88ada5f7a766089 /src/declarative/qml/qdeclarativeexpression_p.h | |
parent | f6563426a2604c2f221fc4c23cb4766071f9df54 (diff) |
Cleanup
Diffstat (limited to 'src/declarative/qml/qdeclarativeexpression_p.h')
-rw-r--r-- | src/declarative/qml/qdeclarativeexpression_p.h | 225 |
1 files changed, 162 insertions, 63 deletions
diff --git a/src/declarative/qml/qdeclarativeexpression_p.h b/src/declarative/qml/qdeclarativeexpression_p.h index b03c70905c..dcf47c3134 100644 --- a/src/declarative/qml/qdeclarativeexpression_p.h +++ b/src/declarative/qml/qdeclarativeexpression_p.h @@ -55,8 +55,8 @@ #include "qdeclarativeexpression.h" -#include "private/qdeclarativeengine_p.h" -#include "private/qdeclarativeguard_p.h" +#include <private/qdeclarativeengine_p.h> +#include <private/qdeclarativeguard_p.h> #include <private/qv8engine_p.h> @@ -107,73 +107,84 @@ private: QDeclarativeDelayedError **prevError; }; -class QDeclarativeQtScriptExpression : public QDeclarativeAbstractExpression, - public QDeclarativeDelayedError +class QDeclarativeDeleteWatchable { public: - enum Mode { SharedContext, ExplicitContext }; - - enum EvaluateFlag { RequiresThisObject = 0x01 }; - Q_DECLARE_FLAGS(EvaluateFlags, EvaluateFlag) - - QDeclarativeQtScriptExpression(); - virtual ~QDeclarativeQtScriptExpression(); + inline QDeclarativeDeleteWatchable(); + inline ~QDeclarativeDeleteWatchable(); +private: + friend class QDeclarativeDeleteWatcher; + bool *m_wasDeleted; +}; - QDeclarativeRefCount *dataRef; +class QDeclarativeDeleteWatcher { +public: + inline QDeclarativeDeleteWatcher(QDeclarativeDeleteWatchable *data); + inline ~QDeclarativeDeleteWatcher(); + inline bool wasDeleted() const; +private: + void *operator new(size_t); + bool *m_wasDeleted; + bool m_wasDeletedStorage; + QDeclarativeDeleteWatchable *m_d; +}; - QString expression; - bool extractExpressionFromFunction; +class QDeclarativeJavaScriptExpression : public QDeclarativeAbstractExpression, + public QDeclarativeDelayedError, + public QDeclarativeDeleteWatchable +{ +public: + QDeclarativeJavaScriptExpression(); + virtual ~QDeclarativeJavaScriptExpression(); - Mode expressionFunctionMode; - v8::Persistent<v8::Function> v8function; - v8::Persistent<v8::Object> v8qmlscope; + v8::Local<v8::Value> evaluate(v8::Handle<v8::Function>, bool *isUndefined); - QObject *scopeObject; // Only used in SharedContext + inline bool requiresThisObject() const; + inline void setRequiresThisObject(bool v); + inline bool useSharedContext() const; + inline void setUseSharedContext(bool v); + inline bool notifyOnValueChanged() const; - bool notifyOnValueChange() const; - void setNotifyOnValueChange(bool); - void resetNotifyOnChange(); + void setNotifyOnValueChanged(bool v); + void resetNotifyOnValueChanged(); void setNotifyObject(QObject *, int ); - void setEvaluateFlags(EvaluateFlags flags); - EvaluateFlags evaluateFlags() const; + inline QObject *scopeObject() const; + inline void setScopeObject(QObject *v); - v8::Local<v8::Value> v8value(QObject *secondaryScope, bool *isUndefined); - - class DeleteWatcher { - public: - inline DeleteWatcher(QDeclarativeQtScriptExpression *data); - inline ~DeleteWatcher(); - inline bool wasDeleted() const; - private: - bool *m_wasDeleted; - bool m_wasDeletedStorage; - QDeclarativeQtScriptExpression *m_d; - }; +protected: + inline virtual QStringRef expressionString(); private: - void clearGuards(); - v8::Local<v8::Value> eval(QObject *secondaryScope, bool *isUndefined); - void updateGuards(const QPODVector<QDeclarativeEnginePrivate::CapturedProperty> &properties); + quint32 m_requiresThisObject:1; + quint32 m_useSharedContext:1; + quint32 m_notifyOnValueChanged:1; + quint32 m_dummy:29; - bool trackChange; + QObject *m_scopeObject; + QObject *m_notifyObject; + int m_notifyIndex; - QDeclarativeNotifierEndpoint *guardList; - int guardListLength; + class GuardList { + public: + inline GuardList(); + inline ~GuardList(); + void inline clear(); - QObject *guardObject; - int guardObjectNotifyIndex; - bool *deleted; + typedef QPODVector<QDeclarativeEnginePrivate::CapturedProperty> CapturedProperties; + void updateGuards(QObject *guardObject, int guardObjectNotifyIndex, + const QStringRef &expression, const CapturedProperties &properties); - EvaluateFlags evalFlags; + private: + QDeclarativeNotifierEndpoint *endpoints; + int length; + }; + GuardList guardList; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeQtScriptExpression::EvaluateFlags) - - class QDeclarativeExpression; class QString; -class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeQtScriptExpression +class QDeclarativeExpressionPrivate : public QObjectPrivate, public QDeclarativeJavaScriptExpression { Q_DECLARE_PUBLIC(QDeclarativeExpression) public: @@ -188,12 +199,8 @@ public: v8::Local<v8::Value> v8value(QObject *secondaryScope = 0, bool *isUndefined = 0); - static QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr) { - return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr)); - } - static QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr) { - return expr->q_func(); - } + static inline QDeclarativeExpressionPrivate *get(QDeclarativeExpression *expr); + static inline QDeclarativeExpression *get(QDeclarativeExpressionPrivate *expr); void _q_notify(); virtual void emitValueChanged(); @@ -204,31 +211,123 @@ public: v8::Persistent<v8::Object> *qmlscope = 0); bool expressionFunctionValid:1; + bool extractExpressionFromFunction:1; + + inline virtual QStringRef expressionString(); + + QString expression; + + v8::Persistent<v8::Object> v8qmlscope; + v8::Persistent<v8::Function> v8function; QString url; // This is a QString for a reason. QUrls are slooooooow... int line; QByteArray name; //function name, hint for the debugger + + QDeclarativeRefCount *dataRef; }; -QDeclarativeQtScriptExpression::DeleteWatcher::DeleteWatcher(QDeclarativeQtScriptExpression *data) +QDeclarativeDeleteWatchable::QDeclarativeDeleteWatchable() +: m_wasDeleted(0) +{ +} + +QDeclarativeDeleteWatchable::~QDeclarativeDeleteWatchable() +{ + if (m_wasDeleted) *m_wasDeleted = true; +} + +QDeclarativeDeleteWatcher::QDeclarativeDeleteWatcher(QDeclarativeDeleteWatchable *data) : m_wasDeletedStorage(false), m_d(data) { - if (!m_d->deleted) - m_d->deleted = &m_wasDeletedStorage; - m_wasDeleted = m_d->deleted; + if (!m_d->m_wasDeleted) + m_d->m_wasDeleted = &m_wasDeletedStorage; + m_wasDeleted = m_d->m_wasDeleted; } -QDeclarativeQtScriptExpression::DeleteWatcher::~DeleteWatcher() +QDeclarativeDeleteWatcher::~QDeclarativeDeleteWatcher() { - if (false == *m_wasDeleted && m_wasDeleted == m_d->deleted) - m_d->deleted = 0; + if (false == *m_wasDeleted && m_wasDeleted == m_d->m_wasDeleted) + m_d->m_wasDeleted = 0; } -bool QDeclarativeQtScriptExpression::DeleteWatcher::wasDeleted() const +bool QDeclarativeDeleteWatcher::wasDeleted() const { return *m_wasDeleted; } +bool QDeclarativeJavaScriptExpression::requiresThisObject() const +{ + return m_requiresThisObject; +} + +void QDeclarativeJavaScriptExpression::setRequiresThisObject(bool v) +{ + m_requiresThisObject = v; +} + +bool QDeclarativeJavaScriptExpression::useSharedContext() const +{ + return m_useSharedContext; +} + +void QDeclarativeJavaScriptExpression::setUseSharedContext(bool v) +{ + m_useSharedContext = v; +} + +bool QDeclarativeJavaScriptExpression::notifyOnValueChanged() const +{ + return m_notifyOnValueChanged; +} + +QObject *QDeclarativeJavaScriptExpression::scopeObject() const +{ + return m_scopeObject; +} + +void QDeclarativeJavaScriptExpression::setScopeObject(QObject *v) +{ + m_scopeObject = v; +} + +QStringRef QDeclarativeJavaScriptExpression::expressionString() +{ + return QStringRef(); +} + +QDeclarativeJavaScriptExpression::GuardList::GuardList() +: endpoints(0), length(0) +{ +} + +QDeclarativeJavaScriptExpression::GuardList::~GuardList() +{ + clear(); +} + +void QDeclarativeJavaScriptExpression::GuardList::clear() +{ + delete [] endpoints; + endpoints = 0; + length = 0; +} + +QDeclarativeExpressionPrivate *QDeclarativeExpressionPrivate::get(QDeclarativeExpression *expr) +{ + return static_cast<QDeclarativeExpressionPrivate *>(QObjectPrivate::get(expr)); +} + +QDeclarativeExpression *QDeclarativeExpressionPrivate::get(QDeclarativeExpressionPrivate *expr) +{ + return expr->q_func(); +} + +QStringRef QDeclarativeExpressionPrivate::expressionString() +{ + return QStringRef(&expression); +} + QT_END_NAMESPACE #endif // QDECLARATIVEEXPRESSION_P_H |