74QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(QV4::ExecutionEngine *engine, QQmlV4FunctionPtr args)
76 QQmlDelayedCallQueue *self = engine->delayedCallQueue();
78 QV4::Scope scope(engine);
79 if (args->length() == 0)
80 THROW_GENERIC_ERROR(
"Qt.callLater: no arguments given");
82 QV4::ScopedValue firstArgument(scope, (*args)[0]);
84 const QV4::FunctionObject *func = firstArgument->as<QV4::FunctionObject>();
87 THROW_GENERIC_ERROR(
"Qt.callLater: first argument not a function or signal");
89 std::pair<QObject *,
int> functionData = QV4::QObjectMethod::extractQtMethod(func);
91 QList<DelayedFunctionCall>::Iterator iter;
92 if (functionData.second != -1) {
94 iter = self->m_delayedFunctionCalls.begin();
95 while (iter != self->m_delayedFunctionCalls.end()) {
96 DelayedFunctionCall& dfc = *iter;
97 std::pair<QObject *,
int> storedFunctionData = QV4::QObjectMethod::extractQtMethod(dfc.m_function.as<QV4::FunctionObject>());
98 if (storedFunctionData == functionData) {
105 iter = self->m_delayedFunctionCalls.begin();
106 while (iter != self->m_delayedFunctionCalls.end()) {
107 DelayedFunctionCall& dfc = *iter;
108 if (firstArgument->asReturnedValue() == dfc.m_function.value()) {
115 const bool functionAlreadyStored = (iter != self->m_delayedFunctionCalls.end());
116 if (functionAlreadyStored) {
117 DelayedFunctionCall dfc = *iter;
118 self->m_delayedFunctionCalls.erase(iter);
119 self->m_delayedFunctionCalls.append(dfc);
121 self->m_delayedFunctionCalls.append(QV4::PersistentValue(engine, firstArgument));
124 DelayedFunctionCall& dfc = self->m_delayedFunctionCalls.last();
125 if (dfc.m_objectGuard.isNull()) {
126 if (functionData.second != -1) {
128 dfc.m_objectGuard = QQmlGuard<QObject>(functionData.first);
129 dfc.m_guarded =
true;
130 }
else if (
const auto *js = func->as<QV4::JavaScriptFunctionObject>();
131 js && js->scope()->type == QV4::Heap::ExecutionContext::Type_QmlContext) {
132 QV4::QmlContext::Data *g =
static_cast<QV4::QmlContext::Data *>(js->scope());
133 Q_ASSERT(g->qml()->scopeObject);
134 dfc.m_objectGuard = QQmlGuard<QObject>(g->qml()->scopeObject);
135 dfc.m_guarded =
true;
138 self->storeAnyArguments(dfc, args, 1, engine);
140 if (!self->m_callbackOutstanding) {
141 self->m_tickedMethod.invoke(self, Qt::QueuedConnection);
142 self->m_callbackOutstanding =
true;
144 return QV4::Encode::undefined();
147void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, QQmlV4FunctionPtr args,
int offset, QV4::ExecutionEngine *engine)