> V8 itself doesn't do anything with stdin, because ECMAScript doesn't.

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-L39C2

const 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.

> You can extend it for your needs if you want,

 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.

On Thu, Jun 13, 2024 at 1:58 AM Jakob Kummerow <jkumme...@chromium.org>
wrote:

> V8 itself doesn't do anything with stdin, because ECMAScript doesn't.
>
> It's up to embedders of V8 to provide integration with desired I/O
> channels. The d8 shell (which I think is what JSVU gives you) does
> implement stdin reading via the readline() function, and in an
> interactive session it works for me:
>
> $ /usr/bin/env -S out/x64.release/d8
> V8 version 12.8.0 (candidate)
> d8> var a = readline()
> hello world                          <<< This is what I typed
> undefined
> d8> a
> "hello world"
>
> Piping JS programs into d8 also works, though the printed output is a bit
> weird in that case:
>
> $ echo "2+3" | /usr/bin/env -S out/x64.release/d8
> V8 version 12.8.0 (candidate)
> d8> 5
> d8>
>
> That said, d8 is intended for our team's testing and development needs, it
> doesn't aim or claim to be a general-purpose shell. You can extend it for
> your needs if you want, or you can take a look at more feature-rich V8
> embedders such as Node.
>
>
> On Thu, Jun 13, 2024 at 7:51 AM guest271314 <guest271...@gmail.com> wrote:
>
>> I'm launching `v8` from a non-TTY program, e.g.,
>>
>>     #!/usr/bin/env -S /home/user/.jsvu/engines/v8/v8
>>
>>
>> readline() is not reading STDOUT from the launching process.
>>
>> read() isn't reading from /dev/stdin or /proc/self/fd/0 either.
>>
>> How to read from /dev/stdin and /proc/self/fd/0 in v8?
>>
>> --
>> --
>> v8-dev mailing list
>> v8-dev@googlegroups.com
>> http://groups.google.com/group/v8-dev
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to v8-dev+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/v8-dev/1c15ed97-8fe6-49f6-a7a4-7420dffb7923n%40googlegroups.com
>> <https://groups.google.com/d/msgid/v8-dev/1c15ed97-8fe6-49f6-a7a4-7420dffb7923n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> --
> v8-dev mailing list
> v8-dev@googlegroups.com
> http://groups.google.com/group/v8-dev
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-dev/CAKSzg3TTqmU5so4Pt%2BEnnGFj3YyYH_H6JtKWhWfzX20xeWs8oQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/v8-dev/CAKSzg3TTqmU5so4Pt%2BEnnGFj3YyYH_H6JtKWhWfzX20xeWs8oQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- 
You received this message because you are subscribed to the Google Groups 
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/CA%2BsyWAP_apwRHCc_rqg1OGsVRomdVb_Kss5s8xogr1W1U3T%2BGg%40mail.gmail.com.

Reply via email to