Proposal: Use web worker to run wasm binaries
Background
Currently there is no way to terminate a running C / C++ program in WKWebView as wasm in web is single-threaded and blocking. Calling WKWebView.reload() or releasing the reference to the existing web view doesn't do anything.
Proposal
I propose to run binaries in web workers and use SharedArrayBuffer and worker.postMessage() to facilitate sync / async communication between native code and the web worker.
Caveat
Due to a security requirement for using SharedArrayBuffer, the following headers from the web server are required to use the API. As we are currently loading the resources using WKWebView.loadFileURL, there doesn't seem to be a way to set custom headers. From what I've tested, the api is blocked by default when loading a local file. We probably need to serve the files with a local web server (GCDWebServer) instead.
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
I would... But I don't know Swift
I would... But I don't know Swift
This is mainly a JavaScript implementation.
I would... But I don't know Swift
This is mainly a JavaScript implementation.
Oh, well, I know JS, so I'll see how much I can help out.
The app is an iOS app, therefore, it does require Swift, not JS to add. You can’t make an iOS/iPadOS app effectively, unless it’s a PWA.
The app is an iOS app, therefore, it does require Swift, not JS to add. You can’t make an iOS/iPadOS app effectively, unless it’s a PWA.
On Thu, Oct 20, 2022 at 19:48, hg0428 @.***> wrote:
I would... But I don't know Swift
This is mainly a JavaScript implementation.
Oh, well, I know JS, so I'll see how much I can help out.
— Reply to this email directly, view it on GitHub https://github.com/thebaselab/codeapp/issues/612#issuecomment-1286283101, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANI5RBNHG7Y23OVJHV3BTUTWEHK6LANCNFSM6AAAAAARIBEPTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
-- Best Wishes, Luke Batema (JavaScript and Front End Developer, Creator of cubelang)
Well then, maybe I can't help much.
The app is an iOS app, therefore, it does require Swift, not JS to add. You can’t make an iOS/iPadOS app effectively, unless it’s a PWA. On Thu, Oct 20, 2022 at 19:48, hg0428 @.***> wrote:
I would... But I don't know Swift This is mainly a JavaScript implementation. Oh, well, I know JS, so I'll see how much I can help out. — Reply to this email directly, view it on GitHub #612 (comment), or unsubscribe https://github.com/notifications/unsubscribe-auth/ANI5RBNHG7Y23OVJHV3BTUTWEHK6LANCNFSM6AAAAAARIBEPTQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
-- Best Wishes, Luke Batema (JavaScript and Front End Developer, Creator of cubelang)
Well then, maybe I can't help much.
You could still help. This issue is about using a JS WebWorker and a JS SharedArrayBuffer to move WebAssembly into another thread, as I understand, and the only Swift code required is to move everything to a web server instead of just serving a local file.
Alternative way to terminate a running wasm: https://github.com/ewasm/wasm-metering
While working on adding stdc++.h, I noticed this in signal.h:
#ifndef _WASI_EMULATED_SIGNAL
#error "wasm lacks signal support; to enable minimal signal emulation, \
compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal"
#else
#ifndef _SIGNAL_H
#define _SIGNAL_H
TODO: Investigate if emulated signal can be used to terminate programs.