JavaScriptEngine.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/extensions/js/JavaScriptEngine.kt
1package eu.friedcutlet.yokan.services.extensions.js23fun interface JavaScriptMessageBridge {4 fun sendMessage(channel: String, payload: String): String5}67/**8 * A single JavaScript context. [evaluate] blocks until the script (including synchronous host9 * bridge calls) finishes, so callers run it on a background dispatcher; [close] must not block.10 * The engine interrupts the script once [isCancelled] returns true.11 */12interface JavaScriptEngine {13 fun evaluate(script: String, isCancelled: () -> Boolean = { false }): String1415 fun close()16}1718/**19 * JavaScript engine for extension sources. QuickJS (zipline) on20 * Android/desktop/iOS; unsupported on the browser, where zipline has no21 * wasm artifact — the actual throws from `evaluate`.22 */23expect fun createJavaScriptEngine(bridge: JavaScriptMessageBridge): JavaScriptEngine24