admin管理员组文章数量:1304953
I'm a new er in Google V8 and Javascript, and I'm trying to add a new class to Javascript using C++.
I've finished some work using Webkit's V8 binding, references are: webkit idl and v8 binding
Now I want to integrate it into V8 engine directly, by modifying V8's code instead of simply using V8's api to make a extension. In other words, I want to add a new class just like Array type in Javascript, using the same implementation mechanism.
I've searched the Internet, including docs in Google, but have only seen guides on embedding V8 with native code.
Where can I find guides about modifying V8's code?
Or where can I find docs about V8's design architecture?
Or can anyone describe how V8 implements the Array type in C++?
Thanks a lot.
I'm a new er in Google V8 and Javascript, and I'm trying to add a new class to Javascript using C++.
I've finished some work using Webkit's V8 binding, references are: webkit idl and v8 binding
Now I want to integrate it into V8 engine directly, by modifying V8's code instead of simply using V8's api to make a extension. In other words, I want to add a new class just like Array type in Javascript, using the same implementation mechanism.
I've searched the Internet, including docs in Google, but have only seen guides on embedding V8 with native code.
Where can I find guides about modifying V8's code?
Or where can I find docs about V8's design architecture?
Or can anyone describe how V8 implements the Array type in C++?
Thanks a lot.
Share Improve this question asked Dec 18, 2012 at 9:18 jeanjean 1721 silver badge8 bronze badges 1- Hooking stackoverflow./q/5834190/632951 – Pacerier Commented Feb 22, 2017 at 12:52
1 Answer
Reset to default 9Firstly, it's likely that you can actually get away with using the v8 api to do whatever it is that you want to do. You can use it to create prototypes that mostly behave the same as built-in objects, you can bind C++ function calls to JS function calls also. There's really no reason to modify v8 itself unless you need something to be extremely fast or to inspect or manipulate v8 internals. For instance, Chrome's DOM implementation uses the v8 API rather than being implemented in v8 directly. The embedder's guide actually has all the information you need to create "classes" (remember that in JS it's actually prototype inheritance): https://developers.google./v8/embed#templates.
That said, here's some good places to look in the source code for say, the array object. I'm not sure off any design doc, you're probably better off looking at the source.
The array object itself is here: https://code.google./p/v8/source/browse/trunk/src/objects.h#8409
Some of the array api functions are implemented here (many use the same public APIs as you would for extending): https://code.google./p/v8/source/browse/trunk/src/builtins#511
Some of the array api functions are implemented in JavaScript: https://code.google./p/v8/source/browse/trunk/src/array.js
Do a search for JSArray and you'll see much more. Pay particular attention to the bits in the native code generator, because you if you really want to take advantage of some custom type written at this level, you'll want to write code to generate efficient machine code too, for a bunch of different architectures...
Edit: Looks like V8 documentation has moved (and are better) than when this answer was written, here's some quick links to useful documentation:
- Wiki: https://github./v8/v8/wiki/Getting%20Started%20with%20Embedding
- API docs: http://v8.paulfryzel./docs/master/index.html
本文标签: javascriptHow to add a new class to Google V8Stack Overflow
版权声明:本文标题:javascript - How to add a new class to Google V8? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741789415a2397572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论