* @brief Calls fn(args) under the watchdog with no explicit `this`. */
| 95 | * @brief Calls fn(args) under the watchdog with no explicit `this`. |
| 96 | */ |
| 97 | QJSValue DataModel::JsWatchdog::call(QJSValue& fn, const QJSValueList& args) |
| 98 | { |
| 99 | Q_ASSERT(fn.isCallable()); |
| 100 | Q_ASSERT(m_engine != nullptr); |
| 101 | |
| 102 | m_lastTimedOut = false; |
| 103 | arm(); |
| 104 | const auto result = fn.call(args); |
| 105 | disarm(); |
| 106 | |
| 107 | if (m_engine->isInterrupted()) [[unlikely]] { |
| 108 | m_engine->setInterrupted(false); |
| 109 | m_lastTimedOut = true; |
| 110 | qWarning().noquote() << "[JsWatchdog]" << (m_tag.isEmpty() ? QStringLiteral("script") : m_tag) |
| 111 | << "timed out after" << m_budgetMs << "ms -- interrupted"; |
| 112 | } |
| 113 | |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @brief Calls fn.callWithInstance(thisObj, args) under the watchdog. |