* @brief Runs the one-shot setup() function if the script defines it. */
| 443 | * @brief Runs the one-shot setup() function if the script defines it. |
| 444 | */ |
| 445 | void DataModel::ControlScriptWorker::runSetup() |
| 446 | { |
| 447 | if (!m_loaded || !m_setupFn.isCallable() || !m_watchdog) |
| 448 | return; |
| 449 | |
| 450 | QJSValueList args; |
| 451 | const QJSValue result = m_watchdog->call(m_setupFn, args); |
| 452 | |
| 453 | if (m_watchdog->lastCallTimedOut()) { |
| 454 | Q_EMIT scriptError( |
| 455 | QStringLiteral("Control script setup() exceeded %1 ms budget.").arg(kRuntimeWatchdogMs)); |
| 456 | stop(); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | if (result.isError()) { |
| 461 | Q_EMIT scriptError(QStringLiteral("setup() line %1: %2") |
| 462 | .arg(result.property(QStringLiteral("lineNumber")).toInt()) |
| 463 | .arg(result.toString())); |
| 464 | stop(); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | //-------------------------------------------------------------------------------------------------- |
| 469 | // Compilation |
nothing calls this directly
no test coverage detected