标签云

微信群

扫码加入我们

WeChat QR Code

I'm looking to writing some C bindings to V8, and so I'll need to figure out the memory layout of the various primitive JavaScript types. Is there any documentation on these details anywhere?


Are you asking about objects or primitive values now?

2019年04月22日31分18秒

Primitives + Object, technically speaking.

2019年04月22日31分18秒

Are you asking for a nodejs-c binding or for developing directly against v8? There is documentation for both both in different places -- and you DON'T want to access the memory directly in either case, but use the API

2019年04月22日31分18秒

If a C binding exists, that would save me a lot of time, but I couldn't find one. I want to do things like "take a String from JavaScript and do work on it in C", and was assuming I would have to write a C++ V8 wrapper that exposes C functions, since V8 is in C++.

2019年04月22日31分18秒

(The eventual intention is to use this with Node)

2019年04月22日31分18秒

excellent, thank you a ton. For my use case, I'm mostly interested in just copying out the data immediately rather than worrying about keeping objects alive, specifically because I was worried about GC rooting and other things you mention.

2019年04月22日31分18秒

SteveKlabnik well, V8 api is explicitly designed this way to prevent any worries about rooting - that's why all objects are always rooted (unless you violate HandleScope nesting and pass around invalid handles)

2019年04月22日31分18秒

My question is about how to write C extensions, not C++.

2019年04月22日31分18秒

You will have to wrap your C in C++

2019年04月22日31分18秒

Yes. In order to do that, I need to know things like the memory layout of the structs, hence the question.

2019年04月22日31分18秒

Correct. Which is why I need to understand these details, so I know how to turn those C structures into the correct ones V8 uses.

2019年04月22日31分18秒

Keep in mind also that the V8 API changes fairly frequently.So even if you were somehow able to create C structs that mapped to the V8 internal goodies, they can change release-to-release.I guess node-ffi isn't going to help, but ... passing it along just in case.There's also nan - tries to abstract away the shifting V8 API for node developers.

2019年04月22日31分18秒