MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / installJS

Method installJS

app/src/DataModel/Scripting/ScriptApiCall.cpp:748–765  ·  view source on GitHub ↗

* @brief Installs apiCall() / apiCallList() into a QJSEngine, reusing the bridge if attached. */

Source from the content-addressed store, hash-verified

746 * @brief Installs apiCall() / apiCallList() into a QJSEngine, reusing the bridge if attached.
747 */
748void DataModel::ScriptApiCall::installJS(QJSEngine* js, int sourceId)
749{
750 Q_ASSERT(js);
751
752 auto global = js->globalObject();
753 auto existingProp = global.property(QStringLiteral("__ss_bridge"));
754 if (existingProp.isQObject()
755 && qobject_cast<DataModel::ScriptApiCallBridge*>(existingProp.toQObject()))
756 return;
757
758 auto* bridge = new DataModel::ScriptApiCallBridge(sourceId, js);
759 auto bridgeVal = js->newQObject(bridge);
760 global.setProperty(QStringLiteral("__ss_bridge"), bridgeVal);
761
762 static const QByteArray sdk = loadSdk(QStringLiteral(":/api/SerialStudio.js"));
763 if (!sdk.isEmpty())
764 js->evaluate(QString::fromUtf8(sdk));
765}
766
767/**
768 * @brief Installs the convenience host bridges (no apiCall bridge, no SDK eval).

Callers

nothing calls this directly

Calls 3

loadSdkFunction · 0.85
isEmptyMethod · 0.80
evaluateMethod · 0.45

Tested by

no test coverage detected