43 #include "private/qdeclarativeexpression_p.h" 45 #include "private/qdeclarativeengine_p.h" 46 #include "private/qdeclarativecontext_p.h" 47 #include "private/qdeclarativerewrite_p.h" 48 #include "private/qdeclarativecompiler_p.h" 49 #include "private/qdeclarativeglobalscriptclass_p.h" 51 #include <QtCore/qdebug.h> 52 #include <QtScript/qscriptprogram.h> 54 #include <private/qscriptdeclarativeclass_p.h> 75 : dataRef(0), expressionFunctionMode(ExplicitContext), scopeObject(0), trackChange(false),
76 guardList(0), guardListLength(0), guardObject(0), guardObjectNotifyIndex(-1), deleted(0)
88 : expressionFunctionValid(true), line(-1)
135 int progIdx = *(exprData);
136 bool isSharedProgram = progIdx & 0x80000000;
137 progIdx &= 0x7FFFFFFF;
143 if (isSharedProgram) {
182 scriptContext->
pushScope(*contextObject);
200 scriptContext->
pushScope(*contextObject);
267 d->init(ctxt, expr, rc, me, url, lineNumber);
303 d->init(ctxt, expression, scope);
316 d->init(ctxt, expression, scope);
329 d->init(ctxt, func, scope);
350 return d->context()?
d->context()->engine:0;
370 return d->expression;
380 d->resetNotifyOnChange();
382 d->expressionFunctionValid =
false;
420 trackChange = notify;
421 if (!notify && guardList)
432 if (guardList) clearGuards();
434 if (!
object || notifyIndex == -1) {
438 guardObject = object;
439 guardObjectNotifyIndex = notifyIndex;
457 Q_ASSERT(!trackChange || (guardObject && guardObjectNotifyIndex != -1));
459 if (!expressionFunction.isValid()) {
460 if (isUndefined) *isUndefined =
true;
478 if (guardList) clearGuards();
507 bool isShared = (expressionFunctionMode == SharedContext);
519 if (evalFlags & RequiresThisObject)
551 Q_ASSERT(guardObjectNotifyIndex != -1);
553 if (properties.
count() != guardListLength) {
556 for (
int ii = 0; ii <
qMin(guardListLength, properties.
count()); ++ii)
557 guardList[ii].copyAndClear(newGuardList[ii]);
560 guardList = newGuardList;
561 guardListLength = properties.
count();
564 bool outputWarningHeader =
false;
565 bool noChanges =
true;
566 for (
int ii = 0; ii < properties.
count(); ++ii) {
570 guard.
target = guardObject;
581 bool existing =
false;
582 for (
int jj = 0; !existing && jj < ii; ++jj)
583 if (guardList[jj].isConnected(
property.notifier))
595 }
else if (
property.notifyIndex != -1) {
603 bool existing =
false;
604 for (
int jj = 0; !existing && jj < ii; ++jj)
617 if (!outputWarningHeader) {
618 outputWarningHeader =
true;
620 <<
"depends on non-NOTIFYable properties:";
623 const QMetaObject *metaObj =
property.object->metaObject();
633 if (!expressionFunctionValid) {
641 scriptContext->
pushScope(expressionContext);
649 expressionFunction = scriptEngine->
evaluate(code, url, line);
652 expressionFunctionMode = ExplicitContext;
653 expressionFunctionValid =
true;
664 qWarning(
"QDeclarativeExpression: Attempted to evaluate an expression in an invalid context");
685 return d->value(0, valueIsUndefined);
695 return d->notifyOnValueChange();
717 d->setNotifyOnValueChange(notifyOnChange);
760 return d->scopeObject;
772 return d->error.isValid();
827 emit q->valueChanged();
831 : m_context(0), m_prevExpression(0), m_nextExpression(0)
881 #include <moc_qdeclarativeexpression.cpp> The QVariant class acts like a union for the most common Qt data types.
const T & at(int idx) const
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
The QScriptContext class represents a Qt Script function invocation.
bool isUndefined() const
Returns true if this QScriptValue is of the primitive type Undefined; otherwise returns false...
void setEvaluateFlags(EvaluateFlags flags)
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
QScriptValue expressionContext
void setName(const QByteArray &name)
#define QT_END_NAMESPACE
This macro expands to.
void setDescription(const QString &)
Sets the error description.
QObject * setOverrideObject(QScriptValue &, QObject *)
QDeclarativeEngine * engine
QDeclarativeAbstractExpression()
QDeclarativeEngine * engine() const
Returns the QDeclarativeEngine this expression is associated with, or 0 if there is no association or...
void setExpression(const QString &)
Set the expression to expression.
QDeclarativeAbstractExpression ** m_prevExpression
void setNotifyObject(QObject *, int)
bool isError() const
Returns true if this QScriptValue is an object of the Error class; otherwise returns false...
static int QDeclarativeExpression_notifyIdx
QDeclarativeExpressionPrivate()
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QDeclarativeGlobalScriptClass * globalClass
void setColumn(int)
Sets the error column number.
QScriptValue scriptValue(QObject *secondaryScope=0, bool *isUndefined=0)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QVariant evaluate(bool *valueIsUndefined=0)
Evaulates the expression, returning the result of the evaluation, or an invalid QVariant if the expre...
void popContext()
Pops the current execution context and restores the previous one.
void copyAndClear(QPODVector< T, Increment > &other)
QDeclarativeAbstractExpression * expressions
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
void connect(QObject *source, int sourceSignal)
The QObject class is the base class of all Qt objects.
QDeclarativeExpression()
Create an invalid QDeclarativeExpression.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
The QChar class provides a 16-bit Unicode character.
static QString fromRawData(const QChar *, int size)
Constructs a QString that uses the first size Unicode characters in the array unicode.
QScriptValue expressionFunction
void init(QDeclarativeContextData *, const QString &, QObject *)
void setNotifyOnValueChanged(bool)
Sets whether the valueChanged() signal is emitted when the expression's evaluated value changes...
QScriptValue newQObject(QObject *, int type=QMetaType::QObjectStar)
QVariant scriptValueToVariant(const QScriptValue &, int hint=QVariant::Invalid)
QDeclarativeDelayedError * nextError
const QScriptValue & staticGlobalObject() const
virtual ~QDeclarativeExpression()
Destroy the QDeclarativeExpression instance.
QDeclarativeRefCount * dataRef
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QScriptValue scriptValue(QObject *secondaryScope, bool *isUndefined)
QScriptValue newSharedContext()
static QScriptValue evalInObjectScope(QDeclarativeContextData *, QObject *, const QString &, const QString &, int, QScriptValue *)
QDeclarativeScriptEngine scriptEngine
QDeclarativeAbstractExpression * m_nextExpression
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
const T & at(int i) const
Returns the item at index position i in the list.
void setNotifyOnValueChange(bool)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QList< QScriptProgram * > cachedPrograms
The QDeclarativeError class encapsulates a QML error.
virtual ~QDeclarativeQtScriptExpression()
QDeclarativeContext * context() const
Returns the QDeclarativeContext this expression is associated with, or 0 if there is no association o...
bool notifyOnValueChanged() const
Returns true if the valueChanged() signal is emitted when the expression's evaluated value changes...
QDeclarativeContextData * m_context
int uncaughtExceptionLineNumber() const
Returns the line number where the last uncaught exception occurred.
QScriptValue newContext(QDeclarativeContextData *, QObject *=0)
QList< QScriptValue * > cachedClosures
QDeclarativeContextData * sharedContext
QDeclarativeNotifierEndpoint * guardList
void clearError()
Clear any expression errors.
bool expressionFunctionValid
QDeclarativeObjectScriptClass * objectClass
QString expression() const
Returns the expression string.
void setLine(int)
Sets the error line number.
virtual void emitValueChanged()
bool hasError() const
Returns true if the last call to evaluate() resulted in an error, otherwise false.
int lineNumber() const
Returns the source file line number for this expression.
Mode expressionFunctionMode
QObject * scopeObject() const
Returns the expression's scope object, if provided, otherwise 0.
QDeclarativeDelayedError ** prevError
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeQtScriptExpression()
QDeclarativeContext * asQDeclarativeContext()
QDeclarativeDelayedError * erroredBindings
QObject * parent() const
Returns a pointer to the parent object.
QString sourceFile() const
Returns the source file URL for this expression.
void setContext(QDeclarativeContextData *)
virtual ~QDeclarativeAbstractExpression()
QDeclarativeContextData * context() const
void clearExceptions()
Clears any uncaught exceptions in this engine.
The QDeclarativeContext class defines a context within a QML engine.
static const QCssKnownValue properties[NumProperties - 1]
void setSourceLocation(const QString &fileName, int line)
Set the location of this expression to line of url.
void updateGuards(const QPODVector< QDeclarativeEnginePrivate::CapturedProperty, 16 > &properties)
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
QVariant property(const char *name) const
Returns the value of the object's name property.
QDeclarativeEngine * engine() const
Return the context's QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the QDeclar...
The QScriptProgram class encapsulates a Qt Script program.
~QDeclarativeExpressionPrivate()
QScriptValue eval(QObject *secondaryScope, bool *isUndefined)
QVariant value(QObject *secondaryScope=0, bool *isUndefined=0)
EvaluateFlags evaluateFlags() const
void resetNotifyOnChange()
QDeclarativeError error() const
Return any error from the last call to evaluate().
The QDeclarativeExpression class evaluates JavaScript in a QML context.
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context's scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
bool addError(QDeclarativeEnginePrivate *)
The QScriptValue class acts as a container for the Qt Script data types.
static QString fileName(const QString &fileUrl)
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this' object in the function call...
bool notifyOnValueChange() const
QPODVector< CapturedProperty, 16 > capturedProperties
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...
The QList class is a template class that provides lists.
QDeclarativeContextScriptClass * contextClass
static QDeclarativeContextData * get(QDeclarativeContext *context)