73QV4::ReturnedValue QQmlDelayedCallQueue::addUniquelyAndExecuteLater(QV4::ExecutionEngine *engine, QQmlV4FunctionPtr args)
75 QQmlDelayedCallQueue *self = engine->delayedCallQueue();
77 QV4::Scope scope(engine);
78 if (args->length() == 0)
79 THROW_GENERIC_ERROR(
"Qt.callLater: no arguments given");
81 QV4::ScopedValue firstArgument(scope, (*args)[0]);
83 const QV4::FunctionObject *func = firstArgument->as<QV4::FunctionObject>();
86 THROW_GENERIC_ERROR(
"Qt.callLater: first argument not a function or signal");
88 std::pair<QObject *,
int> functionData = QV4::QObjectMethod::extractQtMethod(func);
90 QVector<DelayedFunctionCall>::Iterator iter;
91 if (functionData.second != -1) {
93 iter = self->m_delayedFunctionCalls.begin();
94 while (iter != self->m_delayedFunctionCalls.end()) {
95 DelayedFunctionCall& dfc = *iter;
96 std::pair<QObject *,
int> storedFunctionData = QV4::QObjectMethod::extractQtMethod(dfc.m_function.as<QV4::FunctionObject>());
97 if (storedFunctionData == functionData) {
104 iter = self->m_delayedFunctionCalls.begin();
105 while (iter != self->m_delayedFunctionCalls.end()) {
106 DelayedFunctionCall& dfc = *iter;
107 if (firstArgument->asReturnedValue() == dfc.m_function.value()) {
114 const bool functionAlreadyStored = (iter != self->m_delayedFunctionCalls.end());
115 if (functionAlreadyStored) {
116 DelayedFunctionCall dfc = *iter;
117 self->m_delayedFunctionCalls.erase(iter);
118 self->m_delayedFunctionCalls.append(dfc);
120 self->m_delayedFunctionCalls.append(QV4::PersistentValue(engine, firstArgument));
123 DelayedFunctionCall& dfc = self->m_delayedFunctionCalls.last();
124 if (dfc.m_objectGuard.isNull()) {
125 if (functionData.second != -1) {
127 dfc.m_objectGuard = QQmlGuard<QObject>(functionData.first);
128 dfc.m_guarded =
true;
129 }
else if (
const auto *js = func->as<QV4::JavaScriptFunctionObject>();
130 js && js->scope()->type == QV4::Heap::ExecutionContext::Type_QmlContext) {
131 QV4::QmlContext::Data *g =
static_cast<QV4::QmlContext::Data *>(js->scope());
132 Q_ASSERT(g->qml()->scopeObject);
133 dfc.m_objectGuard = QQmlGuard<QObject>(g->qml()->scopeObject);
134 dfc.m_guarded =
true;
137 self->storeAnyArguments(dfc, args, 1, engine);
139 if (!self->m_callbackOutstanding) {
140 self->m_tickedMethod.invoke(self, Qt::QueuedConnection);
141 self->m_callbackOutstanding =
true;
143 return QV4::Encode::undefined();
146void QQmlDelayedCallQueue::storeAnyArguments(DelayedFunctionCall &dfc, QQmlV4FunctionPtr args,
int offset, QV4::ExecutionEngine *engine)