* @brief Runs the JS parse function over a binary frame. */
| 348 | * @brief Runs the JS parse function over a binary frame. |
| 349 | */ |
| 350 | QList<QStringList> DataModel::JsScriptEngine::parseBinary(const QByteArray& frame) |
| 351 | { |
| 352 | Q_ASSERT(!frame.isEmpty()); |
| 353 | |
| 354 | if (!m_parseFunction.isCallable() || m_disabled) |
| 355 | return {}; |
| 356 | |
| 357 | QJSValue jsArray; |
| 358 | if (m_hexToArray.isCallable()) [[likely]] { |
| 359 | QJSValueList hexArgs; |
| 360 | hexArgs << QString::fromLatin1(frame.toHex()); |
| 361 | jsArray = m_hexToArray.call(hexArgs); |
| 362 | |
| 363 | if (jsArray.isError()) [[unlikely]] { |
| 364 | qWarning() << "[JsScriptEngine] hex helper error:" << jsArray.property("message").toString(); |
| 365 | jsArray = QJSValue(); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if (!jsArray.isArray()) { |
| 370 | jsArray = m_engine.newArray(frame.size()); |
| 371 | const auto* data = reinterpret_cast<const quint8*>(frame.constData()); |
| 372 | for (int i = 0; i < frame.size(); ++i) |
| 373 | jsArray.setProperty(i, data[i]); |
| 374 | } |
| 375 | |
| 376 | QJSValueList args; |
| 377 | args << jsArray; |
| 378 | const auto jsResult = guardedCall(args); |
| 379 | |
| 380 | if (m_watchdog.lastCallTimedOut()) [[unlikely]] { |
| 381 | qWarning() << "[JsScriptEngine] parse() timed out after" << kRuntimeWatchdogMs << "ms"; |
| 382 | (void)noteTimeoutAndCheckDisabled(0); |
| 383 | return {}; |
| 384 | } |
| 385 | |
| 386 | if (jsResult.isError()) [[unlikely]] { |
| 387 | qWarning() << "[JsScriptEngine] JS error:" << jsResult.property("message").toString(); |
| 388 | return {}; |
| 389 | } |
| 390 | |
| 391 | resetTimeoutCounter(); |
| 392 | return convertJsResult(jsResult); |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * @brief Evaluates the script and reports any syntax errors, arming the watchdog |
nothing calls this directly
no test coverage detected