QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isUndefined) { Q_Q(QDeclarativeExpression); QVariant rv; if (!q->engine()) { qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context"); return rv; } if (data->expression.isEmpty()) return rv; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(q->engine()); QDeclarativeExpression *lastCurrentExpression = ep->currentExpression; bool lastCaptureProperties = ep->captureProperties; QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties; ep->capturedProperties.copyAndClear(lastCapturedProperties); ep->currentExpression = q; ep->captureProperties = data->trackChange; // This object might be deleted during the eval QDeclarativeExpressionData *localData = data; localData->addref(); rv = evalQtScript(secondaryScope, isUndefined); ep->currentExpression = lastCurrentExpression; ep->captureProperties = lastCaptureProperties; // Check if we were deleted if (localData->q) { if ((!data->trackChange || !ep->capturedProperties.count()) && data->guardList) { clearGuards(); } else if(data->trackChange) { updateGuards(ep->capturedProperties); } } localData->release(); lastCapturedProperties.copyAndClear(ep->capturedProperties); return rv; }
QScriptValue QDeclarativeQtScriptExpression::scriptValue(QObject *secondaryScope, bool *isUndefined) { Q_ASSERT(context() && context()->engine); Q_ASSERT(!trackChange || (guardObject && guardObjectNotifyIndex != -1)); if (!expressionFunction.isValid()) { if (isUndefined) *isUndefined = true; return QScriptValue(); } DeleteWatcher watcher(this); QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(context()->engine); bool lastCaptureProperties = ep->captureProperties; QPODVector<QDeclarativeEnginePrivate::CapturedProperty> lastCapturedProperties; ep->captureProperties = trackChange; ep->capturedProperties.copyAndClear(lastCapturedProperties); QScriptValue value = eval(secondaryScope, isUndefined); if (!watcher.wasDeleted() && trackChange) { if (ep->capturedProperties.count() == 0) { if (guardList) clearGuards(); } else { updateGuards(ep->capturedProperties); } } lastCapturedProperties.copyAndClear(ep->capturedProperties); ep->captureProperties = lastCaptureProperties; return value; }