How to implement a Native Mesaging host using d8?

15 views
Skip to first unread message

guest271314

unread,
Oct 22, 2022, 10:09:08 AM10/22/22
to v8-users
I have implemented Native Messaging hosts using QuickJS, Deno, and Node.js where it is possible to read stdin and write to stdout. 

How would you go about implementing a Native Messaging host using d8?

Ben Noordhuis

unread,
Oct 22, 2022, 5:10:59 PM10/22/22
to v8-u...@googlegroups.com
On Sat, Oct 22, 2022 at 4:09 PM guest271314 <guest...@gmail.com> wrote:
>
> I have implemented Native Messaging hosts using QuickJS, Deno, and Node.js where it is possible to read stdin and write to stdout.
>
> How would you go about implementing a Native Messaging host using d8?

I probably wouldn't. :-)

d8 exists to power V8's test suite. It's not really intended as a
standalone application.

guest271314

unread,
Oct 22, 2022, 8:20:33 PM10/22/22
to v8-u...@googlegroups.com
I know. Node.js is to bloated to justify using other than for preference. And there is no way that I am aware of to build `node` executable with only standard JavaScript implementation, Process, File system modules https://github.com/guest271314/native-messaging-nodejs/blob/main/nm_nodejs.js - without all the bloat. 

I must test and ask if the requirement is possible before abandoning the concept. It should be possible.

This is what I have so far, which exits early without sending the message to client.

d8.js
    #!/usr/bin/env -S ./d8 --enable-os-system --experimental-web-snapshots ./test.js

test.js
    const json = JSON.stringify("test");
    let header = Uint32Array.from({
       length: 4,
     }, (_, index) => (json.length >> (index * 8)) & 0xff
    );
    let output = new Uint8Array(header.length + json.length);
    output.set(header, 0);
    write(JSON.stringify(header));
    write(json);

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/ZCE_WMSBBHs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAHQurc_XkTm2ODVwg79qEOCLmo6uEdoTJnxZf_VB6-51A7rY2A%40mail.gmail.com.

guest271314

unread,
Oct 22, 2022, 9:58:10 PM10/22/22
to v8-u...@googlegroups.com
I am not sure how to test the following in d8.cc. 

Ideally some kind of static code analyzer or optimizer could scan existing Node.js code and identify only the modules used, note them, then build v8 and d8 (and node executable) to do only the task written in JavaScript source code. 

Unfortunately deno compile includes the entire deno executable in the compiled executable as well.

2582 Local<String> Shell::ReadFromStdin(Isolate* isolate) {
// ...
and
2552 void Shell::Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
  WriteAndFlush(stdout, args);
}

On Sat, Oct 22, 2022 at 2:11 PM Ben Noordhuis <in...@bnoordhuis.nl> wrote:
Reply all
Reply to author
Forward
0 new messages