bytecodealliance / bytecodealliance/StarlingMonkey

Compile JavaScript to WASM with no networking involved - just reading STDIN and writing to STDOUT

Open
#314 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
288
Forks
57
PR merge metrics
No merged PRs in 30d

Description

I've built Native Messaging hosts using several JavaScript to WASM toolchains, or just executed the WASM inside of the JavaScript engine compiled to WASM in the case of QuickJS.

Here's the protocol and documentation published by Chrome, MDN, Edge, Opera, Safari https://github.com/guest271314/NativeMessagingHosts#native-messaging-documentation. In pertinent part

> Chrome starts each native messaging host in a separate process and communicates with it using standard input (stdin) and standard output (stdout). The same format is used to send messages in both directions; each message is serialized using JSON, UTF-8 encoded and is preceded with 32-bit message length in native byte order. The maximum size of a single message from the native messaging host is 1 MB, mainly to protect Chrome from misbehaving native applications. The maximum size of the message sent to the native messaging host is 64 MiB.

Note, that the IPC communication is _not_ a TTY.

Several examples of JavaScript compiled to WASM and/or embedded and executed within a JavaScript engine compiled to WASM can be found here

- Javy https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_javy.js
- qjs-wasi.wasm https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_qjs_wasi.js
- js2wasm https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_js2wasm.js

to the extent applicable and comparable to JavaScript or TypeScript,

- AssemblyScript https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_assemblyscript.ts

I was referred to StarlingMonkey over here [#general > Embedding JavaScript into QuickJS before compiling to WASM](https://bytecodealliance.zulipchat.com/#narrow/channel/206238-general/topic/Embedding.20JavaScript.20into.20QuickJS.20before.20compiling.20to.20WASM/with/601612770).

To be clear, I am not looking for "a" or "the" JavaScript to WASM toolchain; I'm actively testing, breaking, and vetting JavaScript to WASM toolchains and novel implementations, for research and comparative analysis purposes; without any biases or preferences for any. They all get tested until they break, witout rancor, and without exception or handicap.

Assume

- I have basically zero experience writing WIT
- There is zero networking involved in the JavaScript source code
- I just need to read STDIN and write to STDOUT

Questions:

- In `node` world there is `process.stdin` and `process.stdout`, and even `readFileSync` point to `0` or `/dev/stdin` or `/proc/self/fd/0`, and `/dev/stdout` or `/proc/self/fd/1`, respectively. STDOUT !== WHATWG Console's `console`. What are the specific I/O interfaces StarlingMonkey has implemented?

- The Component Model has the WIT thing - it's own syntax and bassically an entire language itself. What is the minimal WIT that Component Model compilers expect just to read STDIN and write to STDOUT?

- How to compile generic JavaScript that expects to done only read STDIN and write to STDOUT (neither specified in ECMA-262) - with absolutely no networking involved, no `ServiceWorker`-like `fetch()` handler at all, using StarlingMokey's `starling.wasm` or `starling-raw.wasm`?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.