I understand ECMA-262 doesn't specify reading stardard input or writing standard output. I think that is an omission that is observable by every JavaScript runtime implementing stdio differently. E.g.,
https://github.com/guest271314/NativeMessagingHosts/blob/main/nm_host.js#L7C1-L39C2const runtime = navigator.userAgent;
// ...
let readable, writable, exit, args;
if (runtime.startsWith("Deno")) {
({ readable } = Deno.stdin);
({ writable } = Deno.stdout);
({ exit } = Deno);
({ args } = Deno);
}
if (runtime.startsWith("Node")) {
const { Duplex } = await import("node:stream");
({ readable } = Duplex.toWeb(process.stdin));
({ writable } = Duplex.toWeb(process.stdout));
({ exit } = process);
({ argv: args } = process);
}
if (runtime.startsWith("Bun")) {
readable = Bun.file("/dev/stdin").stream();
writable = new WritableStream({
async write(value) {
await Bun.write(Bun.stdout, value);
},
}, new CountQueuingStrategy({ highWaterMark: Infinity }));
({ exit } = process);
({ argv: args } = Bun);
}
I've tried readline().
This works for writing to stdout
writeFile("/proc/self/fd/1", messageLength);
writeFile("/proc/self/fd/1", message);
The program that is supplying stdin is Chromium 127.
I'm working on v8 (d8) if you prefer and Spidermonkey Native Messaging hosts.
I've written Node.js, Deno, Bun, QuickJS, txiki.js Native Messaging hosts, respoectively, and a single script that is runtime agnostic between Deno, Node.js, and Bun.
It sure would be useful if I/O for JavaScript got standardized.
In QuickJS we can import C compiled shared object files into the runtime.
I've got a C++ Native Messaging host. How can this be used in v8 (d8) without building v8?
Thanks.