How to implement a Native Mesaging host using d8?

閲覧: 15 回
最初の未読メッセージにスキップ

guest271314

未読、
2022/10/22 10:09:082022/10/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

未読、
2022/10/22 17:10:592022/10/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

未読、
2022/10/22 20:20:332022/10/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

未読、
2022/10/22 21:58:102022/10/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:
全員に返信
投稿者に返信
転送
新着メール 0 件