Skip to content

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

@guest271314

Description

@guest271314

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

to the extent applicable and comparable to JavaScript or TypeScript,

I was referred to StarlingMonkey over here #general > Embedding JavaScript into QuickJS before compiling to WASM.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions